Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-notes-api
Commits
4631c73e
Commit
4631c73e
authored
May 04, 2015
by
Christina Roberts
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #23 from edx/christina/search-index-tags
SearchIndex must know about tags to return them.
parents
4af2c003
d2be9ee6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
+15
-6
notesapi/v1/search_indexes.py
+1
-0
notesapi/v1/tests/test_views.py
+12
-6
notesapi/v1/views.py
+2
-0
No files found.
notesapi/v1/search_indexes.py
View file @
4631c73e
...
...
@@ -11,6 +11,7 @@ class NoteIndex(indexes.SearchIndex, indexes.Indexable):
ranges
=
indexes
.
CharField
(
model_attr
=
'ranges'
,
indexed
=
False
)
created
=
indexes
.
DateTimeField
(
model_attr
=
'created'
)
updated
=
indexes
.
DateTimeField
(
model_attr
=
'updated'
)
tags
=
indexes
.
CharField
(
model_attr
=
'tags'
)
def
get_model
(
self
):
return
Note
...
...
notesapi/v1/tests/test_views.py
View file @
4631c73e
...
...
@@ -417,8 +417,8 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
"""
Tests for search method.
"""
self
.
_create_annotation
(
text
=
u'First one'
)
self
.
_create_annotation
(
text
=
u'Second note'
)
self
.
_create_annotation
(
text
=
u'First one'
,
tags
=
[]
)
self
.
_create_annotation
(
text
=
u'Second note'
,
tags
=
[
u'tag1'
,
u'tag2'
]
)
note
=
self
.
_create_annotation
(
text
=
u'Third note'
)
del
note
[
'created'
]
del
note
[
'updated'
]
...
...
@@ -430,10 +430,16 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
last_note
,
note
)
self
.
assertEqual
(
results
[
'total'
],
3
)
results
=
self
.
_get_search_results
(
text
=
"Second"
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
'Second note'
)
def
search_and_verify
(
searchText
,
expectedText
,
expectedTags
):
""" Test the results from a specific text search operation """
results
=
self
.
_get_search_results
(
text
=
searchText
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
expectedText
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'tags'
],
expectedTags
)
search_and_verify
(
"First"
,
"First one"
,
[])
search_and_verify
(
"Second"
,
"Second note"
,
[
"tag1"
,
"tag2"
])
def
test_search_deleted
(
self
):
"""
...
...
notesapi/v1/views.py
View file @
4631c73e
...
...
@@ -74,6 +74,8 @@ class AnnotationSearchView(APIView):
for
item
in
query
:
note_dict
=
item
.
get_stored_fields
()
note_dict
[
'ranges'
]
=
json
.
loads
(
item
.
ranges
)
# If ./manage.py rebuild_index has not been run after tags were added, item.tags will be None.
note_dict
[
'tags'
]
=
json
.
loads
(
item
.
tags
)
if
item
.
tags
else
[]
note_dict
[
'id'
]
=
str
(
item
.
pk
)
if
item
.
highlighted
:
note_dict
[
'text'
]
=
item
.
highlighted
[
0
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment