From edd8dccd07d5c9bbd5d73c74ee98d0a7ee585dd0 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Mon, 14 Sep 2020 10:11:49 +0200 Subject: [PATCH] [mod] searx.query.RawTextQuery: getSearchQuery and changeSearchQuery rename to getQuery and changeQuery getSearchQuery is confusing, the method returns a str not a SearchQuery object --- searx/autocomplete.py | 12 ++++++------ searx/query.py | 8 ++++---- searx/search.py | 2 +- searx/webapp.py | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/searx/autocomplete.py b/searx/autocomplete.py index 9bc6a98f2..420b8a461 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -38,22 +38,22 @@ def get(*args, **kwargs): def searx_bang(full_query): '''check if the searchQuery contain a bang, and create fitting autocompleter results''' # check if there is a query which can be parsed - if len(full_query.getSearchQuery()) == 0: + if len(full_query.getQuery()) == 0: return [] results = [] # check if current query stats with !bang - first_char = full_query.getSearchQuery()[0] + first_char = full_query.getQuery()[0] if first_char == '!' or first_char == '?': - if len(full_query.getSearchQuery()) == 1: + if len(full_query.getQuery()) == 1: # show some example queries # TODO, check if engine is not avaliable results.append(first_char + "images") results.append(first_char + "wikipedia") results.append(first_char + "osm") else: - engine_query = full_query.getSearchQuery()[1:] + engine_query = full_query.getQuery()[1:] # check if query starts with categorie name for categorie in categories: @@ -72,14 +72,14 @@ def searx_bang(full_query): # check if current query stats with :bang elif first_char == ':': - if len(full_query.getSearchQuery()) == 1: + if len(full_query.getQuery()) == 1: # show some example queries results.append(":en") results.append(":en_us") results.append(":english") results.append(":united_kingdom") else: - engine_query = full_query.getSearchQuery()[1:] + engine_query = full_query.getQuery()[1:] for lc in language_codes: lang_id, lang_name, country, english_name = map(str.lower, lc) diff --git a/searx/query.py b/searx/query.py index 6eba2cbd6..7c2b0a249 100644 --- a/searx/query.py +++ b/searx/query.py @@ -162,14 +162,14 @@ class RawTextQuery: # append query part to query_part list self.query_parts.append(query_part) - def changeSearchQuery(self, search_query): + def changeQuery(self, query): if len(self.query_parts): - self.query_parts[-1] = search_query + self.query_parts[-1] = query else: - self.query_parts.append(search_query) + self.query_parts.append(query) return self - def getSearchQuery(self): + def getQuery(self): if len(self.query_parts): return self.query_parts[-1] else: diff --git a/searx/search.py b/searx/search.py index 9c66f75fc..9c1c19446 100644 --- a/searx/search.py +++ b/searx/search.py @@ -268,7 +268,7 @@ def get_search_query_from_webapp(preferences, form): raw_text_query = RawTextQuery(form['q'], disabled_engines) # set query - query = raw_text_query.getSearchQuery() + query = raw_text_query.getQuery() # get and check page number pageno_param = form.get('pageno', '1') diff --git a/searx/webapp.py b/searx/webapp.py index 90bc8fc6e..bba37cce1 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -679,13 +679,13 @@ def index(): # suggestions: use RawTextQuery to get the suggestion URLs with the same bang suggestion_urls = list(map(lambda suggestion: { - 'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(), + 'url': raw_text_query.changeQuery(suggestion).getFullQuery(), 'title': suggestion }, result_container.suggestions)) correction_urls = list(map(lambda correction: { - 'url': raw_text_query.changeSearchQuery(correction).getFullQuery(), + 'url': raw_text_query.changeQuery(correction).getFullQuery(), 'title': correction }, result_container.corrections)) @@ -744,7 +744,7 @@ def autocompleter(): raw_text_query = RawTextQuery(request.form.get('q', ''), disabled_engines) # check if search query is set - if not raw_text_query.getSearchQuery(): + if not raw_text_query.getQuery(): return '', 400 # run autocompleter @@ -765,12 +765,12 @@ def autocompleter(): else: language = language.split('-')[0] # run autocompletion - raw_results.extend(completer(raw_text_query.getSearchQuery(), language)) + raw_results.extend(completer(raw_text_query.getQuery(), language)) # parse results (write :language and !engine back to result string) results = [] for result in raw_results: - raw_text_query.changeSearchQuery(result) + raw_text_query.changeQuery(result) # add parsed result results.append(raw_text_query.getFullQuery())