From df71c24b2043195a94f3098f9b7371c6d6fb2dce Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 23 Aug 2023 15:24:42 +0200 Subject: [PATCH] [mod] autocomplete.py: add support for mwmbl completions --- docs/admin/settings/settings_search.rst | 1 + docs/dev/search_api.rst | 4 ++-- searx/autocomplete.py | 11 +++++++++++ searx/settings.yml | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/admin/settings/settings_search.rst b/docs/admin/settings/settings_search.rst index dcc0ff198..836207614 100644 --- a/docs/admin/settings/settings_search.rst +++ b/docs/admin/settings/settings_search.rst @@ -35,6 +35,7 @@ - ``dbpedia`` - ``duckduckgo`` - ``google`` + - ``mwmbl`` - ``startpage`` - ``swisscows`` - ``qwant`` diff --git a/docs/dev/search_api.rst b/docs/dev/search_api.rst index 2333474a9..423232090 100644 --- a/docs/dev/search_api.rst +++ b/docs/dev/search_api.rst @@ -68,8 +68,8 @@ Parameters Proxy image results through SearXNG. ``autocomplete`` : default from :ref:`settings search` - [ ``google``, ``dbpedia``, ``duckduckgo``, ``startpage``, ``wikipedia``, - ``swisscows``, ``qwant`` ] + [ ``google``, ``dbpedia``, ``duckduckgo``, ``mwmbl``, ``startpage``, + ``wikipedia``, ``swisscows``, ``qwant`` ] Service which completes words as you type. diff --git a/searx/autocomplete.py b/searx/autocomplete.py index ad9903f36..4f674dca7 100644 --- a/searx/autocomplete.py +++ b/searx/autocomplete.py @@ -110,6 +110,16 @@ def google_complete(query, sxng_locale): return results +def mwmbl(query, _lang): + # mwmbl autocompleter + url = 'https://api.mwmbl.org/search/complete?{query}' + + results = get(url.format(query=urlencode({'q': query}))).json()[1] + + # results starting with `go:` are direct urls and not useful for auto completion + return [result for result in results if not result.startswith("go: ") and not result.startswith("search: ")] + + def seznam(query, _lang): # seznam search autocompleter url = 'https://suggest.seznam.cz/fulltext/cs?{query}' @@ -208,6 +218,7 @@ backends = { 'dbpedia': dbpedia, 'duckduckgo': duckduckgo, 'google': google_complete, + 'mwmbl': mwmbl, 'seznam': seznam, 'startpage': startpage, 'swisscows': swisscows, diff --git a/searx/settings.yml b/searx/settings.yml index 070f5a99f..9f53c4d0f 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -23,7 +23,7 @@ brand: search: # Filter results. 0: None, 1: Moderate, 2: Strict safe_search: 0 - # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "yandex", + # Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "yandex", "mwmbl", # "seznam", "startpage", "swisscows", "qwant", "wikipedia" - leave blank to turn it off # by default. autocomplete: ""