diff options
author | Markus Heiser <markus.heiser@darmarit.de> | 2024-04-08 09:15:46 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-04-08 10:56:11 +0200 |
commit | f1a148f53e9fbd10e95baa442b40327732259f25 (patch) | |
tree | 20ce64b82a33f635f27d319cd078b222534dccc0 | |
parent | bd6ff29f8f199c9835bfc5090ea5c4eba25cf3f1 (diff) | |
download | searxng-f1a148f53e9fbd10e95baa442b40327732259f25.tar.gz searxng-f1a148f53e9fbd10e95baa442b40327732259f25.zip |
[fix] ddg engine: if no vqd value can be determined, don't save None
Closes: https://github.com/searxng/searxng/issues/3370
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
-rw-r--r-- | searx/engines/duckduckgo.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index ac78c3b60..8a1dafbcf 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -124,7 +124,8 @@ def get_vqd(query): value = value[: value.index('"')] break logger.debug("new vqd value: '%s'", value) - cache_vqd(query, value) + if value is not None: + cache_vqd(query, value) return value @@ -221,13 +222,10 @@ ddg_lang_map = { } -def request(query, params): - - # request needs a vqd argument - vqd = get_vqd(query) - +def quote_ddg_bangs(query): # quote ddg bangs query_parts = [] + # for val in re.split(r'(\s+)', query): for val in re.split(r'(\s+)', query): if not val.strip(): @@ -235,7 +233,15 @@ def request(query, params): if val.startswith('!') and external_bang.get_node(external_bang.EXTERNAL_BANGS, val[1:]): val = f"'{val}'" query_parts.append(val) - query = ' '.join(query_parts) + return ' '.join(query_parts) + + +def request(query, params): + + query = quote_ddg_bangs(query) + + # request needs a vqd argument + vqd = get_vqd(query) eng_region = traits.get_region(params['searxng_locale'], traits.all_locale) # eng_lang = get_ddg_lang(traits, params['searxng_locale']) |