Browse Source

[enh] better search language selection from query

asciimoo 11 years ago
parent
commit
7c031a3ea6
1 changed files with 12 additions and 3 deletions
  1. 12
    3
      searx/search.py

+ 12
- 3
searx/search.py View File

@@ -79,11 +79,20 @@ class Search(object):
79 79
         modified = False
80 80
         if query_parts[0].startswith(':'):
81 81
             lang = query_parts[0][1:]
82
-            if lang in (x[0] for x in language_codes):
83
-                self.lang = lang
84
-                modified = True
82
+
83
+            for lc in language_codes:
84
+                lang_id, lang_name, country = map(str.lower, lc)
85
+                if lang == lang_id\
86
+                   or lang_id.startswith(lang)\
87
+                   or lang == lang_name\
88
+                   or lang == country:
89
+                    self.lang = lang
90
+                    modified = True
91
+                    break
92
+
85 93
         elif query_parts[0].startswith('!'):
86 94
             prefix = query_parts[0][1:].replace('_', ' ')
95
+
87 96
             if prefix in engine_shortcuts\
88 97
                and not engine_shortcuts[prefix] in self.blocked_engines:
89 98
                 modified = True