Duplicated Info box

This commit is contained in:
kvan7 2024-01-22 03:23:35 +00:00
parent 72e8b5c354
commit b9eb927676
7 changed files with 204 additions and 170 deletions

42
.vscode/settings.json vendored
View file

@ -1,22 +1,24 @@
{ {
"python.testing.unittestArgs": [ "python.testing.unittestArgs": [
"-v", "-v",
"-s", "-s",
"./tests", "./tests",
"-p", "-p",
"test_*.py" "test_*.py"
], ],
"python.testing.pytestEnabled": false, "python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true, "python.testing.unittestEnabled": true,
"[less]": { "[less]": {
"editor.tabSize": 2, "editor.tabSize": 2,
"editor.insertSpaces": true "editor.insertSpaces": true
}, },
"[python]"{ "[python]"{
"editor.tabSize": 4, "editor.tabSize": 4,
"editor.insertSpaces": true "editor.insertSpaces": true
}, },
"cSpell.words": [ "cSpell.words": [
"kvan" "kvan",
] "searx",
"searxng"
]
} }

View file

@ -49,7 +49,7 @@ def response(resp):
response_json = loads(resp.text) response_json = loads(resp.text)
results = response_json['results'] results = response_json['results']
for i in ('answers', 'infoboxes'): for i in ('answers', 'infoboxes', 'chat_box'):
results.extend(response_json[i]) results.extend(response_json[i])
results.extend({'suggestion': s} for s in response_json['suggestions']) results.extend({'suggestion': s} for s in response_json['suggestions'])

17
searx/plugins/chat.py Normal file
View file

@ -0,0 +1,17 @@
from searx.search import SearchWithPlugins
name = "Chat Plugin"
description = "Similar to bing GPT or google bard in their respective searches"
default_on = False
preference_section = 'general'
def post_search(request, search: SearchWithPlugins) -> None:
"""Called after the search is done."""
search_request = search.search_query
container = search.result_container
# container.infoboxes.append(container.infoboxes[0])
container.chat_box = container.infoboxes
print(search_request)
print("HELLO WORLD =====================================================================")

View file

@ -157,6 +157,7 @@ class ResultContainer:
__slots__ = ( __slots__ = (
'_merged_results', '_merged_results',
'chat_box',
'infoboxes', 'infoboxes',
'suggestions', 'suggestions',
'answers', 'answers',
@ -176,6 +177,7 @@ class ResultContainer:
super().__init__() super().__init__()
self._merged_results = [] self._merged_results = []
self.infoboxes = [] self.infoboxes = []
self.chat_box = []
self.suggestions = set() self.suggestions = set()
self.answers = {} self.answers = {}
self.corrections = set() self.corrections = set()

View file

@ -10,9 +10,9 @@
{% block title %}{% if query_in_title %}{{- q|e }} - {% endif %}{% endblock %} {% block title %}{% if query_in_title %}{{- q|e }} - {% endif %}{% endblock %}
{% block meta %} {% block meta %}
<link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}" <link rel="alternate" type="application/rss+xml" title="Searx search: {{ q|e }}"
href="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;categories={{ selected_categories|join(" ,") | href="{{ url_for('search', _external=True) }}?q={{ q|urlencode }}&amp;categories={{ selected_categories|join(" ,") |
replace(' ',' +') }}&amp;pageno={{ pageno }}&amp;time_range={{ time_range }}&amp;language={{ current_language replace(' ',' +') }}&amp;pageno={{ pageno }}&amp;time_range={{ time_range }}&amp;language={{ current_language
}}&amp;safesearch={{ safesearch }}&amp;format=rss">{% endblock %} }}&amp;safesearch={{ safesearch }}&amp;format=rss">{% endblock %}
{% block content %} {% block content %}
{% include 'kvanDark/search.html' %} {% include 'kvanDark/search.html' %}
@ -23,162 +23,173 @@
{% endif %} {% endif %}
<div id="results" class="{{ only_template }}"> <div id="results" class="{{ only_template }}">
{% if answers -%} {% if answers -%}
<div id="answers" role="complementary" aria-labelledby="answers-title"> <div id="answers" role="complementary" aria-labelledby="answers-title">
<h4 class="title" id="answers-title">{{ _('Answers') }} : </h4> <h4 class="title" id="answers-title">{{ _('Answers') }} : </h4>
{%- for answer in answers.values() -%} {%- for answer in answers.values() -%}
<div class="answer"> <div class="answer">
<span>{{ answer.answer }}</span> <span>{{ answer.answer }}</span>
{% if answer.url -%} {% if answer.url -%}
<a href="{{ answer.url }}" class="answer-url">{{ urlparse(answer.url).hostname }}</a> <a href="{{ answer.url }}" class="answer-url">{{ urlparse(answer.url).hostname }}</a>
{% endif -%} {% endif -%}
</div> </div>
{%- endfor -%} {%- endfor -%}
</div> </div>
{%- endif %} {%- endif %}
<div id="sidebar"> <div id="sidebar">
{%- if number_of_results != '0' -%} {%- if number_of_results != '0' -%}
<p id="result_count"><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p> <p id="result_count"><small>{{ _('Number of results') }}: {{ number_of_results }}</small></p>
{%- endif -%} {%- endif -%}
{%- if infoboxes -%} {%- if chat_box -%}
<div id="infoboxes"> <div id="chat_box">
<details open class="sidebar-collapsable"> <details open class="sidebar-collapsable">
<summary class="title">{{ _('Info') }}</summary> <summary class="title">{{ _('Info') }}</summary>
{%- for infobox in infoboxes -%} {%- for infobox in infoboxes -%}
{%- include 'kvanDark/elements/infobox.html' -%} {%- include 'kvanDark/elements/infobox.html' -%}
{%- endfor -%} {%- endfor -%}
</details> </details>
</div> </div>
{%- endif -%} {%- endif -%}
{%- if suggestions -%} {%- if infoboxes -%}
{%- include 'kvanDark/elements/suggestions.html' -%} <div id="infoboxes">
{%- endif -%} <details open class="sidebar-collapsable">
<summary class="title">{{ _('Info') }}</summary>
{%- for infobox in infoboxes -%}
{%- include 'kvanDark/elements/infobox.html' -%}
{%- endfor -%}
</details>
</div>
{%- endif -%}
{%- if method == 'POST' -%} {%- if suggestions -%}
{%- include 'kvanDark/elements/search_url.html' -%} {%- include 'kvanDark/elements/suggestions.html' -%}
{%- endif -%} {%- endif -%}
{%- if unresponsive_engines -%} {%- if method == 'POST' -%}
{%- include 'kvanDark/elements/engines_msg.html' -%} {%- include 'kvanDark/elements/search_url.html' -%}
{%- endif -%} {%- endif -%}
{%- if search_formats -%} {%- if unresponsive_engines -%}
{%- include 'kvanDark/elements/apis.html' -%} {%- include 'kvanDark/elements/engines_msg.html' -%}
{%- endif -%} {%- endif -%}
<div id="sidebar-end-collapsable"></div> {%- if search_formats -%}
</div> {%- include 'kvanDark/elements/apis.html' -%}
{%- endif -%}
{% if corrections %} <div id="sidebar-end-collapsable"></div>
<div id="corrections" role="complementary" aria-labelledby="corrections-title"> </div>
<h4 id="corrections-title">{{ _('Try searching for:') }}</h4>
{% for correction in corrections %}
<div class="left">
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="navigation">
{% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1">
{% endfor %}
<input type="hidden" name="q" value="{{ correction.url }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit }}">{% endif %}
<input type="submit" role="link" value="{{ correction.title }}">
</form>
</div>
{% endfor %}
</div>
{% endif %}
<div id="urls" role="main"> {% if corrections %}
{% for result in results %} <div id="corrections" role="complementary" aria-labelledby="corrections-title">
{% if result.open_group and not only_template %}<div <h4 id="corrections-title">{{ _('Try searching for:') }}</h4>
class="template_group_{{ result['template']|replace('.html', '') }}">{% endif %} {% for correction in corrections %}
{% set index = loop.index %} <div class="left">
{% include get_result_template('kvanDark', result['template']) %} <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" role="navigation">
{% if result.close_group and not only_template %}</div>{% endif %} {% for category in selected_categories %}
{% endfor %} <input type="hidden" name="category_{{ category }}" value="1">
{% if not results and not answers %} {% endfor %}
{% include 'kvanDark/messages/no_results.html' %} <input type="hidden" name="q" value="{{ correction.url }}">
{% endif %} <input type="hidden" name="language" value="{{ current_language }}">
</div> <input type="hidden" name="time_range" value="{{ time_range }}">
<div id="backToTop"> <input type="hidden" name="safesearch" value="{{ safesearch }}">
<a href="#" aria-label="{{ _('Back to top') }}">{{ icon_small('chevron-up-outline') }}</a> <input type="hidden" name="theme" value="{{ theme }}">
</div> {% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit }}">{% endif %}
{% if paging %} <input type="submit" role="link" value="{{ correction.title }}">
<nav id="pagination" role="navigation"> </form>
{% if pageno > 1 %} </div>
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="previous_page"> {% endfor %}
<div class="{% if rtl %}right{% else %}left{% endif %}"> </div>
<input type="hidden" name="q" value="{{ q|e }}"> {% endif %}
{% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1">
{% endfor %}
<input type="hidden" name="pageno" value="{{ pageno-1 }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif
%}
{{- engine_data_form(engine_data) -}}
<button role="link" type="submit">{{ icon_small('chevron-left') }} {{ _('Previous page') }}</button>
</div>
</form>
{% endif %}
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="next_page">
<div class="{% if rtl %}left{% else %}right{% endif %}">
<input type="hidden" name="q" value="{{ q|e }}">
{% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1">
{% endfor %}
<input type="hidden" name="pageno" value="{{ pageno+1 }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif
%}
{{- engine_data_form(engine_data) -}}
<button role="link" type="submit">{{ _('Next page') }} {{ icon_small('chevron-right') }}</button>
</div>
</form>
{% set pstart = 1 %}
{% set pend = 11 %}
{% if pageno > 5 %}
{% set pstart = pageno - 4 %}
{% set pend = pageno + 6 %}
{% endif %}
<div class="numbered_pagination"> <div id="urls" role="main">
{% for x in range(pstart, pend) %} {% for result in results %}
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="page_number"> {% if result.open_group and not only_template %}<div
<input type="hidden" name="q" value="{{ q|e }}"> class="template_group_{{ result['template']|replace('.html', '') }}">{% endif %}
{% for category in selected_categories %} {% set index = loop.index %}
<input type="hidden" name="category_{{ category }}" value="1"> {% include get_result_template('kvanDark', result['template']) %}
{% endfor %} {% if result.close_group and not only_template %}</div>{% endif %}
<input type="hidden" name="pageno" value="{{ x }}"> {% endfor %}
<input type="hidden" name="language" value="{{ current_language }}"> {% if not results and not answers %}
<input type="hidden" name="time_range" value="{{ time_range }}"> {% include 'kvanDark/messages/no_results.html' %}
<input type="hidden" name="safesearch" value="{{ safesearch }}"> {% endif %}
<input type="hidden" name="theme" value="{{ theme }}"> </div>
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif <div id="backToTop">
%} <a href="#" aria-label="{{ _('Back to top') }}">{{ icon_small('chevron-up-outline') }}</a>
{{- engine_data_form(engine_data) -}} </div>
{% if pageno == x %} {% if paging %}
<input role="link" class="page_number_current" type="button" value="{{ x }}"> <nav id="pagination" role="navigation">
{% else %} {% if pageno > 1 %}
<input role="link" class="page_number" type="submit" value="{{ x }}"> <form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="previous_page">
{% endif %} <div class="{% if rtl %}right{% else %}left{% endif %}">
</form> <input type="hidden" name="q" value="{{ q|e }}">
{% endfor %} {% for category in selected_categories %}
</div> <input type="hidden" name="category_{{ category }}" value="1">
</nav> {% endfor %}
{% endif %} <input type="hidden" name="pageno" value="{{ pageno-1 }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif
%}
{{- engine_data_form(engine_data) -}}
<button role="link" type="submit">{{ icon_small('chevron-left') }} {{ _('Previous page') }}</button>
</div>
</form>
{% endif %}
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="next_page">
<div class="{% if rtl %}left{% else %}right{% endif %}">
<input type="hidden" name="q" value="{{ q|e }}">
{% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1">
{% endfor %}
<input type="hidden" name="pageno" value="{{ pageno+1 }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif
%}
{{- engine_data_form(engine_data) -}}
<button role="link" type="submit">{{ _('Next page') }} {{ icon_small('chevron-right') }}</button>
</div>
</form>
{% set pstart = 1 %}
{% set pend = 11 %}
{% if pageno > 5 %}
{% set pstart = pageno - 4 %}
{% set pend = pageno + 6 %}
{% endif %}
<div class="numbered_pagination">
{% for x in range(pstart, pend) %}
<form method="{{ method or 'POST' }}" action="{{ url_for('search') }}" class="page_number">
<input type="hidden" name="q" value="{{ q|e }}">
{% for category in selected_categories %}
<input type="hidden" name="category_{{ category }}" value="1">
{% endfor %}
<input type="hidden" name="pageno" value="{{ x }}">
<input type="hidden" name="language" value="{{ current_language }}">
<input type="hidden" name="time_range" value="{{ time_range }}">
<input type="hidden" name="safesearch" value="{{ safesearch }}">
<input type="hidden" name="theme" value="{{ theme }}">
{% if timeout_limit %}<input type="hidden" name="timeout_limit" value="{{ timeout_limit|e }}">{% endif
%}
{{- engine_data_form(engine_data) -}}
{% if pageno == x %}
<input role="link" class="page_number_current" type="button" value="{{ x }}">
{% else %}
<input role="link" class="page_number" type="submit" value="{{ x }}">
{% endif %}
</form>
{% endfor %}
</div>
</nav>
{% endif %}
</div> </div>
{% endblock %} {% endblock %}

View file

@ -779,6 +779,7 @@ def search():
answers = result_container.answers, answers = result_container.answers,
corrections = correction_urls, corrections = correction_urls,
infoboxes = result_container.infoboxes, infoboxes = result_container.infoboxes,
chat_box = result_container.chat_box,
engine_data = result_container.engine_data, engine_data = result_container.engine_data,
paging = result_container.paging, paging = result_container.paging,
unresponsive_engines = webutils.get_translated_errors( unresponsive_engines = webutils.get_translated_errors(

View file

@ -164,6 +164,7 @@ def get_json_response(sq: SearchQuery, rc: ResultContainer) -> str:
'answers': list(rc.answers), 'answers': list(rc.answers),
'corrections': list(rc.corrections), 'corrections': list(rc.corrections),
'infoboxes': rc.infoboxes, 'infoboxes': rc.infoboxes,
'chat_box': rc.chat_box,
'suggestions': list(rc.suggestions), 'suggestions': list(rc.suggestions),
'unresponsive_engines': get_translated_errors(rc.unresponsive_engines), 'unresponsive_engines': get_translated_errors(rc.unresponsive_engines),
} }