Skip to content

Commit

Permalink
search_request_object --> SearchView.search_request; set self.search_…
Browse files Browse the repository at this point in the history
…request in BaseSearchFilter, re #11578
  • Loading branch information
whatisgalen committed Nov 20, 2024
1 parent fa81b4f commit a1f34c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
5 changes: 5 additions & 0 deletions arches/app/search/components/base_search_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ def __init__(self, request=None, user=None, componentname=None):
item.componentname, float("inf")
),
)
request_object = (
self.request.GET if self.request.method == "GET" else self.request.POST
)
request_object = request_object.dict()
self.search_request = self.create_query_dict(request_object)

@property
def required_search_filters(self):
Expand Down
24 changes: 12 additions & 12 deletions arches/app/search/components/paging_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@

class PagingFilter(BaseSearchFilter):
def append_dsl(self, search_query_object, **kwargs):
search_request_object = kwargs.get("search_request_object", self.request.GET)
export = search_request_object.get("export", None)
mobile_download = search_request_object.get("mobiledownload", None)
search_request = kwargs.get("search_request")
export = search_request.get("export", None)
mobile_download = search_request.get("mobiledownload", None)
page = (
1
if search_request_object.get(self.componentname) == ""
or isinstance(search_request_object.get(self.componentname), dict)
else int(search_request_object.get(self.componentname, 1))
if search_request.get(self.componentname) == ""
or isinstance(search_request.get(self.componentname), dict)
else int(search_request.get(self.componentname, 1))
)

if export is not None:
limit = settings.SEARCH_RESULT_LIMIT
elif mobile_download is not None:
limit = search_request_object.get("resourcecount")
limit = search_request.get("resourcecount")
else:
limit = settings.SEARCH_ITEMS_PER_PAGE
limit = int(search_request_object.get("limit", limit))
limit = int(search_request.get("limit", limit))
search_query_object["query"].start = limit * int(page - 1)
search_query_object["query"].limit = limit

def post_search_hook(self, search_query_object, response_object, **kwargs):
search_request_object = kwargs.get("search_request_object", self.request.GET)
search_request = kwargs.get("search_request")
total = (
response_object["results"]["hits"]["total"]["value"]
if response_object["results"]["hits"]["total"]["value"]
Expand All @@ -47,9 +47,9 @@ def post_search_hook(self, search_query_object, response_object, **kwargs):
)
page = (
1
if search_request_object.get(self.componentname) == ""
or isinstance(search_request_object.get(self.componentname), dict)
else int(search_request_object.get(self.componentname, 1))
if search_request.get(self.componentname) == ""
or isinstance(search_request.get(self.componentname), dict)
else int(search_request.get(self.componentname, 1))
)

paginator, pages = get_paginator(
Expand Down
27 changes: 11 additions & 16 deletions arches/app/search/components/standard_search_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@
class StandardSearchView(BaseSearchView):

def append_dsl(self, search_query_object, **kwargs):
search_request_object = kwargs.get("search_request_object", self.request.GET)
search_query_object["query"].include("graph_id")
search_query_object["query"].include("root_ontology_class")
search_query_object["query"].include("resourceinstanceid")
Expand All @@ -133,16 +132,15 @@ def append_dsl(self, search_query_object, **kwargs):
search_query_object["query"].include("map_popup")
search_query_object["query"].include("provisional_resource")
search_query_object["query"].include("permissions")
load_tiles = get_str_kwarg_as_bool("tiles", search_request_object)
load_tiles = get_str_kwarg_as_bool("tiles", self.search_request)
if load_tiles:
search_query_object["query"].include("tiles")

def execute_query(self, search_query_object, response_object, **kwargs):
search_request_object = kwargs.get("search_request_object", self.request.GET)
for_export = get_str_kwarg_as_bool("export", search_request_object)
pages = search_request_object.get("pages", None)
total = int(search_request_object.get("total", "0"))
resourceinstanceid = search_request_object.get("id", None)
for_export = get_str_kwarg_as_bool("export", self.search_request)
pages = self.search_request.get("pages", None)
total = int(self.search_request.get("total", "0"))
resourceinstanceid = self.search_request.get("id", None)
dsl = search_query_object["query"]
if for_export or pages:
results = dsl.search(index=RESOURCES_INDEX, scroll="1m")
Expand Down Expand Up @@ -208,21 +206,18 @@ def handle_search_results_query(
se = SearchEngineFactory().create()
search_query_object = {"query": Query(se)}
response_object = {"results": None}
sorted_query_obj = search_filter_factory.create_search_query_dict(
list(self.request.GET.items()) + list(self.request.POST.items())
)
permitted_nodegroups = get_permitted_nodegroups(self.request.user)
include_provisional = get_provisional_type(self.request)
try:
for filter_type, querystring in list(sorted_query_obj.items()):
for filter_type, querystring in list(self.search_request.items()):
search_filter = search_filter_factory.get_filter(filter_type)
if search_filter:
search_filter.append_dsl(
search_query_object,
permitted_nodegroups=permitted_nodegroups,
include_provisional=include_provisional,
querystring=querystring,
search_request_object=sorted_query_obj,
search_request=self.search_request,
)
append_instance_permission_filter_dsl(self.request, search_query_object)
except Exception as err:
Expand All @@ -235,25 +230,25 @@ def handle_search_results_query(
if returnDsl:
return response_object, search_query_object

for filter_type, querystring in list(sorted_query_obj.items()):
for filter_type, querystring in list(self.search_request.items()):
search_filter = search_filter_factory.get_filter(filter_type)
if search_filter:
search_filter.execute_query(
search_query_object,
response_object,
search_request_object=sorted_query_obj,
search_request=self.search_request,
)

if response_object["results"] is not None:
# allow filters to modify the results
for filter_type, querystring in list(sorted_query_obj.items()):
for filter_type, querystring in list(self.search_request.items()):
search_filter = search_filter_factory.get_filter(filter_type)
if search_filter:
search_filter.post_search_hook(
search_query_object,
response_object,
permitted_nodegroups=permitted_nodegroups,
search_request_object=sorted_query_obj,
search_request=self.search_request,
)

search_query_object.pop("query")
Expand Down
4 changes: 2 additions & 2 deletions arches/app/search/components/term_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def append_dsl(self, search_query_object, **kwargs):
include_provisional = kwargs.get("include_provisional")
search_query = Bool()
querystring_params = kwargs.get("querystring", "[]")
search_request_object = kwargs.get("search_request_object", self.request.GET)
language = search_request_object.get("language", "*")
search_request = kwargs.get("search_request")
language = search_request.get("language", "*")
for term in JSONDeserializer().deserialize(querystring_params):
if term["type"] == "term" or term["type"] == "string":
string_filter = Bool()
Expand Down

0 comments on commit a1f34c4

Please sign in to comment.