1
0
mirror of https://github.com/searx/searx synced 2024-12-11 08:25:27 +01:00

[enh] Add autocompleter from Brave (#3109)

* [enh] Add autocompleter from Brave

Raw response example: https://search.brave.com/api/suggest?q=how%20to:%20with%20j

Headers are needed in order to get a 200 response, thus Searx user-agent is used.

Other URL param could be  '&rich=false' or  '&rich=true'.
This commit is contained in:
Allen 2022-01-15 19:08:53 +01:00 committed by GitHub
parent 82ac634070
commit 321ddc91bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,6 +35,22 @@ def get(*args, **kwargs):
return http_get(*args, **kwargs) return http_get(*args, **kwargs)
def brave(query, lang):
# brave search autocompleter
url = 'https://search.brave.com/api/suggest?{query}'
resp = get(url.format(query=urlencode({'q': query})))
results = []
if resp.ok:
data = loads(resp.text)
for suggestion in data[1]:
results.append(suggestion)
return results
def dbpedia(query, lang): def dbpedia(query, lang):
# dbpedia autocompleter, no HTTPS # dbpedia autocompleter, no HTTPS
autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
@ -120,7 +136,8 @@ def wikipedia(query, lang):
return [] return []
backends = {'dbpedia': dbpedia, backends = {'brave': brave,
'dbpedia': dbpedia,
'duckduckgo': duckduckgo, 'duckduckgo': duckduckgo,
'google': google, 'google': google,
'startpage': startpage, 'startpage': startpage,