summaryrefslogtreecommitdiff
path: root/searx/search/models.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-01-05 11:24:39 +0100
committerAlexandre Flament <alex@al-f.net>2021-01-12 11:47:17 +0100
commit3a9f513521d006a7939538cce368d7b799e32c30 (patch)
tree238da19ef56643af53b13ef24a330277ed53ae51 /searx/search/models.py
parent6e2872f43625aba71eba019e16f7fbd74743f590 (diff)
downloadsearxng-3a9f513521d006a7939538cce368d7b799e32c30.tar.gz
searxng-3a9f513521d006a7939538cce368d7b799e32c30.zip
[enh] checker: background check
See settings.yml for the options SIGUSR1 signal starts the checker. The result is available at /stats/checker
Diffstat (limited to 'searx/search/models.py')
-rw-r--r--searx/search/models.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/searx/search/models.py b/searx/search/models.py
new file mode 100644
index 000000000..80ceaa223
--- /dev/null
+++ b/searx/search/models.py
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+import typing
+
+
+class EngineRef:
+
+ __slots__ = 'name', 'category'
+
+ def __init__(self, name: str, category: str):
+ self.name = name
+ self.category = category
+
+ def __repr__(self):
+ return "EngineRef({!r}, {!r})".format(self.name, self.category)
+
+ def __eq__(self, other):
+ return self.name == other.name and self.category == other.category
+
+ def __hash__(self):
+ return hash((self.name, self.category))
+
+
+class SearchQuery:
+ """container for all the search parameters (query, language, etc...)"""
+
+ __slots__ = 'query', 'engineref_list', 'lang', 'safesearch', 'pageno', 'time_range',\
+ 'timeout_limit', 'external_bang'
+
+ def __init__(self,
+ query: str,
+ engineref_list: typing.List[EngineRef],
+ lang: str='all',
+ safesearch: int=0,
+ pageno: int=1,
+ time_range: typing.Optional[str]=None,
+ timeout_limit: typing.Optional[float]=None,
+ external_bang: typing.Optional[str]=None):
+ self.query = query
+ self.engineref_list = engineref_list
+ self.lang = lang
+ self.safesearch = safesearch
+ self.pageno = pageno
+ self.time_range = time_range
+ self.timeout_limit = timeout_limit
+ self.external_bang = external_bang
+
+ @property
+ def categories(self):
+ return list(set(map(lambda engineref: engineref.category, self.engineref_list)))
+
+ def __repr__(self):
+ return "SearchQuery({!r}, {!r}, {!r}, {!r}, {!r}, {!r}, {!r}, {!r})".\
+ format(self.query, self.engineref_list, self.lang, self.safesearch,
+ self.pageno, self.time_range, self.timeout_limit, self.external_bang)
+
+ def __eq__(self, other):
+ return self.query == other.query\
+ and self.engineref_list == other.engineref_list\
+ and self.lang == other.lang\
+ and self.safesearch == other.safesearch\
+ and self.pageno == other.pageno\
+ and self.time_range == other.time_range\
+ and self.timeout_limit == other.timeout_limit\
+ and self.external_bang == other.external_bang
+
+ def __hash__(self):
+ return hash((self.query, tuple(self.engineref_list), self.lang, self.safesearch, self.pageno, self.time_range,
+ self.timeout_limit, self.external_bang))