1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-22 12:10:11 +01:00

[mod] searx.search.EngineRef: remove from_bang parameter

from_bang is True when the user query contains a bang.
In this case the category is also set to 'none'.

from_bang only usage was in searx.webadapter.parse_specific :
if from_bang is True, then the EngineRef category is ignored and force to 'none'.

This commit also removes the searx.webadapter.parse_sepecific function.
This commit is contained in:
Alexandre Flament 2020-12-18 12:19:14 +01:00
parent 995ba2f406
commit eda8934f15
5 changed files with 12 additions and 24 deletions

View File

@ -125,12 +125,12 @@ class RawTextQuery:
searx_query_part = True searx_query_part = True
engine_name = engine_shortcuts[prefix] engine_name = engine_shortcuts[prefix]
if engine_name in engines: 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 # check if prefix is equal with engine name
elif prefix in engines: elif prefix in engines:
searx_query_part = True 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 # check if prefix is equal with categorie name
elif prefix in categories: elif prefix in categories:

View File

@ -52,18 +52,17 @@ def initialize(settings_engines=None):
class EngineRef: 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.name = name
self.category = category self.category = category
self.from_bang = from_bang
def __repr__(self): 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): 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: class SearchQuery:

View File

@ -109,17 +109,6 @@ def parse_timeout(form: Dict[str, str], raw_text_query: RawTextQuery) -> Optiona
raise SearxParameterException('timeout_limit', timeout_limit) 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)
return query_engineref_list
def parse_category_form(query_categories: List[str], name: str, value: str) -> None: def parse_category_form(query_categories: List[str], name: str, value: str) -> None:
if name == 'categories': if name == 'categories':
query_categories.extend(categ for categ in map(str.strip, value.split(',')) if categ in categories) query_categories.extend(categ for categ in map(str.strip, value.split(',')) if categ in categories)
@ -232,7 +221,7 @@ 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 not is_locked('categories') and raw_text_query.enginerefs and raw_text_query.specific:
# if engines are calculated from query, # if engines are calculated from query,
# set categories by using that informations # set categories by using that informations
query_engineref_list = parse_specific(raw_text_query) query_engineref_list = raw_text_query.enginerefs
else: else:
# otherwise, using defined categories to # otherwise, using defined categories to
# calculate which engines should be used # calculate which engines should be used

View File

@ -23,13 +23,13 @@ TEST_ENGINES = [
class SearchQueryTestCase(SearxTestCase): class SearchQueryTestCase(SearxTestCase):
def test_repr(self): def test_repr(self):
s = SearchQuery('test', [EngineRef('bing', 'general', False)], 'all', 0, 1, '1', 5.0, 'g') s = SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')
self.assertEqual(repr(s), self.assertEqual(repr(s),
"SearchQuery('test', [EngineRef('bing', 'general', False)], 'all', 0, 1, '1', 5.0, 'g')") # noqa "SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, '1', 5.0, 'g')") # noqa
def test_eq(self): def test_eq(self):
s = SearchQuery('test', [EngineRef('bing', 'general', False)], 'all', 0, 1, None, None, None) s = SearchQuery('test', [EngineRef('bing', 'general')], 'all', 0, 1, None, None, None)
t = SearchQuery('test', [EngineRef('google', 'general', False)], 'all', 0, 1, None, None, None) t = SearchQuery('test', [EngineRef('google', 'general')], 'all', 0, 1, None, None, None)
self.assertEqual(s, s) self.assertEqual(s, s)
self.assertNotEqual(s, t) self.assertNotEqual(s, t)

View File

@ -101,7 +101,7 @@ class StandaloneSearx(SearxTestCase):
args = sas.parse_argument(['rain', ]) args = sas.parse_argument(['rain', ])
search_q = sas.get_search_query(args) search_q = sas.get_search_query(args)
self.assertTrue(search_q) self.assertTrue(search_q)
self.assertEqual(search_q, SearchQuery('rain', [EngineRef('engine1', 'general', False)], self.assertEqual(search_q, SearchQuery('rain', [EngineRef('engine1', 'general')],
'all', 0, 1, None, None, None)) 'all', 0, 1, None, None, None))
def test_no_parsed_url(self): def test_no_parsed_url(self):