Commit fcd1de13 by Muhammad Ammar

Merge pull request #37 from edx/ammar/fix-unicode-search

fix unicode error when search with highlighting
parents ec24a5d4 6ddfa002
...@@ -56,7 +56,7 @@ class NotesElasticSearchSerializer(serializers.Serializer): # pylint: disable=a ...@@ -56,7 +56,7 @@ class NotesElasticSearchSerializer(serializers.Serializer): # pylint: disable=a
Return note text. Return note text.
""" """
if note.highlighted: if note.highlighted:
return note.highlighted[0].decode('unicode_escape') return note.highlighted[0]
return note.text return note.text
def get_ranges(self, note): def get_ranges(self, note):
......
...@@ -738,6 +738,25 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -738,6 +738,25 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
response = self._get_search_results(text=u"Свят") response = self._get_search_results(text=u"Свят")
self.assertEqual(response['rows'][0]['text'], u'Веселих свят') self.assertEqual(response['rows'][0]['text'], u'Веселих свят')
@ddt.unpack
@ddt.data(
{"text": u"Веселих свят", 'text_to_search': u"веселих", 'result': u"{}Веселих{} свят"},
{"text": "The Hunger games", 'text_to_search': "Hunger", 'result': "The {}Hunger{} games"}
)
@unittest.skipIf(settings.ES_DISABLED, "MySQL cannot do highlighting")
def test_search_with_highlighting(self, text, text_to_search, result):
"""
Tests searching of unicode and non-unicode text with highlighting enabled.
"""
start_tag = "{elasticsearch_highlight_start}"
end_tag = "{elasticsearch_highlight_end}"
self._create_annotation(text=text)
response = self._get_search_results(text=text_to_search, highlight=True)
self.assertEqual(response['total'], 1)
self.assertEqual(response['rows'][0]['text'], result.format(start_tag, end_tag))
def test_search_multiword(self): def test_search_multiword(self):
""" """
Tests searching of complex words and word combinations Tests searching of complex words and word combinations
......
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