Commit ba00cf80 by Tim Babych Committed by Oleg Marshev

use Match query for text searches

parent ea0c9425
...@@ -370,11 +370,25 @@ class AnnotationViewTests(BaseAnnotationViewTests): ...@@ -370,11 +370,25 @@ class AnnotationViewTests(BaseAnnotationViewTests):
results = self._get_search_results(text=u"Свят") results = self._get_search_results(text=u"Свят")
self.assertEqual(results['rows'][0]['text'], u'Веселих свят') self.assertEqual(results['rows'][0]['text'], u'Веселих свят')
def test_search_multiword(self):
"""
Tests searching of complex words and word combinations
"""
self._create_annotation(text=u'Totally different something')
self.assertEqual(self._get_search_results(text=u"TOTALLY")['total'], 1)
self.assertEqual(self._get_search_results(text=u"different")['total'], 1)
self.assertEqual(self._get_search_results(text=u"differ")['total'], 1)
self.assertEqual(self._get_search_results(text=u"total")['total'], 1)
self.assertEqual(self._get_search_results(text=u"totil")['total'], 0)
self.assertEqual(self._get_search_results(text=u"something")['total'], 1)
self.assertEqual(self._get_search_results(text=u"totally different")['total'], 1)
def test_search_course(self): def test_search_course(self):
""" """
Tests searching with course_id provided Tests searching with course_id provided
""" """
self._create_annotation(text=u'First one', course_id="u'edX/DemoX/Demo_Course'") self._create_annotation(text=u'First one', course_id="u'edX/DemoX/Demo_Course'")
self._create_annotation(text=u'Not shown', course_id="u'edx/demox/demo_course'") # wrong case
self._create_annotation(text=u'Second note', course_id="u'edX/DemoX/Demo_Course'") self._create_annotation(text=u'Second note', course_id="u'edX/DemoX/Demo_Course'")
self._create_annotation(text=u'Third note', course_id="b") self._create_annotation(text=u'Third note', course_id="b")
self._create_annotation(text=u'Fourth note', course_id="c") self._create_annotation(text=u'Fourth note', course_id="c")
......
...@@ -25,8 +25,8 @@ class AnnotationSearchView(APIView): ...@@ -25,8 +25,8 @@ class AnnotationSearchView(APIView):
params = self.request.QUERY_PARAMS.dict() params = self.request.QUERY_PARAMS.dict()
for field in ('text', 'quote'): for field in ('text', 'quote'):
if field in params: if field in params:
params[field] = params[field].lower() params[field + "__match"] = params[field]
del params[field]
if params.get('highlight'): if params.get('highlight'):
params.pop('highlight') params.pop('highlight')
results = NoteMappingType.process_result( results = NoteMappingType.process_result(
...@@ -37,7 +37,7 @@ class AnnotationSearchView(APIView): ...@@ -37,7 +37,7 @@ class AnnotationSearchView(APIView):
) )
else: else:
results = NoteMappingType.process_result( results = NoteMappingType.process_result(
list(note_searcher.filter(**params).order_by("-created").values_dict("_source")) list(note_searcher.query(**params).order_by("-created").values_dict("_source"))
) )
return Response({'total': len(results), 'rows': results}) return Response({'total': len(results), 'rows': results})
......
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