diff options
| author | Alexandre Flament <alex@al-f.net> | 2020-12-16 13:41:32 +0100 |
|---|---|---|
| committer | Alexandre Flament <alex@al-f.net> | 2020-12-17 11:39:36 +0100 |
| commit | 7ec8bc3ea76516e33318c67165161df5c1efdd36 (patch) | |
| tree | 6c9dff310882db816cada8662ef5ed2b8a8158e8 /searx/search/processors/abstract.py | |
| parent | c0cc01e936593ff3df828fa3bb834507c45cd7ac (diff) | |
[mod] split searx.search into different processors
see searx.search.processors.abstract.EngineProcessor
First the method searx call the get_params method.
If the return value is not None, then the searx call the method search.
Diffstat (limited to 'searx/search/processors/abstract.py')
| -rw-r--r-- | searx/search/processors/abstract.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/searx/search/processors/abstract.py b/searx/search/processors/abstract.py new file mode 100644 index 000000000..cf3fd7236 --- /dev/null +++ b/searx/search/processors/abstract.py @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later + +from abc import abstractmethod +from searx import logger + + +logger = logger.getChild('searx.search.processor') + + +class EngineProcessor: + + def __init__(self, engine, engine_name): + self.engine = engine + self.engine_name = engine_name + + def get_params(self, search_query, engine_category): + # if paging is not supported, skip + if search_query.pageno > 1 and not self.engine.paging: + return None + + # if time_range is not supported, skip + if search_query.time_range and not self.engine.time_range_support: + return None + + params = {} + params['category'] = engine_category + params['pageno'] = search_query.pageno + params['safesearch'] = search_query.safesearch + params['time_range'] = search_query.time_range + + if hasattr(self.engine, 'language') and self.engine.language: + params['language'] = self.engine.language + else: + params['language'] = search_query.lang + return params + + @abstractmethod + def search(self, query, params, result_container, start_time, timeout_limit): + pass |