Browse Source

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

Add '?' bang to the autocompleter
Adam Tauber 10 years ago
parent
commit
f6b4220414
1 changed files with 9 additions and 8 deletions
  1. 9
    8
      searx/autocomplete.py

+ 9
- 8
searx/autocomplete.py View File

35
     results = []
35
     results = []
36
 
36
 
37
     # check if current query stats with !bang
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
         if len(full_query.getSearchQuery()) == 1:
40
         if len(full_query.getSearchQuery()) == 1:
40
             # show some example queries
41
             # show some example queries
41
             # TODO, check if engine is not avaliable
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
         else:
46
         else:
46
             engine_query = full_query.getSearchQuery()[1:]
47
             engine_query = full_query.getSearchQuery()[1:]
47
 
48
 
48
             # check if query starts with categorie name
49
             # check if query starts with categorie name
49
             for categorie in categories:
50
             for categorie in categories:
50
                 if categorie.startswith(engine_query):
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
             # check if query starts with engine name
54
             # check if query starts with engine name
54
             for engine in engines:
55
             for engine in engines:
55
                 if engine.startswith(engine_query.replace('_', ' ')):
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
             # check if query starts with engine shortcut
59
             # check if query starts with engine shortcut
59
             for engine_shortcut in engine_shortcuts:
60
             for engine_shortcut in engine_shortcuts:
60
                 if engine_shortcut.startswith(engine_query):
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
     # check if current query stats with :bang
64
     # check if current query stats with :bang
64
-    elif full_query.getSearchQuery()[0] == ':':
65
+    elif first_char == ':':
65
         if len(full_query.getSearchQuery()) == 1:
66
         if len(full_query.getSearchQuery()) == 1:
66
             # show some example queries
67
             # show some example queries
67
             results.append(":en")
68
             results.append(":en")