[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
1 changed files with 18 additions and 1 deletions

View File

@ -35,6 +35,22 @@ def 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):
# dbpedia autocompleter, no HTTPS
autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
@ -120,7 +136,8 @@ def wikipedia(query, lang):
return []
backends = {'dbpedia': dbpedia,
backends = {'brave': brave,
'dbpedia': dbpedia,
'duckduckgo': duckduckgo,
'google': google,
'startpage': startpage,