2022-07-21 00:12:06 +00:00
|
|
|
import shlex, string
|
2022-07-21 23:21:16 +00:00
|
|
|
from flask_babel import gettext
|
2022-07-21 00:12:06 +00:00
|
|
|
|
2022-07-21 23:21:16 +00:00
|
|
|
name = gettext("query strings")
|
|
|
|
description = gettext('adds site:, - and "" to searx')
|
2022-07-21 00:12:06 +00:00
|
|
|
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 '')
|
2022-07-21 23:26:38 +00:00
|
|
|
if all((x not in title or x not in content) for x in spitems):
|
2022-07-21 00:12:06 +00:00
|
|
|
return False
|
2022-07-21 23:26:38 +00:00
|
|
|
if all((x in title or x in content) for x in mitems):
|
2022-07-21 00:12:06 +00:00
|
|
|
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
|