wikipedia wikidata infobox + disable wikisource

by default switch wikipedia and wikidata to infobox only
disable wikisource by default
This commit is contained in:
Emilien Devos 2023-09-17 17:45:04 +02:00
parent b4e0d2eedc
commit 299a3fc7b0
3 changed files with 42 additions and 13 deletions

View file

@ -31,6 +31,8 @@ if TYPE_CHECKING:
traits: EngineTraits
display_type = "list"
# about
about = {
"website": 'https://wikidata.org/',
@ -268,7 +270,7 @@ def get_results(attribute_result, attributes, language):
for url in value.split(', '):
infobox_urls.append({'title': attribute.get_label(language), 'url': url, **attribute.kwargs})
# "normal" results (not infobox) include official website and Wikipedia links.
if attribute.kwargs.get('official') or attribute_type == WDArticle:
if display_type == "list" and (attribute.kwargs.get('official') or attribute_type == WDArticle):
results.append({'title': infobox_title, 'url': url, "content": infobox_content})
# update the infobox_id with the wikipedia URL
# first the local wikipedia URL, and as fallback the english wikipedia URL
@ -307,7 +309,7 @@ def get_results(attribute_result, attributes, language):
if img_src is None and len(infobox_attributes) == 0 and len(infobox_urls) == 1 and len(infobox_content) == 0:
results.append({'url': infobox_urls[0]['url'], 'title': infobox_title, 'content': infobox_content})
else:
elif display_type == "infobox":
results.append(
{
'infobox': infobox_title,

View file

@ -67,6 +67,8 @@ from searx.enginelib.traits import EngineTraits
traits: EngineTraits
display_type = "list"
# about
about = {
"website": 'https://www.wikipedia.org/',
@ -185,18 +187,21 @@ def response(resp):
api_result = resp.json()
title = utils.html_to_text(api_result.get('titles', {}).get('display') or api_result.get('title'))
wikipedia_link = api_result['content_urls']['desktop']['page']
results.append({'url': wikipedia_link, 'title': title, 'content': api_result.get('description', '')})
if api_result.get('type') == 'standard':
results.append(
{
'infobox': title,
'id': wikipedia_link,
'content': api_result.get('extract', ''),
'img_src': api_result.get('thumbnail', {}).get('source'),
'urls': [{'title': 'Wikipedia', 'url': wikipedia_link}],
}
)
if display_type == "list":
results.append({'url': wikipedia_link, 'title': title, 'content': api_result.get('description', '')})
if display_type == "infobox":
if api_result.get('type') == 'standard':
results.append(
{
'infobox': title,
'id': wikipedia_link,
'content': api_result.get('extract', ''),
'img_src': api_result.get('thumbnail', {}).get('source'),
'urls': [{'title': 'Wikipedia', 'url': wikipedia_link}],
}
)
return results