summaryrefslogtreecommitdiff
path: root/searx
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2020-12-20 09:32:54 +0100
committerGitHub <noreply@github.com>2020-12-20 09:32:54 +0100
commit04447f8c1a32aa2d1a2209d0a120ce04435c1346 (patch)
tree7ae38f290f3c2d25547ca4de1c2cb2173e342856 /searx
parent35feb00a5b76ecebc0259f9ff09d6f62a9c3319a (diff)
parenteda8934f1548ed228d00a0196b61d35585ea11bc (diff)
downloadsearxng-04447f8c1a32aa2d1a2209d0a120ce04435c1346.tar.gz
searxng-04447f8c1a32aa2d1a2209d0a120ce04435c1346.zip
Merge pull request #2398 from dalf/mod-search-query
Mod search query
Diffstat (limited to 'searx')
-rw-r--r--searx/query.py4
-rw-r--r--searx/search/__init__.py30
-rw-r--r--searx/webadapter.py29
3 files changed, 23 insertions, 40 deletions
diff --git a/searx/query.py b/searx/query.py
index 422cd57b5..e61e24f2c 100644
--- a/searx/query.py
+++ b/searx/query.py
@@ -125,12 +125,12 @@ class RawTextQuery:
searx_query_part = True
engine_name = engine_shortcuts[prefix]
if engine_name in engines:
- self.enginerefs.append(EngineRef(engine_name, 'none', True))
+ self.enginerefs.append(EngineRef(engine_name, 'none'))
# check if prefix is equal with engine name
elif prefix in engines:
searx_query_part = True
- self.enginerefs.append(EngineRef(prefix, 'none', True))
+ self.enginerefs.append(EngineRef(prefix, 'none'))
# check if prefix is equal with categorie name
elif prefix in categories:
diff --git a/searx/search/__init__.py b/searx/search/__init__.py
index 99459c7a3..0d45f0b7c 100644
--- a/searx/search/__init__.py
+++ b/searx/search/__init__.py
@@ -52,39 +52,36 @@ def initialize(settings_engines=None):
class EngineRef:
- __slots__ = 'name', 'category', 'from_bang'
+ __slots__ = 'name', 'category'
- def __init__(self, name: str, category: str, from_bang: bool=False):
+ def __init__(self, name: str, category: str):
self.name = name
self.category = category
- self.from_bang = from_bang
def __repr__(self):
- return "EngineRef({!r}, {!r}, {!r})".format(self.name, self.category, self.from_bang)
+ return "EngineRef({!r}, {!r})".format(self.name, self.category)
def __eq__(self, other):
- return self.name == other.name and self.category == other.category and self.from_bang == other.from_bang
+ return self.name == other.name and self.category == other.category
class SearchQuery:
"""container for all the search parameters (query, language, etc...)"""
- __slots__ = 'query', 'engineref_list', 'categories', 'lang', 'safesearch', 'pageno', 'time_range',\
+ __slots__ = 'query', 'engineref_list', 'lang', 'safesearch', 'pageno', 'time_range',\
'timeout_limit', 'external_bang'
def __init__(self,
query: str,
engineref_list: typing.List[EngineRef],
- categories: typing.List[str],
- lang: str,
- safesearch: int,
- pageno: int,
- time_range: typing.Optional[str],
+ 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.categories = categories
self.lang = lang
self.safesearch = safesearch
self.pageno = pageno
@@ -92,15 +89,18 @@ class SearchQuery:
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}, {!r})".\
- format(self.query, self.engineref_list, self.categories, self.lang, self.safesearch,
+ 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.categories == self.categories\
and self.lang == other.lang\
and self.safesearch == other.safesearch\
and self.pageno == other.pageno\
diff --git a/searx/webadapter.py b/searx/webadapter.py
index 7c71b7262..0ad82c62c 100644
--- a/searx/webadapter.py
+++ b/searx/webadapter.py
@@ -109,18 +109,6 @@ def parse_timeout(form: Dict[str, str], raw_text_query: RawTextQuery) -> Optiona
raise SearxParameterException('timeout_limit', timeout_limit)
-def parse_specific(raw_text_query: RawTextQuery) -> Tuple[List[EngineRef], List[str]]:
- query_engineref_list = raw_text_query.enginerefs
- additional_categories = set()
- for engineref in raw_text_query.enginerefs:
- if engineref.from_bang:
- additional_categories.add('none')
- else:
- additional_categories.add(engineref.category)
- query_categories = list(additional_categories)
- return query_engineref_list, query_categories
-
-
def parse_category_form(query_categories: List[str], name: str, value: str) -> None:
if name == 'categories':
query_categories.extend(categ for categ in map(str.strip, value.split(',')) if categ in categories)
@@ -171,8 +159,7 @@ def get_engineref_from_category_list(category_list: List[str], disabled_engines:
return result
-def parse_generic(preferences: Preferences, form: Dict[str, str], disabled_engines: List[str])\
- -> Tuple[List[EngineRef], List[str]]:
+def parse_generic(preferences: Preferences, form: Dict[str, str], disabled_engines: List[str]) -> List[EngineRef]:
query_engineref_list = []
query_categories = []
@@ -195,8 +182,6 @@ def parse_generic(preferences: Preferences, form: Dict[str, str], disabled_engin
if query_categories:
# add engines from referenced by the "categories" parameter and the "category_*"" parameters
query_engineref_list.extend(get_engineref_from_category_list(query_categories, disabled_engines))
- # get categories from the query_engineref_list
- query_categories = list(set(engine.category for engine in query_engineref_list))
else:
# no "engines" parameters in the form
if not query_categories:
@@ -208,7 +193,7 @@ def parse_generic(preferences: Preferences, form: Dict[str, str], disabled_engin
# declared under the specific categories
query_engineref_list.extend(get_engineref_from_category_list(query_categories, disabled_engines))
- return query_engineref_list, query_categories
+ return query_engineref_list
def get_search_query_from_webapp(preferences: Preferences, form: Dict[str, str])\
@@ -236,20 +221,18 @@ def get_search_query_from_webapp(preferences: Preferences, form: Dict[str, str])
if not is_locked('categories') and raw_text_query.enginerefs and raw_text_query.specific:
# if engines are calculated from query,
# set categories by using that informations
- query_engineref_list, query_categories = parse_specific(raw_text_query)
+ query_engineref_list = raw_text_query.enginerefs
else:
# otherwise, using defined categories to
# calculate which engines should be used
- query_engineref_list, query_categories = parse_generic(preferences, form, disabled_engines)
+ query_engineref_list = parse_generic(preferences, form, disabled_engines)
query_engineref_list = deduplicate_engineref_list(query_engineref_list)
query_engineref_list, query_engineref_list_unknown, query_engineref_list_notoken =\
validate_engineref_list(query_engineref_list, preferences)
- return (SearchQuery(query, query_engineref_list, query_categories,
- query_lang, query_safesearch, query_pageno,
- query_time_range, query_timeout,
- external_bang=external_bang),
+ return (SearchQuery(query, query_engineref_list, query_lang, query_safesearch, query_pageno,
+ query_time_range, query_timeout, external_bang=external_bang),
raw_text_query,
query_engineref_list_unknown,
query_engineref_list_notoken)