From 7fd5e74ea91d31618ac951be0f62e4a15846322f Mon Sep 17 00:00:00 2001 From: DiamondDemon669 <62653580+DiamondDemon669@users.noreply.github.com> Date: Thu, 21 Jul 2022 01:12:06 +0100 Subject: [PATCH 1/5] Create query_strings.py --- searx/plugins/query_strings.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 searx/plugins/query_strings.py diff --git a/searx/plugins/query_strings.py b/searx/plugins/query_strings.py new file mode 100644 index 000000000..af49405d5 --- /dev/null +++ b/searx/plugins/query_strings.py @@ -0,0 +1,23 @@ +import shlex, string + +name = "query strings" +description = 'adds site:, - and "" to searx' +default_on = True + +def on_result(request, search, result): + q = search.search_query.query + qs = shlex.split(q) + spitems = [x.lower() for x in qs if ' ' in x] + mitems = [x.lower() for x in qs if x.startswith('-')] + siteitems = [x.lower() for x in qs if x.startswith('site:')] + msiteitems = [x.lower() for x in qs if x.startswith('-site:')] + url, title, content = result["url"].lower(), result["title"].lower(), (result.get("content").lower() if result.get("content") else '') + if all(x not in title or content for x in spitems): + return False + if all(x in title or content for x in mitems): + return False + if all(x not in url for x in siteitems): + return False + if all(x in url for x in msiteitems): + return False + return True From d0488e533b5e34ab81a9ab6e14b4aea36c9c3790 Mon Sep 17 00:00:00 2001 From: DiamondDemon669 <62653580+DiamondDemon669@users.noreply.github.com> Date: Thu, 21 Jul 2022 01:23:31 +0100 Subject: [PATCH 2/5] Registered plugin --- searx/plugins/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index 8ece94358..758c669bf 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -212,6 +212,7 @@ class PluginStore: plugins = PluginStore() +plugins.register('./query_strings.py') def plugin_module_names(): yield_plugins = set() From bab35de7b04b579dc46ff00483078207c4303d1b Mon Sep 17 00:00:00 2001 From: DiamondDemon669 <62653580+DiamondDemon669@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:18:25 +0100 Subject: [PATCH 3/5] Enabled query strings plugin Suggested by Solirs --- searx/settings.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/searx/settings.yml b/searx/settings.yml index 21f0f20b3..70dd2e466 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -176,7 +176,8 @@ outgoing: # Comment or un-comment plugin to activate / deactivate by default. # -# enabled_plugins: +enabled_plugins: + - 'query strings' # # these plugins are enabled if nothing is configured .. # - 'Hash plugin' # - 'Search on category select' From eb4c237c9dfbb07212eb68c9af7fc3b4ba39901f Mon Sep 17 00:00:00 2001 From: DiamondDemon669 <62653580+DiamondDemon669@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:21:16 +0100 Subject: [PATCH 4/5] Enabled translations and fixed condition bug --- searx/plugins/query_strings.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/searx/plugins/query_strings.py b/searx/plugins/query_strings.py index af49405d5..ee7b5f583 100644 --- a/searx/plugins/query_strings.py +++ b/searx/plugins/query_strings.py @@ -1,7 +1,8 @@ import shlex, string +from flask_babel import gettext -name = "query strings" -description = 'adds site:, - and "" to searx' +name = gettext("query strings") +description = gettext('adds site:, - and "" to searx') default_on = True def on_result(request, search, result): @@ -12,9 +13,9 @@ def on_result(request, search, result): siteitems = [x.lower() for x in qs if x.startswith('site:')] msiteitems = [x.lower() for x in qs if x.startswith('-site:')] url, title, content = result["url"].lower(), result["title"].lower(), (result.get("content").lower() if result.get("content") else '') - if all(x not in title or content for x in spitems): + if all(x not in (title or content) for x in spitems): return False - if all(x in title or content for x in mitems): + if all(x in (title or content) for x in mitems): return False if all(x not in url for x in siteitems): return False From 121993abcd66b895a0c6718b570222815c216de9 Mon Sep 17 00:00:00 2001 From: DiamondDemon669 <62653580+DiamondDemon669@users.noreply.github.com> Date: Fri, 22 Jul 2022 00:26:38 +0100 Subject: [PATCH 5/5] Small bugfix --- searx/plugins/query_strings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searx/plugins/query_strings.py b/searx/plugins/query_strings.py index ee7b5f583..af0e31cc4 100644 --- a/searx/plugins/query_strings.py +++ b/searx/plugins/query_strings.py @@ -13,9 +13,9 @@ def on_result(request, search, result): siteitems = [x.lower() for x in qs if x.startswith('site:')] msiteitems = [x.lower() for x in qs if x.startswith('-site:')] url, title, content = result["url"].lower(), result["title"].lower(), (result.get("content").lower() if result.get("content") else '') - if all(x not in (title or content) for x in spitems): + if all((x not in title or x not in content) for x in spitems): return False - if all(x in (title or content) for x in mitems): + if all((x in title or x in content) for x in mitems): return False if all(x not in url for x in siteitems): return False