summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/admin/settings/settings_search.rst1
-rw-r--r--searx/autocomplete.py49
-rw-r--r--searx/settings.yml2
3 files changed, 50 insertions, 2 deletions
diff --git a/docs/admin/settings/settings_search.rst b/docs/admin/settings/settings_search.rst
index 06ad03b46..40c2607ad 100644
--- a/docs/admin/settings/settings_search.rst
+++ b/docs/admin/settings/settings_search.rst
@@ -46,6 +46,7 @@
- ``qwant``
- ``seznam``
- ``sogou``
+ - ``startpage``
- ``stract``
- ``swisscows``
- ``wikipedia``
diff --git a/searx/autocomplete.py b/searx/autocomplete.py
index 05a641829..31121c7e7 100644
--- a/searx/autocomplete.py
+++ b/searx/autocomplete.py
@@ -20,7 +20,7 @@ from searx.engines import (
)
from searx.network import get as http_get, post as http_post
from searx.exceptions import SearxEngineResponseException
-from searx.utils import extr
+from searx.utils import extr, gen_useragent
def update_kwargs(**kwargs):
@@ -233,6 +233,52 @@ def sogou(query, _lang):
return []
+def startpage(query, sxng_locale):
+ """Autocomplete from Startpage's Firefox extension.
+ Supports the languages specified in lang_map.
+ """
+
+ lang_map = {
+ 'da': 'dansk',
+ 'de': 'deutsch',
+ 'en': 'english',
+ 'es': 'espanol',
+ 'fr': 'francais',
+ 'nb': 'norsk',
+ 'nl': 'nederlands',
+ 'pl': 'polski',
+ 'pt': 'portugues',
+ 'sv': 'svenska',
+ }
+
+ base_lang = sxng_locale.split('-')[0]
+ lui = lang_map.get(base_lang, 'english')
+
+ url_params = {
+ 'q': query,
+ 'format': 'opensearch',
+ 'segment': 'startpage.defaultffx',
+ 'lui': lui,
+ }
+ url = f'https://www.startpage.com/suggestions?{urlencode(url_params)}'
+
+ # Needs user agent, returns a 204 otherwise
+ h = {'User-Agent': gen_useragent()}
+
+ resp = get(url, headers=h)
+
+ if resp.ok:
+ try:
+ data = resp.json()
+
+ if len(data) >= 2 and isinstance(data[1], list):
+ return data[1]
+ except json.JSONDecodeError:
+ pass
+
+ return []
+
+
def stract(query, _lang):
# stract autocompleter (beta)
url = f"https://stract.com/beta/api/autosuggest?q={quote_plus(query)}"
@@ -320,6 +366,7 @@ backends = {
'qwant': qwant,
'seznam': seznam,
'sogou': sogou,
+ 'startpage': startpage,
'stract': stract,
'swisscows': swisscows,
'wikipedia': wikipedia,
diff --git a/searx/settings.yml b/searx/settings.yml
index 76200d4be..b530ca90d 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -34,7 +34,7 @@ search:
# Filter results. 0: None, 1: Moderate, 2: Strict
safe_search: 0
# Existing autocomplete backends: "360search", "baidu", "brave", "dbpedia", "duckduckgo", "google", "yandex",
- # "mwmbl", "naver", "seznam", "sogou", "stract", "swisscows", "quark", "qwant", "wikipedia" -
+ # "mwmbl", "naver", "seznam", "sogou", "startpage", "stract", "swisscows", "quark", "qwant", "wikipedia" -
# leave blank to turn it off by default.
autocomplete: ""
# minimun characters to type before autocompleter starts