diff options
author | dalf <alex@al-f.net> | 2016-10-22 14:01:53 +0200 |
---|---|---|
committer | Alexandre Flament <alex@al-f.net> | 2016-11-02 14:22:16 +0100 |
commit | fbb080f3588ad43bf896a569257f3a95e1181d7b (patch) | |
tree | 8852a7af03c4e9bafe65885fae89417d47da7685 /searx/search.py | |
parent | 67e11c42b973932c8f568d80a0f25bfd7fc150ab (diff) | |
download | searxng-fbb080f3588ad43bf896a569257f3a95e1181d7b.tar.gz searxng-fbb080f3588ad43bf896a569257f3a95e1181d7b.zip |
Change plugin API :
- pre_search(request, search)
- post_search(request, search)
- on_result(request, search, result)
with
- request is the Flask request
- search a searx.Search instance
- result a searx result as usual
Diffstat (limited to 'searx/search.py')
-rw-r--r-- | searx/search.py | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/searx/search.py b/searx/search.py index a41c4b09a..a8de143b0 100644 --- a/searx/search.py +++ b/searx/search.py @@ -357,35 +357,23 @@ class Search(object): return self.result_container -def search_with_plugins(do_search, search_query, request, request_data, result_container): - """Search using the do_search function and with plugins filtering. - Standalone function to have a well define locals(). - result_container contains the results after the function call. - """ - search = search_query - - if plugins.call('pre_search', request, locals()): - do_search() - - plugins.call('post_search', request, locals()) - - results = result_container.get_ordered_results() - - for result in results: - plugins.call('on_result', request, locals()) - - class SearchWithPlugins(Search): + """Similar to the Search class but call the plugins.""" + def __init__(self, search_query, request): super(SearchWithPlugins, self).__init__(search_query) self.request = request - self.request_data = request.request_data def search(self): - - def do_search(): + if plugins.call('pre_search', self.request, self): super(SearchWithPlugins, self).search() - search_with_plugins(do_search, self.search_query, self.request, self.request_data, self.result_container) + plugins.call('post_search', self.request, self) + + results = self.result_container.get_ordered_results() + + for result in results: + plugins.call('on_result', self.request, self, result) + return self.result_container |