浏览代码

Add non exclusif bang

Allow to perform a search while adding an engine (or a category) without adding it "officially" to the request.
'?' is used to add an engine without modifying anything else to the request. For example, you can perform a search in the 'general' category, and if you add '?tw' the result from Twitter will be added to the originals results.
Cqoicebordel 10 年前
父节点
当前提交
96c4d52eef
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 5
    1
      searx/query.py
  2. 1
    1
      searx/search.py

+ 5
- 1
searx/query.py 查看文件

@@ -38,6 +38,7 @@ class Query(object):
38 38
         self.query_parts = []
39 39
         self.engines = []
40 40
         self.languages = []
41
+        self.specific = False
41 42
 
42 43
     # parse query, if tags are set, which
43 44
     # change the serch engine or search-language
@@ -83,7 +84,7 @@ class Query(object):
83 84
                         break
84 85
 
85 86
             # this force a engine or category
86
-            if query_part[0] == '!':
87
+            if query_part[0] == '!' or query_part[0] == '?':
87 88
                 prefix = query_part[1:].replace('_', ' ')
88 89
 
89 90
                 # check if prefix is equal with engine shortcut
@@ -110,6 +111,9 @@ class Query(object):
110 111
                                         for engine in categories[prefix]
111 112
                                         if engine not in self.blocked_engines)
112 113
 
114
+            if query_part[0] == '!':
115
+                self.specific = True
116
+
113 117
             # append query part to query_part list
114 118
             self.query_parts.append(query_part)
115 119
 

+ 1
- 1
searx/search.py 查看文件

@@ -371,7 +371,7 @@ class Search(object):
371 371
 
372 372
         # if engines are calculated from query,
373 373
         # set categories by using that informations
374
-        if self.engines:
374
+        if self.engines and query_obj.specific:
375 375
             self.categories = list(set(engine['category']
376 376
                                        for engine in self.engines))
377 377