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..a7c4619f 100755 --- a/search/views.py +++ b/search/views.py @@ -208,6 +208,10 @@ def course_discovery(request): search_term = request.POST.get("search_string", None) + # 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) field_dictionary = _course_process_field_values(request) @@ -228,6 +232,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', '') )