logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: b57258f98ba2748806084952486ea269afc1c896
parent: 88425f05d6c0e6124c625e52c684ef57f6a46827
Author: asciimoo <asciimoo@gmail.com>
Date:   Fri, 31 Jan 2014 15:55:38 +0100

[enh] query parsing improvements - shortcut support

Diffstat:

searx/webapp.py | 25+++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/searx/webapp.py b/searx/webapp.py @@ -26,7 +26,11 @@ from flask import url_for, Response, make_response, redirect from flask import send_from_directory from searx import settings, searx_dir -from searx.engines import search, categories, engines, get_engines_stats +from searx.engines import search +from searx.engines import categories +from searx.engines import engines +from searx.engines import get_engines_stats +from searx.engines import engine_shortcuts from searx.utils import UnicodeWriter from searx.utils import highlight_content, html_to_text from searx.languages import language_codes @@ -98,17 +102,18 @@ def parse_query(query): query_engines = [] query_parts = query.split() - if query_parts[0].startswith('-'): - engine_name = query_parts[0][1:].replace('_', ' ') - if engine_name in engines: + if query_parts[0].startswith('!'): + prefix = query_parts[0][1:].replace('_', ' ') + if prefix in engine_shortcuts: query_engines.append({'category': 'none', - 'name': query_parts[0][1:]}) - elif query_parts[0].startswith('!'): - category_name = query_parts[0][1:].replace('_', ' ') - if category_name in categories: - query_engines.extend({'category': category_name, + 'name': engine_shortcuts[prefix]}) + elif prefix in engines: + query_engines.append({'category': 'none', + 'name': prefix}) + elif prefix in categories: + query_engines.extend({'category': prefix, 'name': engine.name} - for engine in categories[category_name]) + for engine in categories[prefix]) if len(query_engines): query = query.replace(query_parts[0], '', 1).strip()