diff options
author | a01200356 <a01200356@itesm.mx> | 2016-03-29 18:53:31 -0600 |
---|---|---|
committer | a01200356 <a01200356@itesm.mx> | 2016-03-29 19:10:13 -0600 |
commit | 94cb3a7f11d252dc8dabd6bce4d7f4d67a1ececd (patch) | |
tree | 4062d57084e992d08292be268a182f7d46a0d04a /searx/autocomplete.py | |
parent | 71de593a5b9025e360da32813e9efeaeaa4992b2 (diff) | |
download | searxng-94cb3a7f11d252dc8dabd6bce4d7f4d67a1ececd.tar.gz searxng-94cb3a7f11d252dc8dabd6bce4d7f4d67a1ececd.zip |
[enh] multilingual autocomplete
implemented for wikipedia, qwant and google
Diffstat (limited to 'searx/autocomplete.py')
-rw-r--r-- | searx/autocomplete.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/searx/autocomplete.py b/searx/autocomplete.py index 94913e8d8..527104041 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -110,7 +110,7 @@ def searx_bang(full_query): return list(result_set) -def dbpedia(query): +def dbpedia(query, lang): # dbpedia autocompleter, no HTTPS autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' @@ -126,7 +126,7 @@ def dbpedia(query): return results -def duckduckgo(query): +def duckduckgo(query, lang): # duckduckgo autocompleter url = 'https://ac.duckduckgo.com/ac/?{0}&type=list' @@ -136,11 +136,11 @@ def duckduckgo(query): return [] -def google(query): +def google(query, lang): # google autocompleter autocomplete_url = 'https://suggestqueries.google.com/complete/search?client=toolbar&' - response = get(autocomplete_url + urlencode(dict(q=query))) + response = get(autocomplete_url + urlencode(dict(hl=lang, q=query))) results = [] @@ -151,8 +151,8 @@ def google(query): return results -def startpage(query): - # wikipedia autocompleter +def startpage(query, lang): + # startpage autocompleter url = 'https://startpage.com/do/suggest?{query}' resp = get(url.format(query=urlencode({'query': query}))).text.split('\n') @@ -161,11 +161,11 @@ def startpage(query): return [] -def qwant(query): +def qwant(query, lang): # qwant autocompleter (additional parameter : lang=en_en&count=xxx ) url = 'https://api.qwant.com/api/suggest?{query}' - resp = get(url.format(query=urlencode({'q': query}))) + resp = get(url.format(query=urlencode({'q': query, 'lang': lang}))) results = [] @@ -178,9 +178,9 @@ def qwant(query): return results -def wikipedia(query): +def wikipedia(query, lang): # wikipedia autocompleter - url = 'https://en.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json' + url = 'https://' + lang + '.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json' resp = loads(get(url.format(urlencode(dict(search=query)))).text) if len(resp) > 1: |