From 32189d05db91f8a7587c48017f910bfa9718c6bd Mon Sep 17 00:00:00 2001 From: Ramadan Omar <55840806+ramadanomar@users.noreply.github.com> Date: Tue, 20 Sep 2022 13:57:45 -0700 Subject: [PATCH] Uses a terms array to query data (#902) Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com> Co-authored-by: Olga Bulat Co-authored-by: Krystle Salazar --- .../api/controllers/search_controller.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api/catalog/api/controllers/search_controller.py b/api/catalog/api/controllers/search_controller.py index d6db5072b..363326cbf 100644 --- a/api/catalog/api/controllers/search_controller.py +++ b/api/catalog/api/controllers/search_controller.py @@ -240,15 +240,16 @@ def _apply_filter( """ if serializer_field in search_params.data: - filters = [] - for arg in search_params.data[serializer_field].split(","): - _param = es_field or serializer_field - args = {"name_or_query": "term", _param: arg} - filters.append(Q(**args)) + arguments = search_params.data.get(serializer_field) + if arguments is None: + return s + arguments = arguments.split(",") + parameter = es_field or serializer_field + query = Q("terms", **{parameter: arguments}) method = getattr(s, behaviour) - return method("bool", should=filters) - else: - return s + return method("bool", should=query) + + return s def _exclude_filtered(s: Search):