commit: 7f45e8a562ea6a57ab9126b99cba87b9a40bfaa7
parent: 8305da3e5d755a28f1ad774d5e5100644c1b70ed
Author: asciimoo <asciimoo@gmail.com>
Date: Sun, 9 Feb 2014 01:07:18 +0100
[mod] query parsing refactor vol.1
Diffstat:
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/searx/search.py b/searx/search.py
@@ -13,7 +13,6 @@ class Search(object):
self.query = None
self.engines = []
self.categories = []
- query_engines = []
self.paging = False
self.pageno = 1
self.lang = 'all'
@@ -46,25 +45,7 @@ class Search(object):
self.pageno = int(pageno_param)
- query_parts = self.query.split()
- if query_parts[0].startswith('!'):
- prefix = query_parts[0][1:].replace('_', ' ')
- if prefix in engine_shortcuts\
- and not engine_shortcuts[prefix] in self.blocked_engines:
- self.engines.append({'category': 'none',
- 'name': engine_shortcuts[prefix]})
- elif prefix in engines\
- and not prefix in self.blocked_engines:
- self.engines.append({'category': 'none',
- 'name': prefix})
- elif prefix in categories:
- self.engines.extend({'category': prefix,
- 'name': engine.name}
- for engine in categories[prefix]
- if not engine in self.blocked_engines)
-
- if len(query_engines):
- self.query = self.query.replace(query_parts[0], '', 1).strip()
+ self.parse_query()
self.categories = []
@@ -92,3 +73,27 @@ class Search(object):
'name': x.name}
for x in categories[categ]
if not x.name in self.blocked_engines)
+
+ def parse_query(self):
+ query_parts = self.query.split()
+ modified = False
+ if query_parts[0].startswith('!'):
+ prefix = query_parts[0][1:].replace('_', ' ')
+ if prefix in engine_shortcuts\
+ and not engine_shortcuts[prefix] in self.blocked_engines:
+ modified = True
+ self.engines.append({'category': 'none',
+ 'name': engine_shortcuts[prefix]})
+ elif prefix in engines\
+ and not prefix in self.blocked_engines:
+ modified = True
+ self.engines.append({'category': 'none',
+ 'name': prefix})
+ elif prefix in categories:
+ modified = True
+ self.engines.extend({'category': prefix,
+ 'name': engine.name}
+ for engine in categories[prefix]
+ if not engine in self.blocked_engines)
+ if modified:
+ self.query = self.query.replace(query_parts[0], '', 1).strip()