mirror of
https://github.com/searxng/searxng.git
synced 2025-06-28 11:39:52 +00:00
[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
This commit is contained in:
parent
776ac0add8
commit
8757655644
3 changed files with 50 additions and 2 deletions
|
@ -46,6 +46,7 @@
|
|||
- ``qwant``
|
||||
- ``seznam``
|
||||
- ``sogou``
|
||||
- ``startpage``
|
||||
- ``stract``
|
||||
- ``swisscows``
|
||||
- ``wikipedia``
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue