Commit 333ce86a by Muzaffar yousaf

Merge pull request #36 from edx/muzaffar/format-tags-tnl4012

Adding format tag instead of Klass and span for ES highlight.
parents ea572112 00922530
...@@ -679,14 +679,10 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -679,14 +679,10 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
results = self._get_search_results(text="first", highlight=True) results = self._get_search_results(text="first", highlight=True)
self.assertEqual(results['total'], 1) self.assertEqual(results['total'], 1)
self.assertEqual(len(results['rows']), 1) self.assertEqual(len(results['rows']), 1)
self.assertEqual(results['rows'][0]['text'], '<em>First</em> note') self.assertEqual(
results['rows'][0]['text'],
results = self._get_search_results(text="first", highlight=True, highlight_tag='tag') '{elasticsearch_highlight_start}First{elasticsearch_highlight_end} note'
self.assertEqual(results['rows'][0]['text'], '<tag>First</tag> note') )
results = self._get_search_results(text="first", highlight=True, highlight_tag='tag', highlight_class='klass')
self.assertEqual(results['rows'][0]['text'], '<tag class="klass">First</tag> note')
@override_settings(ES_DISABLED=True) @override_settings(ES_DISABLED=True)
def test_search_ordering_in_db(self): def test_search_ordering_in_db(self):
...@@ -861,13 +857,10 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests): ...@@ -861,13 +857,10 @@ class AnnotationSearchViewTests(BaseAnnotationViewTests):
results = self._get_search_results(text="bar", highlight=True) results = self._get_search_results(text="bar", highlight=True)
self.assertEqual(results['total'], 1) self.assertEqual(results['total'], 1)
self.assertEqual(len(results['rows']), 1) self.assertEqual(len(results['rows']), 1)
self.assertEqual(results['rows'][0]['tags'], ['foo', '<em>bar</em>']) self.assertEqual(
results['rows'][0]['tags'],
results = self._get_search_results(text="bar", highlight=True, highlight_tag='tag') ['foo', '{elasticsearch_highlight_start}bar{elasticsearch_highlight_end}']
self.assertEqual(results['rows'][0]['tags'], ['foo', '<tag>bar</tag>']) )
results = self._get_search_results(text="bar", highlight=True, highlight_tag='tag', highlight_class='klass')
self.assertEqual(results['rows'][0]['tags'], ['foo', '<tag class="klass">bar</tag>'])
@ddt.unpack @ddt.unpack
@ddt.data( @ddt.data(
......
...@@ -145,14 +145,9 @@ class AnnotationSearchView(GenericAPIView): ...@@ -145,14 +145,9 @@ class AnnotationSearchView(GenericAPIView):
query = query.filter(SQ(data=clean_text)) query = query.filter(SQ(data=clean_text))
if params.get('highlight'): if params.get('highlight'):
tag = params.get('highlight_tag', 'em')
klass = params.get('highlight_class')
opts = { opts = {
'pre_tags': ['<{tag}{klass_str}>'.format( 'pre_tags': ['{elasticsearch_highlight_start}'],
tag=tag, 'post_tags': ['{elasticsearch_highlight_end}'],
klass_str=' class=\\"{}\\"'.format(klass) if klass else ''
)],
'post_tags': ['</{tag}>'.format(tag=tag)],
} }
query = query.highlight(**opts) query = query.highlight(**opts)
......
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