diff --git a/arches/app/media/js/views/components/search/base-search-view.js b/arches/app/media/js/views/components/search/base-search-view.js index 4c170fd6c4f..f20e626b2e9 100644 --- a/arches/app/media/js/views/components/search/base-search-view.js +++ b/arches/app/media/js/views/components/search/base-search-view.js @@ -50,8 +50,9 @@ define([ doQuery: function() { const queryObj = JSON.parse(this.queryString()); if (self.updateRequest) { self.updateRequest.abort(); } + const requestMethod = JSON.stringify(queryObj).length > 1800 ? "POST" : "GET"; self.updateRequest = $.ajax({ - type: "GET", + type: requestMethod, url: arches.urls.search_results, data: queryObj, context: this, @@ -82,7 +83,8 @@ define([ }, complete: function(request, status) { self.updateRequest = undefined; - window.history.pushState({}, '', '?' + $.param(queryObj).split('+').join('%20')); + if (requestMethod === "GET") + window.history.pushState({}, '', '?' + $.param(queryObj).split('+').join('%20')); this.sharedStateObject.loading(false); } }); diff --git a/arches/app/search/components/base.py b/arches/app/search/components/base.py index b0b6e06cf46..abbdcb4175d 100644 --- a/arches/app/search/components/base.py +++ b/arches/app/search/components/base.py @@ -9,8 +9,11 @@ class BaseSearchFilter: - def __init__(self, request=None, user=None, componentname=None): + def __init__( + self, request=None, search_request=None, user=None, componentname=None + ): self.request = request + self.search_request = search_request self.user = user self.componentname = componentname @@ -54,6 +57,10 @@ def __init__(self, request=None, user=None): for search_filter in SearchComponent.objects.all() } self.search_filters_instances = {} + request_object = ( + self.request.GET if self.request.method == "GET" else self.request.POST + ) + self.search_request = request_object.dict() def get_filter(self, componentname): if componentname in self.search_filters: @@ -71,7 +78,7 @@ def get_filter(self, componentname): ) if class_method: filter_instance = class_method( - self.request, self.user, componentname + self.request, self.search_request, self.user, componentname ) self.search_filters_instances[search_filter.componentname] = ( filter_instance @@ -83,10 +90,8 @@ def get_filter(self, componentname): def get_searchview_name(self): if not self.request: searchview_component_name = None - elif self.request.method == "POST": - searchview_component_name = self.request.POST.get("search-view", None) else: - searchview_component_name = self.request.GET.get("search-view", None) + searchview_component_name = self.search_request.get("search-view", None) if not searchview_component_name: # get default search_view component diff --git a/arches/app/search/components/base_search_view.py b/arches/app/search/components/base_search_view.py index b6064a83cea..9b028d6a9a7 100644 --- a/arches/app/search/components/base_search_view.py +++ b/arches/app/search/components/base_search_view.py @@ -48,8 +48,15 @@ class BaseSearchView(BaseSearchFilter): how to execute a search in the search_results method """ - def __init__(self, request=None, user=None, componentname=None): - super().__init__(request=request, user=user, componentname=componentname) + def __init__( + self, request=None, search_request=None, user=None, componentname=None + ): + super().__init__( + request=request, + search_request=search_request, + user=user, + componentname=componentname, + ) self.searchview_component = SearchComponent.objects.get( componentname=componentname ) @@ -95,6 +102,7 @@ def __init__(self, request=None, user=None, componentname=None): item.componentname, float("inf") ), ) + self.search_request = self.create_query_dict(self.search_request) @property def required_search_filters(self): diff --git a/arches/app/search/components/paging_filter.py b/arches/app/search/components/paging_filter.py index 216208be123..f6437d1cadd 100644 --- a/arches/app/search/components/paging_filter.py +++ b/arches/app/search/components/paging_filter.py @@ -17,21 +17,22 @@ class PagingFilter(BaseSearchFilter): def append_dsl(self, search_query_object, **kwargs): - export = self.request.GET.get("export", None) - mobile_download = self.request.GET.get("mobiledownload", None) + export = self.search_request.get("export", None) + mobile_download = self.search_request.get("mobiledownload", None) page = ( 1 - if self.request.GET.get(self.componentname) == "" - else int(self.request.GET.get(self.componentname, 1)) + if self.search_request.get(self.componentname) == "" + or isinstance(self.search_request.get(self.componentname), dict) + else int(self.search_request.get(self.componentname, 1)) ) if export is not None: limit = settings.SEARCH_RESULT_LIMIT elif mobile_download is not None: - limit = self.request.GET["resourcecount"] + limit = self.search_request.get("resourcecount") else: limit = settings.SEARCH_ITEMS_PER_PAGE - limit = int(self.request.GET.get("limit", limit)) + limit = int(self.search_request.get("limit", limit)) search_query_object["query"].start = limit * int(page - 1) search_query_object["query"].limit = limit @@ -44,8 +45,9 @@ def post_search_hook(self, search_query_object, response_object, **kwargs): ) page = ( 1 - if self.request.GET.get(self.componentname) == "" - else int(self.request.GET.get(self.componentname, 1)) + if self.search_request.get(self.componentname) == "" + or isinstance(self.search_request.get(self.componentname), dict) + else int(self.search_request.get(self.componentname, 1)) ) paginator, pages = get_paginator( diff --git a/arches/app/search/components/sort_results.py b/arches/app/search/components/sort_results.py index 4682998560f..7174b4648be 100644 --- a/arches/app/search/components/sort_results.py +++ b/arches/app/search/components/sort_results.py @@ -16,7 +16,7 @@ class SortResults(BaseSearchFilter): def append_dsl(self, search_query_object, **kwargs): - sort_param = self.request.GET.get(self.componentname, None) + sort_param = kwargs.get("querystring", None) if sort_param is not None and sort_param != "": search_query_object["query"].sort( diff --git a/arches/app/search/components/standard_search_view.py b/arches/app/search/components/standard_search_view.py index 6af783b1af6..2805edc684b 100644 --- a/arches/app/search/components/standard_search_view.py +++ b/arches/app/search/components/standard_search_view.py @@ -132,15 +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", self.request.GET) + 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): - for_export = get_str_kwarg_as_bool("export", self.request.GET) - pages = self.request.GET.get("pages", None) - total = int(self.request.GET.get("total", "0")) - resourceinstanceid = self.request.GET.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") @@ -206,13 +206,10 @@ 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( @@ -232,14 +229,17 @@ 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_filter.execute_query( + search_query_object, + response_object, + ) 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( diff --git a/arches/app/search/components/term_filter.py b/arches/app/search/components/term_filter.py index f100753766c..17b2f000032 100644 --- a/arches/app/search/components/term_filter.py +++ b/arches/app/search/components/term_filter.py @@ -34,7 +34,7 @@ def append_dsl(self, search_query_object, **kwargs): include_provisional = kwargs.get("include_provisional") search_query = Bool() querystring_params = kwargs.get("querystring", "[]") - language = self.request.GET.get("language", "*") + language = self.search_request.get("language", "*") for term in JSONDeserializer().deserialize(querystring_params): if term["type"] == "term" or term["type"] == "string": string_filter = Bool()