From d068b67a7193780787a7cc166a1dd208cf5eb9b2 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 11 Jun 2022 10:50:11 +0200 Subject: [PATCH 1/2] Wikidata engine: minor change of the SPARQL request The engine can be slow especially when the query won't return any answer. See https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI#Find_articles_in_Wikipedia_speaking_about_cheese_and_see_which_Wikibase_items_they_correspond_to Related to #1290 --- searx/engines/wikidata.py | 1 + 1 file changed, 1 insertion(+) diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index b7c318e53..b93cfd223 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -65,6 +65,7 @@ WHERE mwapi:language "%LANGUAGE%". ?item wikibase:apiOutputItem mwapi:item. } + hint:Prior hint:runFirst "true". %WHERE% From cd2dd5dd55e765b3ddd894119e2a8957c6c407e7 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Sat, 11 Jun 2022 11:03:55 +0200 Subject: [PATCH 2/2] Wikidata engine: ignore dummy entities Close #641 --- searx/engines/wikidata.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index b93cfd223..d828f4be8 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -94,6 +94,12 @@ WHERE { } """ +# see the property "dummy value" of https://www.wikidata.org/wiki/Q2013 (Wikidata) +# hard coded here to avoid to an additional SPARQL request when the server starts +DUMMY_ENTITY_URLS = set( + "http://www.wikidata.org/entity/" + wid for wid in ("Q4115189", "Q13406268", "Q15397819", "Q17339402") +) + # https://www.w3.org/TR/sparql11-query/#rSTRING_LITERAL1 # https://lists.w3.org/Archives/Public/public-rdf-dawg/2011OctDec/0175.html @@ -178,7 +184,7 @@ def response(resp): for result in jsonresponse.get('results', {}).get('bindings', []): attribute_result = {key: value['value'] for key, value in result.items()} entity_url = attribute_result['item'] - if entity_url not in seen_entities: + if entity_url not in seen_entities and entity_url not in DUMMY_ENTITY_URLS: seen_entities.add(entity_url) results += get_results(attribute_result, attributes, language) else: