瀏覽代碼

Merge pull request #186 from Cqoicebordel/add-bang-autocompletion

Add '?' bang to the autocompleter
Adam Tauber 10 年之前
父節點
當前提交
f6b4220414
共有 1 個檔案被更改,包括 9 行新增8 行删除
  1. 9
    8
      searx/autocomplete.py

+ 9
- 8
searx/autocomplete.py 查看文件

@@ -35,33 +35,34 @@ def searx_bang(full_query):
35 35
     results = []
36 36
 
37 37
     # check if current query stats with !bang
38
-    if full_query.getSearchQuery()[0] == '!':
38
+    first_char = full_query.getSearchQuery()[0]
39
+    if first_char == '!' or first_char == '?':
39 40
         if len(full_query.getSearchQuery()) == 1:
40 41
             # show some example queries
41 42
             # TODO, check if engine is not avaliable
42
-            results.append("!images")
43
-            results.append("!wikipedia")
44
-            results.append("!osm")
43
+            results.append(first_char + "images")
44
+            results.append(first_char + "wikipedia")
45
+            results.append(first_char + "osm")
45 46
         else:
46 47
             engine_query = full_query.getSearchQuery()[1:]
47 48
 
48 49
             # check if query starts with categorie name
49 50
             for categorie in categories:
50 51
                 if categorie.startswith(engine_query):
51
-                    results.append('!{categorie}'.format(categorie=categorie))
52
+                    results.append(first_char+'{categorie}'.format(categorie=categorie))
52 53
 
53 54
             # check if query starts with engine name
54 55
             for engine in engines:
55 56
                 if engine.startswith(engine_query.replace('_', ' ')):
56
-                    results.append('!{engine}'.format(engine=engine.replace(' ', '_')))
57
+                    results.append(first_char+'{engine}'.format(engine=engine.replace(' ', '_')))
57 58
 
58 59
             # check if query starts with engine shortcut
59 60
             for engine_shortcut in engine_shortcuts:
60 61
                 if engine_shortcut.startswith(engine_query):
61
-                    results.append('!{engine_shortcut}'.format(engine_shortcut=engine_shortcut))
62
+                    results.append(first_char+'{engine_shortcut}'.format(engine_shortcut=engine_shortcut))
62 63
 
63 64
     # check if current query stats with :bang
64
-    elif full_query.getSearchQuery()[0] == ':':
65
+    elif first_char == ':':
65 66
         if len(full_query.getSearchQuery()) == 1:
66 67
             # show some example queries
67 68
             results.append(":en")