diff options
Diffstat (limited to 'searx/engines')
| -rw-r--r-- | searx/engines/json_engine.py | 8 | ||||
| -rw-r--r-- | searx/engines/wikidata.py | 9 |
2 files changed, 16 insertions, 1 deletions
diff --git a/searx/engines/json_engine.py b/searx/engines/json_engine.py index f53bc0bf4..2dd3bc55e 100644 --- a/searx/engines/json_engine.py +++ b/searx/engines/json_engine.py @@ -16,6 +16,11 @@ paging = False suggestion_query = '' results_query = '' +cookies = {} +headers = {} +'''Some engines might offer different result based on cookies or headers. +Possible use-case: To set safesearch cookie or header to moderate.''' + # parameters for engines with paging support # # number of results on each page @@ -88,6 +93,9 @@ def request(query, params): if paging and search_url.find('{pageno}') >= 0: fp['pageno'] = (params['pageno'] - 1) * page_size + first_page_num + params['cookies'].update(cookies) + params['headers'].update(headers) + params['url'] = search_url.format(**fp) params['query'] = query diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index b7c318e53..d828f4be8 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% @@ -93,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 @@ -177,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: |