From b6de23f540fc47099303eca82727128957136ea8 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 12 May 2015 08:21:39 +0200 Subject: [PATCH] [enh] cleaner category/engine selection from GET/POST param - closes #289 --- searx/search.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/searx/search.py b/searx/search.py index 862b17e33..1ec1c377d 100644 --- a/searx/search.py +++ b/searx/search.py @@ -382,9 +382,19 @@ class Search(object): # otherwise, using defined categories to # calculate which engines should be used else: - # set used categories + # set categories/engines + load_default_categories = True for pd_name, pd in self.request_data.items(): - if pd_name.startswith('category_'): + if pd_name == 'categories': + self.categories.extend(categ for categ in pd.split(',') if categ in categories) + elif pd_name == 'engines': + pd_engines = [{'category': engines[engine].categories[0], + 'name': engine} + for engine in pd.split(',') if engine in engines] + if pd_engines: + self.engines.extend(pd_engines) + load_default_categories = False + elif pd_name.startswith('category_'): category = pd_name[9:] # if category is not found in list, skip @@ -398,6 +408,9 @@ class Search(object): # remove category from list if property is set to 'off' self.categories.remove(category) + if not load_default_categories: + return + # if no category is specified for this search, # using user-defined default-configuration which # (is stored in cookie)