mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[enh] query parsing improvements - shortcut support
This commit is contained in:
parent
88425f05d6
commit
b57258f98b
@ -26,7 +26,11 @@ from flask import url_for, Response, make_response, redirect
|
|||||||
from flask import send_from_directory
|
from flask import send_from_directory
|
||||||
|
|
||||||
from searx import settings, searx_dir
|
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 UnicodeWriter
|
||||||
from searx.utils import highlight_content, html_to_text
|
from searx.utils import highlight_content, html_to_text
|
||||||
from searx.languages import language_codes
|
from searx.languages import language_codes
|
||||||
@ -98,17 +102,18 @@ def parse_query(query):
|
|||||||
query_engines = []
|
query_engines = []
|
||||||
query_parts = query.split()
|
query_parts = query.split()
|
||||||
|
|
||||||
if query_parts[0].startswith('-'):
|
if query_parts[0].startswith('!'):
|
||||||
engine_name = query_parts[0][1:].replace('_', ' ')
|
prefix = query_parts[0][1:].replace('_', ' ')
|
||||||
if engine_name in engines:
|
if prefix in engine_shortcuts:
|
||||||
query_engines.append({'category': 'none',
|
query_engines.append({'category': 'none',
|
||||||
'name': query_parts[0][1:]})
|
'name': engine_shortcuts[prefix]})
|
||||||
elif query_parts[0].startswith('!'):
|
elif prefix in engines:
|
||||||
category_name = query_parts[0][1:].replace('_', ' ')
|
query_engines.append({'category': 'none',
|
||||||
if category_name in categories:
|
'name': prefix})
|
||||||
query_engines.extend({'category': category_name,
|
elif prefix in categories:
|
||||||
|
query_engines.extend({'category': prefix,
|
||||||
'name': engine.name}
|
'name': engine.name}
|
||||||
for engine in categories[category_name])
|
for engine in categories[prefix])
|
||||||
|
|
||||||
if len(query_engines):
|
if len(query_engines):
|
||||||
query = query.replace(query_parts[0], '', 1).strip()
|
query = query.replace(query_parts[0], '', 1).strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user