Commit d2be9ee6 by cahrens

SearchIndex must know about tags to return them.

parent 4af2c003
......@@ -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
......
......@@ -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):
"""
......
......@@ -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]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment