Skip to content
Permalink
Browse files

Suggestions: use RawTextQuery to make the suggestions URLs. Update al…

…l themes accordingly.
  • Loading branch information...
dalf committed Jul 16, 2019
1 parent ddee486 commit c7220b40ead8c53b21e1533d23ffff8ae3b831bd
@@ -145,6 +145,7 @@ def changeSearchQuery(self, search_query):
self.query_parts[-1] = search_query
else:
self.query_parts.append(search_query)
return self

def getSearchQuery(self):
if len(self.query_parts):
@@ -319,8 +319,9 @@ def get_search_query_from_webapp(preferences, form):
for engine in categories[categ]
if (engine.name, categ) not in disabled_engines)

return SearchQuery(query, query_engines, query_categories,
query_lang, query_safesearch, query_pageno, query_time_range)
return (SearchQuery(query, query_engines, query_categories,
query_lang, query_safesearch, query_pageno, query_time_range),
raw_text_query)


class Search(object):
@@ -42,8 +42,8 @@
<div id="suggestions"><span>{{ _('Suggestions') }}</span>
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<input type="hidden" name="q" value="{{ suggestion }}">
<input type="submit" value="{{ suggestion }}" />
<input type="hidden" name="q" value="{{ suggestion.url }}">
<input type="submit" value="{{ suggestion.title }}" />
</form>
{% endfor %}
</div>
@@ -44,8 +44,8 @@
{% set first = true %}
{% for suggestion in suggestions %}
{% if not first %} &bull; {% endif %}<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<input type="hidden" name="q" value="{{ suggestion }}">
<input type="submit" class="suggestion" value="{{ suggestion }}" />
<input type="hidden" name="q" value="{{ suggestion.url }}">
<input type="submit" class="suggestion" value="{{ suggestion.title }}" />
</form>
{% set first = false %}
{% endfor %}
@@ -118,8 +118,8 @@ <h4 class="panel-title">{{ _('Suggestions') }}</h4>
<div class="panel-body">
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" role="navigation" class="form-inline pull-{% if rtl %}right{% else %}left{% endif %} suggestion_item">
<input type="hidden" name="q" value="{{ query_prefix + suggestion }}">
<button type="submit" class="btn btn-default btn-xs">{{ suggestion }}</button>
<input type="hidden" name="q" value="{{ suggestion.url }}">
<button type="submit" class="btn btn-default btn-xs">{{ suggestion.title }}</button>
</form>
{% endfor %}
</div>
@@ -50,11 +50,11 @@ <h4 class="title">{{ _('Suggestions') }} : </h4>
<div class="wrapper">
{% for suggestion in suggestions %}
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}">
<input type="hidden" name="q" value="{{ suggestion }}">
<input type="hidden" name="q" value="{{ suggestion.url }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
<input type="submit" class="suggestion" value="&bull; {{ suggestion }}">
<input type="submit" class="suggestion" value="&bull; {{ suggestion.title }}">
</form>
{% endfor %}
</div>
@@ -489,9 +489,10 @@ def index():

# search
search_query = None
raw_text_query = None
result_container = None
try:
search_query = get_search_query_from_webapp(request.preferences, request.form)
search_query, raw_text_query = get_search_query_from_webapp(request.preferences, request.form)
# search = Search(search_query) # without plugins
search = SearchWithPlugins(search_query, request.user_plugins, request)
result_container = search.search()
@@ -580,17 +581,25 @@ def index():
)
return Response(response_rss, mimetype='text/xml')

# HTML output format

# suggestions: use RawTextQuery to get the suggestion URLs with the same bang
suggestion_urls = map(lambda suggestion: {
'url': raw_text_query.changeSearchQuery(suggestion).getFullQuery(),
'title': suggestion
},
result_container.suggestions)
#
return render(
'results.html',
results=results,
q=request.form['q'],
query_prefix=u''.join((request.form['q']).rsplit(search_query.query.decode('utf-8'), 1)),
selected_categories=search_query.categories,
pageno=search_query.pageno,
time_range=search_query.time_range,
number_of_results=format_decimal(number_of_results),
advanced_search=advanced_search,
suggestions=result_container.suggestions,
suggestions=suggestion_urls,
answers=result_container.answers,
corrections=result_container.corrections,
infoboxes=result_container.infoboxes,
@@ -64,7 +64,7 @@
preferences = searx.preferences.Preferences(['oscar'], searx.engines.categories.keys(), searx.engines.engines, [])
preferences.key_value_settings['safesearch'].parse(args.safesearch)

search_query = searx.search.get_search_query_from_webapp(preferences, form)
search_query, raw_text_query = searx.search.get_search_query_from_webapp(preferences, form)
search = searx.search.Search(search_query)
result_container = search.search()

2 comments on commit c7220b4

@rachmadaniHaryono

This comment has been minimized.

Copy link
Contributor

replied Jul 21, 2019

raw_text_query variable on standalone_searx.py is not used right?

@dalf

This comment has been minimized.

Copy link
Collaborator Author

replied Jul 21, 2019

No it is not used, it can replaced by

search_query, __ = searx.search.get_search_query_from_webapp(preferences, form)

or similar writting.

Please sign in to comment.
You can’t perform that action at this time.