From b8c98c4c0d716c1e1c3a7f26788a012a41e59dbe Mon Sep 17 00:00:00 2001 From: Allen <64094914+allendema@users.noreply.github.com> Date: Sun, 2 Jan 2022 23:05:49 +0100 Subject: [PATCH] [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'. Cherry-pick: https://github.com/allendema/searx/commit/71786bf9cb6fbb175a054692e6951e77769aac1b --- searx/autocomplete.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/searx/autocomplete.py b/searx/autocomplete.py index b8d272c32..6c69ff7c5 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -36,6 +36,20 @@ 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 item in data[1]: + results.append(item) + return results + + def dbpedia(query, lang): # dbpedia autocompleter, no HTTPS autocomplete_url = 'https://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' @@ -128,6 +142,7 @@ backends = { 'swisscows': swisscows, 'qwant': qwant, 'wikipedia': wikipedia, + 'brave': brave, }