mirror of
https://github.com/searxng/searxng.git
synced 2026-05-07 18:03:51 +02:00
[feat] autocomplete: add bing autocompleter
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
|
||||
- ``360search``
|
||||
- ``baidu``
|
||||
- ``bing``
|
||||
- ``brave``
|
||||
- ``dbpedia``
|
||||
- ``duckduckgo``
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""This module implements functions needed for the autocompleter."""
|
||||
|
||||
# pylint: disable=use-dict-literal
|
||||
import string
|
||||
import random
|
||||
|
||||
import json
|
||||
import typing as t
|
||||
@@ -53,6 +56,26 @@ def baidu(query: str, _sxng_locale: str) -> list[str]:
|
||||
return results
|
||||
|
||||
|
||||
def bing(query: str, _sxng_locale: str) -> list[str]:
|
||||
# bing search autocompleter
|
||||
base_url = "https://www.bing.com/AS/Suggestions?"
|
||||
# cvid has to be a 32 character long string consisting of numbers and uppsercase characters
|
||||
cvid = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(32))
|
||||
response = get(base_url + urlencode({'qry': query, 'csr': 1, 'cvid': cvid}))
|
||||
results: list[str] = []
|
||||
|
||||
if response.ok:
|
||||
data: dict[str, t.Any] = response.json()
|
||||
if 's' in data:
|
||||
for item in data['s']:
|
||||
completion: str = item['q']
|
||||
# bing uses PUA unicode characters to highlight parts of the query
|
||||
# we have to remove these manually (U+E000 and U+E001)
|
||||
completion = completion.replace("\ue000", "").replace("\ue001", "")
|
||||
results.append(completion)
|
||||
return results
|
||||
|
||||
|
||||
def brave(query: str, _sxng_locale: str) -> list[str]:
|
||||
# brave search autocompleter
|
||||
url = 'https://search.brave.com/api/suggest?'
|
||||
@@ -331,6 +354,7 @@ def yandex(query: str, _sxng_locale: str) -> list[str]:
|
||||
backends: dict[str, t.Callable[[str, str], list[str]]] = {
|
||||
'360search': qihu360search,
|
||||
'baidu': baidu,
|
||||
'bing': bing,
|
||||
'brave': brave,
|
||||
'dbpedia': dbpedia,
|
||||
'duckduckgo': duckduckgo,
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ brand:
|
||||
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", "startpage", "swisscows", "quark", "qwant", "wikipedia" -
|
||||
# Existing autocomplete backends: "360search", "baidu", "bing", "brave", "dbpedia", "duckduckgo", "google",
|
||||
# "yandex", "mwmbl", "naver", "seznam", "sogou", "startpage", "swisscows", "quark", "qwant", "wikipedia" -
|
||||
# leave blank to turn it off by default.
|
||||
autocomplete: ""
|
||||
# minimun characters to type before autocompleter starts
|
||||
|
||||
Reference in New Issue
Block a user