mirror of
https://github.com/searxng/searxng.git
synced 2024-11-22 19:01:00 +00: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
4 changed files with 16 additions and 16 deletions
|
@ -38,22 +38,22 @@ def get(*args, **kwargs):
|
||||||
def searx_bang(full_query):
|
def searx_bang(full_query):
|
||||||
'''check if the searchQuery contain a bang, and create fitting autocompleter results'''
|
'''check if the searchQuery contain a bang, and create fitting autocompleter results'''
|
||||||
# check if there is a query which can be parsed
|
# check if there is a query which can be parsed
|
||||||
if len(full_query.getSearchQuery()) == 0:
|
if len(full_query.getQuery()) == 0:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# check if current query stats with !bang
|
# 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 first_char == '!' or first_char == '?':
|
||||||
if len(full_query.getSearchQuery()) == 1:
|
if len(full_query.getQuery()) == 1:
|
||||||
# show some example queries
|
# show some example queries
|
||||||
# TODO, check if engine is not avaliable
|
# TODO, check if engine is not avaliable
|
||||||
results.append(first_char + "images")
|
results.append(first_char + "images")
|
||||||
results.append(first_char + "wikipedia")
|
results.append(first_char + "wikipedia")
|
||||||
results.append(first_char + "osm")
|
results.append(first_char + "osm")
|
||||||
else:
|
else:
|
||||||
engine_query = full_query.getSearchQuery()[1:]
|
engine_query = full_query.getQuery()[1:]
|
||||||
|
|
||||||
# check if query starts with categorie name
|
# check if query starts with categorie name
|
||||||
for categorie in categories:
|
for categorie in categories:
|
||||||
|
@ -72,14 +72,14 @@ def searx_bang(full_query):
|
||||||
|
|
||||||
# check if current query stats with :bang
|
# check if current query stats with :bang
|
||||||
elif first_char == ':':
|
elif first_char == ':':
|
||||||
if len(full_query.getSearchQuery()) == 1:
|
if len(full_query.getQuery()) == 1:
|
||||||
# show some example queries
|
# show some example queries
|
||||||
results.append(":en")
|
results.append(":en")
|
||||||
results.append(":en_us")
|
results.append(":en_us")
|
||||||
results.append(":english")
|
results.append(":english")
|
||||||
results.append(":united_kingdom")
|
results.append(":united_kingdom")
|
||||||
else:
|
else:
|
||||||
engine_query = full_query.getSearchQuery()[1:]
|
engine_query = full_query.getQuery()[1:]
|
||||||
|
|
||||||
for lc in language_codes:
|
for lc in language_codes:
|
||||||
lang_id, lang_name, country, english_name = map(str.lower, lc)
|
lang_id, lang_name, country, english_name = map(str.lower, lc)
|
||||||
|
|
|
@ -162,14 +162,14 @@ class RawTextQuery:
|
||||||
# append query part to query_part list
|
# append query part to query_part list
|
||||||
self.query_parts.append(query_part)
|
self.query_parts.append(query_part)
|
||||||
|
|
||||||
def changeSearchQuery(self, search_query):
|
def changeQuery(self, query):
|
||||||
if len(self.query_parts):
|
if len(self.query_parts):
|
||||||
self.query_parts[-1] = search_query
|
self.query_parts[-1] = query
|
||||||
else:
|
else:
|
||||||
self.query_parts.append(search_query)
|
self.query_parts.append(query)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def getSearchQuery(self):
|
def getQuery(self):
|
||||||
if len(self.query_parts):
|
if len(self.query_parts):
|
||||||
return self.query_parts[-1]
|
return self.query_parts[-1]
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -268,7 +268,7 @@ def get_search_query_from_webapp(preferences, form):
|
||||||
raw_text_query = RawTextQuery(form['q'], disabled_engines)
|
raw_text_query = RawTextQuery(form['q'], disabled_engines)
|
||||||
|
|
||||||
# set query
|
# set query
|
||||||
query = raw_text_query.getSearchQuery()
|
query = raw_text_query.getQuery()
|
||||||
|
|
||||||
# get and check page number
|
# get and check page number
|
||||||
pageno_param = form.get('pageno', '1')
|
pageno_param = form.get('pageno', '1')
|
||||||
|
|
|
@ -679,13 +679,13 @@ def index():
|
||||||
|
|
||||||
# suggestions: use RawTextQuery to get the suggestion URLs with the same bang
|
# suggestions: use RawTextQuery to get the suggestion URLs with the same bang
|
||||||
suggestion_urls = list(map(lambda suggestion: {
|
suggestion_urls = list(map(lambda suggestion: {
|
||||||
'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(),
|
'url': raw_text_query.changeQuery(suggestion).getFullQuery(),
|
||||||
'title': suggestion
|
'title': suggestion
|
||||||
},
|
},
|
||||||
result_container.suggestions))
|
result_container.suggestions))
|
||||||
|
|
||||||
correction_urls = list(map(lambda correction: {
|
correction_urls = list(map(lambda correction: {
|
||||||
'url': raw_text_query.changeSearchQuery(correction).getFullQuery(),
|
'url': raw_text_query.changeQuery(correction).getFullQuery(),
|
||||||
'title': correction
|
'title': correction
|
||||||
},
|
},
|
||||||
result_container.corrections))
|
result_container.corrections))
|
||||||
|
@ -744,7 +744,7 @@ def autocompleter():
|
||||||
raw_text_query = RawTextQuery(request.form.get('q', ''), disabled_engines)
|
raw_text_query = RawTextQuery(request.form.get('q', ''), disabled_engines)
|
||||||
|
|
||||||
# check if search query is set
|
# check if search query is set
|
||||||
if not raw_text_query.getSearchQuery():
|
if not raw_text_query.getQuery():
|
||||||
return '', 400
|
return '', 400
|
||||||
|
|
||||||
# run autocompleter
|
# run autocompleter
|
||||||
|
@ -765,12 +765,12 @@ def autocompleter():
|
||||||
else:
|
else:
|
||||||
language = language.split('-')[0]
|
language = language.split('-')[0]
|
||||||
# run autocompletion
|
# 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)
|
# parse results (write :language and !engine back to result string)
|
||||||
results = []
|
results = []
|
||||||
for result in raw_results:
|
for result in raw_results:
|
||||||
raw_text_query.changeSearchQuery(result)
|
raw_text_query.changeQuery(result)
|
||||||
|
|
||||||
# add parsed result
|
# add parsed result
|
||||||
results.append(raw_text_query.getFullQuery())
|
results.append(raw_text_query.getFullQuery())
|
||||||
|
|
Loading…
Reference in a new issue