Dear Gitlab users, due to maintenance reasons, Gitlab will not be available on Thursday 30.09.2021 from 5:00 pm to approximately 5:30 pm.

Commit 9d8ea81a authored by felix.herrmann's avatar felix.herrmann
Browse files

Merge branch '415-suchfilter-funktionieren-nicht' into 'master'

Resolve "Suchfilter funktionieren nicht"

Closes #415

See merge request !390
parents fa7482d6 2b12248c
......@@ -52,22 +52,36 @@ SEARCH_FIELDS_DATASET = [
# }
def add_tag_filter(search, filter_name, filter_list, filter_field):
# Commented out, as filters are not applied using this code.
# Switching back to older version below.
# def add_tag_filter(search, filter_name, filter_list, filter_field):
# """
# Add specific filters dynamically to search object using the alternative elasticsearch-dsl syntax
# see: https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#dotted-fields
# """
# if filter_list:
# query_list = list()
# # construct list of Q match clauses for filtering elements
# for elem in filter_list:
# if elem != "":
# query_list.append(Q("match", **{"{}.name".format(filter_name): elem}))
# # add the list to the search object
# return search.filter("terms", **{filter_name + "." + filter_field: query_list})
# else:
# # return original search object if filter_list is None
# return search
def add_tag_filter(search, filter_name, filter_list):
"""
Add specific filters dynamically to search object using the alternative elasticsearch-dsl syntax
Add specific filters dynamically using the alternative elasticsearch-dsl syntax
see: https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html#dotted-fields
"""
if filter_list:
query_list = list()
# construct list of Q match clauses for filtering elements
for elem in filter_list:
if elem != "":
query_list.append(Q("match", **{"{}.name".format(filter_name): elem}))
# add the list to the search object
return search.filter("terms", **{filter_name + "." + filter_field: query_list})
else:
# return original search object if filter_list is None
return search
search = search.query("match", **{"{}.name".format(filter_name): elem})
return search
def index_search(index, term, **kwargs):
......@@ -134,23 +148,23 @@ def index_search(index, term, **kwargs):
search = document.search().query(filter_query)
# add filters for both dataset_index and user_index to search
search = add_tag_filter(search, "countries", countries, "name")
search = add_tag_filter(search, "countries", countries)
# add filters for dataset_index
if index == "dataset_index":
search = add_tag_filter(search, "keywords", keywords, "name")
search = add_tag_filter(search, "languages_of_data", languages, "name")
search = add_tag_filter(search, "disciplines", disciplines, "name")
search = add_tag_filter(search, "keywords", keywords)
search = add_tag_filter(search, "languages_of_data", languages)
search = add_tag_filter(search, "disciplines", disciplines)
search = add_tag_filter(
search, "methods_of_data_collection", methods_of_data_collection, "name"
search, "methods_of_data_collection", methods_of_data_collection
)
search = add_tag_filter(
search, "methods_of_data_analysis", methods_of_data_analysis, "name"
search, "methods_of_data_analysis", methods_of_data_analysis
)
# add filters for user_index
if index == "user_index":
search = add_tag_filter(search, "interests", keywords, "name")
search = add_tag_filter(search, "interests", keywords)
# return all results, not just 10 (elastic default)
total = search.count()
......
......@@ -117,13 +117,13 @@ def core_search_view(request, search_index, objects_on_page):
methods_of_data_collection = request.GET.getlist("methods_of_data_collection")
if len(methods_of_data_collection) == 1 and methods_of_data_collection[0] == "":
methods_of_data_collection = None
methods_of_data_collection_all = AnalysisMethodsTagged.objects.all()
methods_of_data_collection_all = CollectionMethodsTagged.objects.all()
# extract methods_of_data_analysis slugs from GET
methods_of_data_analysis = request.GET.getlist("methods_of_data_analysis")
if len(methods_of_data_analysis) == 1 and methods_of_data_analysis[0] == "":
methods_of_data_analysis = None
methods_of_data_analysis_all = CollectionMethodsTagged.objects.all()
methods_of_data_analysis_all = AnalysisMethodsTagged.objects.all()
if search_index == "dataset_index":
template = "dddatasets/search_results.html"
......
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