예제 #1
0
 def test_forms_courses_build_es_query_search_by_match_text(self, *_):
     """
     Happy path: build a query that filters courses by matching text
     """
     form = CourseSearchForm(
         data=QueryDict(query_string="limit=2&offset=20&query=some%20phrase%20terms")
     )
     self.assertTrue(form.is_valid())
     self.assertEqual(
         form.build_es_query()[2],
         {
             "bool": {
                 "must": [
                     {
                         "multi_match": {
                             "analyzer": "english",
                             "fields": [
                                 "description.*",
                                 "title.*",
                                 "categories_names.*^0.05",
                                 "organizations_names.*^0.05",
                                 "persons_names.*^0.05",
                             ],
                             "query": "some phrase terms",
                             "type": "cross_fields",
                         }
                     }
                 ]
             }
         },
     )
예제 #2
0
 def test_forms_courses_build_es_query_search_by_match_text(self, *_):
     """
     Happy path: build a query that filters courses by matching text
     """
     form = CourseSearchForm(data=QueryDict(
         query_string="limit=2&offset=20&query=some%20phrase%20terms"))
     self.assertTrue(form.is_valid())
     self.assertEqual(
         form.build_es_query()[2]["function_score"]["query"],
         {
             "bool": {
                 "filter": {
                     "term": {
                         "is_listed": True
                     }
                 },
                 "must": [{
                     "bool": {
                         "should": [
                             {
                                 "multi_match": {
                                     "analyzer":
                                     "english",
                                     "fields": [
                                         "description.*",
                                         "introduction.*",
                                         "title.*^50",
                                         "categories_names.*^0.05",
                                         "organizations_names.*^0.05",
                                         "persons_names.*^0.05",
                                     ],
                                     "query":
                                     "some phrase terms",
                                     "type":
                                     "best_fields",
                                 }
                             },
                             {
                                 "match": {
                                     "code": {
                                         "query": "some phrase terms",
                                         "analyzer": "code",
                                         "boost": 3000,
                                     }
                                 }
                             },
                             {
                                 "match": {
                                     "code": {
                                         "query": "some phrase terms",
                                         "analyzer": "code",
                                         "fuzziness": "AUTO",
                                     }
                                 }
                             },
                         ]
                     }
                 }],
             }
         },
     )