forked from zaclys/searxng
commit
1b42d42695
|
@ -14,8 +14,8 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
from os.path import expanduser, isabs, realpath, commonprefix
|
from os.path import expanduser, isabs, realpath, commonprefix
|
||||||
from re import MULTILINE, search as re_search
|
|
||||||
from shlex import split as shlex_split
|
from shlex import split as shlex_split
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
from time import time
|
from time import time
|
||||||
|
@ -59,7 +59,7 @@ def init(engine_settings):
|
||||||
if 'parse_regex' in engine_settings:
|
if 'parse_regex' in engine_settings:
|
||||||
parse_regex = engine_settings['parse_regex']
|
parse_regex = engine_settings['parse_regex']
|
||||||
for result_key, regex in parse_regex.items():
|
for result_key, regex in parse_regex.items():
|
||||||
_compiled_parse_regex[result_key] = re.compile(regex, flags=MULTILINE)
|
_compiled_parse_regex[result_key] = re.compile(regex, flags=re.MULTILINE)
|
||||||
if 'delimiter' in engine_settings:
|
if 'delimiter' in engine_settings:
|
||||||
delimiter = engine_settings['delimiter']
|
delimiter = engine_settings['delimiter']
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from json import loads, dumps
|
from json import loads, dumps
|
||||||
from urllib.parse import html_to_text
|
from searx.utils import html_to_text
|
||||||
|
|
||||||
# engine dependent config
|
# engine dependent config
|
||||||
categories = ['science']
|
categories = ['science']
|
||||||
|
|
|
@ -122,9 +122,6 @@ def parse_specific(raw_text_query: RawTextQuery) -> Tuple[List[EngineRef], List[
|
||||||
|
|
||||||
|
|
||||||
def parse_category_form(query_categories: List[str], name: str, value: str) -> None:
|
def parse_category_form(query_categories: List[str], name: str, value: str) -> None:
|
||||||
if is_locked('categories'):
|
|
||||||
return preferences.get_value('categories')
|
|
||||||
|
|
||||||
if name == 'categories':
|
if name == 'categories':
|
||||||
query_categories.extend(categ for categ in map(str.strip, value.split(',')) if categ in categories)
|
query_categories.extend(categ for categ in map(str.strip, value.split(',')) if categ in categories)
|
||||||
elif name.startswith('category_'):
|
elif name.startswith('category_'):
|
||||||
|
@ -145,7 +142,7 @@ def parse_category_form(query_categories: List[str], name: str, value: str) -> N
|
||||||
def get_selected_categories(preferences: Preferences, form: Optional[Dict[str, str]]) -> List[str]:
|
def get_selected_categories(preferences: Preferences, form: Optional[Dict[str, str]]) -> List[str]:
|
||||||
selected_categories = []
|
selected_categories = []
|
||||||
|
|
||||||
if form is not None:
|
if not is_locked('categories') and form is not None:
|
||||||
for name, value in form.items():
|
for name, value in form.items():
|
||||||
parse_category_form(selected_categories, name, value)
|
parse_category_form(selected_categories, name, value)
|
||||||
|
|
||||||
|
@ -181,15 +178,17 @@ def parse_generic(preferences: Preferences, form: Dict[str, str], disabled_engin
|
||||||
|
|
||||||
# set categories/engines
|
# set categories/engines
|
||||||
explicit_engine_list = False
|
explicit_engine_list = False
|
||||||
for pd_name, pd in form.items():
|
if not is_locked('categories'):
|
||||||
if pd_name == 'engines':
|
# parse the form only if the categories are not locked
|
||||||
pd_engines = [EngineRef(engine_name, engines[engine_name].categories[0])
|
for pd_name, pd in form.items():
|
||||||
for engine_name in map(str.strip, pd.split(',')) if engine_name in engines]
|
if pd_name == 'engines':
|
||||||
if pd_engines:
|
pd_engines = [EngineRef(engine_name, engines[engine_name].categories[0])
|
||||||
query_engineref_list.extend(pd_engines)
|
for engine_name in map(str.strip, pd.split(',')) if engine_name in engines]
|
||||||
explicit_engine_list = True
|
if pd_engines:
|
||||||
else:
|
query_engineref_list.extend(pd_engines)
|
||||||
parse_category_form(query_categories, pd_name, pd)
|
explicit_engine_list = True
|
||||||
|
else:
|
||||||
|
parse_category_form(query_categories, pd_name, pd)
|
||||||
|
|
||||||
if explicit_engine_list:
|
if explicit_engine_list:
|
||||||
# explicit list of engines with the "engines" parameter in the form
|
# explicit list of engines with the "engines" parameter in the form
|
||||||
|
@ -234,7 +233,7 @@ def get_search_query_from_webapp(preferences: Preferences, form: Dict[str, str])
|
||||||
query_timeout = parse_timeout(form, raw_text_query)
|
query_timeout = parse_timeout(form, raw_text_query)
|
||||||
external_bang = raw_text_query.external_bang
|
external_bang = raw_text_query.external_bang
|
||||||
|
|
||||||
if raw_text_query.enginerefs and raw_text_query.specific:
|
if not is_locked('categories') and raw_text_query.enginerefs and raw_text_query.specific:
|
||||||
# if engines are calculated from query,
|
# if engines are calculated from query,
|
||||||
# set categories by using that informations
|
# set categories by using that informations
|
||||||
query_engineref_list, query_categories = parse_specific(raw_text_query)
|
query_engineref_list, query_categories = parse_specific(raw_text_query)
|
||||||
|
|
Loading…
Reference in New Issue