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] 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