summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authoruseralias <212567668+useralias@users.noreply.github.com>2025-06-23 12:30:29 -0400
committerBnyro <bnyro@tutanota.com>2025-06-25 17:38:31 +0200
commit8757655644bab3c25daad612c2087754331640fb (patch)
tree3196f58f46401acf31d4c3696c1ac51472d69454 /searx
parent776ac0add822612d749965d4d354f3ad0ce73a70 (diff)
[fix] restore startpage autocompleter
Changes: - Undo deletions of the autocompleter in settings and logic - Add fixed autocomplete function in autocomplete.py Related: - https://github.com/searxng/searxng/issues/4334
Diffstat (limited to 'searx')
-rw-r--r--searx/autocomplete.py49
-rw-r--r--searx/settings.yml2
2 files changed, 49 insertions, 2 deletions
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