mirror of https://github.com/searxng/searxng.git
[enh] infoboxes : if the result doesn't contain anything except one link, use the normal result template
This commit is contained in:
parent
295b1699ce
commit
cac1761a54
|
@ -116,6 +116,13 @@ def response(resp):
|
||||||
|
|
||||||
if len(heading)>0:
|
if len(heading)>0:
|
||||||
# TODO get infobox.meta.value where .label='article_title'
|
# TODO get infobox.meta.value where .label='article_title'
|
||||||
|
if image==None and len(attributes)==0 and len(urls)==1 and len(relatedTopics)==0 and len(content)==0:
|
||||||
|
results.append({
|
||||||
|
'url': urls[0]['url'],
|
||||||
|
'title': heading,
|
||||||
|
'content': content
|
||||||
|
})
|
||||||
|
else:
|
||||||
results.append({
|
results.append({
|
||||||
'infobox': heading,
|
'infobox': heading,
|
||||||
'id': infobox_id,
|
'id': infobox_id,
|
||||||
|
|
|
@ -33,17 +33,20 @@ def response(resp):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def getDetail(jsonresponse, wikidata_id, language):
|
def getDetail(jsonresponse, wikidata_id, language):
|
||||||
result = jsonresponse.get('entities', {}).get(wikidata_id, {})
|
|
||||||
|
|
||||||
title = result.get('labels', {}).get(language, {}).get('value', None)
|
|
||||||
if title == None:
|
|
||||||
title = result.get('labels', {}).get('en', {}).get('value', wikidata_id)
|
|
||||||
results = []
|
results = []
|
||||||
urls = []
|
urls = []
|
||||||
attributes = []
|
attributes = []
|
||||||
|
|
||||||
description = result.get('descriptions', {}).get(language, {}).get('value', '')
|
result = jsonresponse.get('entities', {}).get(wikidata_id, {})
|
||||||
if description == '':
|
|
||||||
|
title = result.get('labels', {}).get(language, {}).get('value', None)
|
||||||
|
if title == None:
|
||||||
|
title = result.get('labels', {}).get('en', {}).get('value', None)
|
||||||
|
if title == None:
|
||||||
|
return results
|
||||||
|
|
||||||
|
description = result.get('descriptions', {}).get(language, {}).get('value', None)
|
||||||
|
if description == None:
|
||||||
description = result.get('descriptions', {}).get('en', {}).get('value', '')
|
description = result.get('descriptions', {}).get('en', {}).get('value', '')
|
||||||
|
|
||||||
claims = result.get('claims', {})
|
claims = result.get('claims', {})
|
||||||
|
@ -52,10 +55,15 @@ def getDetail(jsonresponse, wikidata_id, language):
|
||||||
urls.append({ 'title' : 'Official site', 'url': official_website })
|
urls.append({ 'title' : 'Official site', 'url': official_website })
|
||||||
results.append({ 'title': title, 'url' : official_website })
|
results.append({ 'title': title, 'url' : official_website })
|
||||||
|
|
||||||
|
wikipedia_link_count = 0
|
||||||
if language != 'en':
|
if language != 'en':
|
||||||
add_url(urls, 'Wikipedia (' + language + ')', get_wikilink(result, language + 'wiki'))
|
wikipedia_link_count += add_url(urls, 'Wikipedia (' + language + ')', get_wikilink(result, language + 'wiki'))
|
||||||
wikipedia_en_link = get_wikilink(result, 'enwiki')
|
wikipedia_en_link = get_wikilink(result, 'enwiki')
|
||||||
add_url(urls, 'Wikipedia (en)', wikipedia_en_link)
|
wikipedia_link_count += add_url(urls, 'Wikipedia (en)', wikipedia_en_link)
|
||||||
|
if wikipedia_link_count == 0:
|
||||||
|
misc_language = get_wiki_firstlanguage(result, 'wiki')
|
||||||
|
if misc_language != None:
|
||||||
|
add_url(urls, 'Wikipedia (' + misc_language + ')', get_wikilink(result, misc_language + 'wiki'))
|
||||||
|
|
||||||
if language != 'en':
|
if language != 'en':
|
||||||
add_url(urls, 'Wiki voyage (' + language + ')', get_wikilink(result, language + 'wikivoyage'))
|
add_url(urls, 'Wiki voyage (' + language + ')', get_wikilink(result, language + 'wikivoyage'))
|
||||||
|
@ -105,7 +113,13 @@ def getDetail(jsonresponse, wikidata_id, language):
|
||||||
if date_of_death != None:
|
if date_of_death != None:
|
||||||
attributes.append({'label' : 'Date of death', 'value' : date_of_death})
|
attributes.append({'label' : 'Date of death', 'value' : date_of_death})
|
||||||
|
|
||||||
|
if len(attributes)==0 and len(urls)==2 and len(description)==0:
|
||||||
|
results.append({
|
||||||
|
'url': urls[0]['url'],
|
||||||
|
'title': title,
|
||||||
|
'content': description
|
||||||
|
})
|
||||||
|
else:
|
||||||
results.append({
|
results.append({
|
||||||
'infobox' : title,
|
'infobox' : title,
|
||||||
'id' : wikipedia_en_link,
|
'id' : wikipedia_en_link,
|
||||||
|
@ -120,7 +134,9 @@ def getDetail(jsonresponse, wikidata_id, language):
|
||||||
def add_url(urls, title, url):
|
def add_url(urls, title, url):
|
||||||
if url != None:
|
if url != None:
|
||||||
urls.append({'title' : title, 'url' : url})
|
urls.append({'title' : title, 'url' : url})
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
def get_mainsnak(claims, propertyName):
|
def get_mainsnak(claims, propertyName):
|
||||||
propValue = claims.get(propertyName, {})
|
propValue = claims.get(propertyName, {})
|
||||||
|
@ -213,3 +229,9 @@ def get_wikilink(result, wikiid):
|
||||||
elif url.startswith('//'):
|
elif url.startswith('//'):
|
||||||
url = 'https:' + url
|
url = 'https:' + url
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
def get_wiki_firstlanguage(result, wikipatternid):
|
||||||
|
for k in result.get('sitelinks', {}).keys():
|
||||||
|
if k.endswith(wikipatternid) and len(k)==(2+len(wikipatternid)):
|
||||||
|
return k[0:2]
|
||||||
|
return None
|
||||||
|
|
Loading…
Reference in New Issue