浏览代码

[enh] cleaner category/engine selection from GET/POST param - closes #289

Adam Tauber 10 年前
父节点
当前提交
b6de23f540
共有 1 个文件被更改,包括 15 次插入2 次删除
  1. 15
    2
      searx/search.py

+ 15
- 2
searx/search.py 查看文件

382
         # otherwise, using defined categories to
382
         # otherwise, using defined categories to
383
         # calculate which engines should be used
383
         # calculate which engines should be used
384
         else:
384
         else:
385
-            # set used categories
385
+            # set categories/engines
386
+            load_default_categories = True
386
             for pd_name, pd in self.request_data.items():
387
             for pd_name, pd in self.request_data.items():
387
-                if pd_name.startswith('category_'):
388
+                if pd_name == 'categories':
389
+                    self.categories.extend(categ for categ in pd.split(',') if categ in categories)
390
+                elif pd_name == 'engines':
391
+                    pd_engines = [{'category': engines[engine].categories[0],
392
+                                   'name': engine}
393
+                                  for engine in pd.split(',') if engine in engines]
394
+                    if pd_engines:
395
+                        self.engines.extend(pd_engines)
396
+                        load_default_categories = False
397
+                elif pd_name.startswith('category_'):
388
                     category = pd_name[9:]
398
                     category = pd_name[9:]
389
 
399
 
390
                     # if category is not found in list, skip
400
                     # if category is not found in list, skip
398
                         # remove category from list if property is set to 'off'
408
                         # remove category from list if property is set to 'off'
399
                         self.categories.remove(category)
409
                         self.categories.remove(category)
400
 
410
 
411
+            if not load_default_categories:
412
+                return
413
+
401
             # if no category is specified for this search,
414
             # if no category is specified for this search,
402
             # using user-defined default-configuration which
415
             # using user-defined default-configuration which
403
             # (is stored in cookie)
416
             # (is stored in cookie)