on master help sign in
Add startpage as an autocompleter engine
633c7b6Cqoicebordel
searx/autocomplete.py+18−6
@@ -57,17 +57,17 @@ def searx_bang(full_query):
57 # check if query starts with categorie name
57 # check if query starts with categorie name
58 for categorie in categories:
58 for categorie in categories:
59 if categorie.startswith(engine_query):
59 if categorie.startswith(engine_query):
60− results.append(first_char+'{categorie}'.format(categorie=categorie))
60+ results.append(first_char + '{categorie}'.format(categorie=categorie))
61
61
62 # check if query starts with engine name
62 # check if query starts with engine name
63 for engine in engines:
63 for engine in engines:
64 if engine.startswith(engine_query.replace('_', ' ')):
64 if engine.startswith(engine_query.replace('_', ' ')):
65− results.append(first_char+'{engine}'.format(engine=engine.replace(' ', '_')))
65+ results.append(first_char + '{engine}'.format(engine=engine.replace(' ', '_')))
66
66
67 # check if query starts with engine shortcut
67 # check if query starts with engine shortcut
68 for engine_shortcut in engine_shortcuts:
68 for engine_shortcut in engine_shortcuts:
69 if engine_shortcut.startswith(engine_query):
69 if engine_shortcut.startswith(engine_query):
70− results.append(first_char+'{engine_shortcut}'.format(engine_shortcut=engine_shortcut))
70+ results.append(first_char + '{engine_shortcut}'.format(engine_shortcut=engine_shortcut))
71
71
72 # check if current query stats with :bang
72 # check if current query stats with :bang
73 elif first_char == ':':
73 elif first_char == ':':
@@ -112,7 +112,7 @@ def searx_bang(full_query):
112
112
113def dbpedia(query):
113def dbpedia(query):
114 # dbpedia autocompleter, no HTTPS
114 # dbpedia autocompleter, no HTTPS
115− autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?' # noqa
115+ autocomplete_url = 'http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?'
116
116
117 response = get(autocomplete_url
117 response = get(autocomplete_url
118 + urlencode(dict(QueryString=query)))
118 + urlencode(dict(QueryString=query)))
@@ -139,7 +139,7 @@ def duckduckgo(query):
139
139
140def google(query):
140def google(query):
141 # google autocompleter
141 # google autocompleter
142− autocomplete_url = 'https://suggestqueries.google.com/complete/search?client=toolbar&' # noqa
142+ autocomplete_url = 'https://suggestqueries.google.com/complete/search?client=toolbar&'
143
143
144 response = get(autocomplete_url
144 response = get(autocomplete_url
145 + urlencode(dict(q=query)))
145 + urlencode(dict(q=query)))
@@ -153,9 +153,20 @@ def google(query):
153 return results
153 return results
154
154
155
155
156+def startpage(query):
157+ # wikipedia autocompleter
158+ url = 'https://startpage.com/do/suggest?{query}'
159+
160+ resp = get(url.format(query=urlencode({'query': query}))).text.split('\n')
161+ print resp
162+ if len(resp) > 1:
163+ return resp
164+ return []
165+
166+
156def wikipedia(query):
167def wikipedia(query):
157 # wikipedia autocompleter
168 # wikipedia autocompleter
158− url = 'https://en.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json' # noqa
169+ url = 'https://en.wikipedia.org/w/api.php?action=opensearch&{0}&limit=10&namespace=0&format=json'
159
170
160 resp = loads(get(url.format(urlencode(dict(search=query)))).text)
171 resp = loads(get(url.format(urlencode(dict(search=query)))).text)
161 if len(resp) > 1:
172 if len(resp) > 1:
@@ -166,5 +177,6 @@ def wikipedia(query):
166backends = {'dbpedia': dbpedia,
177backends = {'dbpedia': dbpedia,
167 'duckduckgo': duckduckgo,
178 'duckduckgo': duckduckgo,
168 'google': google,
179 'google': google,
180+ 'startpage': startpage,
169 'wikipedia': wikipedia
181 'wikipedia': wikipedia
170 }
182 }