From 75a9e1088f02f4f530309d872b3632860df96815 Mon Sep 17 00:00:00 2001 From: rythmE Date: Sun, 12 Dec 2021 20:04:11 +0800 Subject: [PATCH 1/2] Studio search 1 --- search/api.py | 3 +++ search/elastic.py | 9 ++++++++- search/views.py | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/search/api.py b/search/api.py index 935c3471..eb8ff1b1 100755 --- a/search/api.py +++ b/search/api.py @@ -260,6 +260,8 @@ def course_discovery_search(search_term=None, size=20, from_=0, field_dictionary if getattr(settings, 'ALLOW_CATALOG_VISIBILITY_FILTER', False): use_field_dictionary['catalog_visibility'] = CATALOG_VISIBILITY_CATALOG_AND_ABOUT + course_tag_list = kwargs.get('course_tag_list', []) + results = searcher.search( query_string=search_term, doc_type="course_info", @@ -271,6 +273,7 @@ def course_discovery_search(search_term=None, size=20, from_=0, field_dictionary filter_dictionary=filter_dictionary, exclude_dictionary=exclude_dictionary, facet_terms=course_discovery_facets(), + course_tag_list=course_tag_list, sort=sort_args ) diff --git a/search/elastic.py b/search/elastic.py index f9fc8cdc..df06ae6e 100755 --- a/search/elastic.py +++ b/search/elastic.py @@ -519,6 +519,7 @@ def search(self, filter_dictionary=None, exclude_dictionary=None, facet_terms=None, + course_tag_list=None, exclude_ids=None, use_field_match=False, include_content=False, @@ -640,6 +641,11 @@ def search(self, "analyzer": "standard" } }) + elastic_queries.append({ + "terms": { + "tag": course_tag_list + } + }) if field_dictionary: if use_field_match: @@ -667,7 +673,7 @@ def search(self, if elastic_queries: query_segment = { "bool": { - "must": elastic_queries + "should": elastic_queries } } @@ -698,6 +704,7 @@ def search(self, body=body, **kwargs ) + log.info("search es_response: %s", es_response) except exceptions.ElasticsearchException as ex: message = unicode(ex) if 'QueryParsingException' in message: diff --git a/search/views.py b/search/views.py index 752011be..2dac6a72 100755 --- a/search/views.py +++ b/search/views.py @@ -207,6 +207,8 @@ def course_discovery(request): status_code = 500 search_term = request.POST.get("search_string", None) + course_tag_list_string = request.POST.get("course_tag_list_string", '') + course_tag_list = course_tag_list_string.split(', ') try: size, from_, page = _process_pagination_values(request) @@ -228,6 +230,7 @@ def course_discovery(request): from_=from_, field_dictionary=field_dictionary, user=request.user, + course_tag_list=course_tag_list, allow_enrollment_end_filter=True, sort_type=request.POST.get('sort_type', '') ) From 9149529277b4f7fbf79b0d0f80e92df586b8eeea Mon Sep 17 00:00:00 2001 From: rythmE Date: Wed, 22 Dec 2021 17:08:06 +0800 Subject: [PATCH 2/2] LMS Search filter --- search/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/search/views.py b/search/views.py index 2dac6a72..a7c4619f 100755 --- a/search/views.py +++ b/search/views.py @@ -207,8 +207,10 @@ def course_discovery(request): status_code = 500 search_term = request.POST.get("search_string", None) - course_tag_list_string = request.POST.get("course_tag_list_string", '') - course_tag_list = course_tag_list_string.split(', ') + + # Search tag by input with the course search + # course_tag_list_string = request.POST.get("course_tag_list_string", '') + # course_tag_list = course_tag_list_string.split(', ') try: size, from_, page = _process_pagination_values(request) @@ -230,7 +232,7 @@ def course_discovery(request): from_=from_, field_dictionary=field_dictionary, user=request.user, - course_tag_list=course_tag_list, + # course_tag_list=course_tag_list, allow_enrollment_end_filter=True, sort_type=request.POST.get('sort_type', '') )