mirror of
https://github.com/searxng/searxng.git
synced 2024-11-16 17:40:11 +01:00
[mod] searx.query.RawTextQuery: getSearchQuery and changeSearchQuery rename to getQuery and changeQuery
getSearchQuery is confusing, the method returns a str not a SearchQuery object
This commit is contained in:
parent
c4067a9d02
commit
edd8dccd07
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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')
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user