on master help sign in
[fix] make search requests on wikidata more accurate
commitb12857a70dd947a804e667d864ba56055b528ee0 authorMarc Abonce Seguin <marc-abonce@mailbox.org> dateSun 8 Apr 2018, 21:17 (9 years ago) parent835d1ed
2 files changed+7−7
searx/engines/wikidata.py+6−7 searx/settings.yml+1
searx/engines/wikidata.py+6−7
@@ -27,7 +27,7 @@ result_count = 1
2727# urls
2828wikidata_host = 'https://www.wikidata.org'
2929url_search = wikidata_host \
30− + '/wiki/Special:ItemDisambiguation?{query}'
30+ + '/w/index.php?{query}'
3131
3232wikidata_api = wikidata_host + '/w/api.php'
3333url_detail = wikidata_api\
@@ -40,7 +40,7 @@ url_map = 'https://www.openstreetmap.org/'\
4040url_image = 'https://commons.wikimedia.org/wiki/Special:FilePath/{filename}?width=500&height=400'
4141
4242# xpaths
43−wikidata_ids_xpath = '//div/ul[@class="wikibase-disambiguation"]/li/a/@title'
43+wikidata_ids_xpath = '//ul[@class="mw-search-results"]/li//a/@href'
4444title_xpath = '//*[contains(@class,"wikibase-title-label")]'
4545description_xpath = '//div[contains(@class,"wikibase-entitytermsview-heading-description")]'
4646property_xpath = '//div[@id="{propertyid}"]'
@@ -57,22 +57,21 @@ calendar_name_xpath = './/sup[contains(@class,"wb-calendar-name")]'
5757
5858
5959def request(query, params):
60− language = match_language(params['language'], supported_languages).split('-')[0]
61−
6260 params['url'] = url_search.format(
63− query=urlencode({'label': query, 'language': language}))
61+ query=urlencode({'search': query}))
6462 return params
6563
6664
6765def response(resp):
6866 results = []
6967 html = fromstring(resp.text)
70− wikidata_ids = html.xpath(wikidata_ids_xpath)
68+ search_results = html.xpath(wikidata_ids_xpath)
7169
7270 language = match_language(resp.search_params['language'], supported_languages).split('-')[0]
7371
7472 # TODO: make requests asynchronous to avoid timeout when result_count > 1
75− for wikidata_id in wikidata_ids[:result_count]:
73+ for search_result in search_results[:result_count]:
74+ wikidata_id = search_result.split('/')[-1]
7675 url = url_detail.format(query=urlencode({'page': wikidata_id, 'uselang': language}))
7776 htmlresponse = get(url)
7877 jsonresponse = loads(htmlresponse.text)
searx/settings.yml+1
@@ -174,6 +174,7 @@ engines:
174174 - name : wikidata
175175 engine : wikidata
176176 shortcut : wd
177+ timeout : 3.0
177178 weight : 2
178179
179180 - name : duckduckgo