mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Check if query is math
This commit is contained in:
parent
dec04c0ed6
commit
04d8c4304c
2 changed files with 16 additions and 1 deletions
|
@ -81,6 +81,7 @@ from searx.webutils import (
|
|||
is_hmac_of,
|
||||
is_flask_run_cmdline,
|
||||
group_engines_in_tab,
|
||||
is_math,
|
||||
)
|
||||
from searx.webadapter import (
|
||||
get_search_query_from_webapp,
|
||||
|
@ -851,7 +852,8 @@ def search():
|
|||
),
|
||||
theme = get_current_theme_name(),
|
||||
favicons = global_favicons[themes.index(get_current_theme_name())],
|
||||
timeout_limit = request.form.get('timeout_limit', None)
|
||||
timeout_limit = request.form.get('timeout_limit', None),
|
||||
is_math = is_math(search_query.query)
|
||||
# fmt: on
|
||||
)
|
||||
|
||||
|
|
|
@ -179,3 +179,16 @@ def group_engines_in_tab(engines: Iterable[Engine]) -> List[Tuple[str, Iterable[
|
|||
return (engine.about.get('language', ''), engine.name)
|
||||
|
||||
return [(groupname, sorted(engines, key=engine_sort_key)) for groupname, engines in sorted_groups]
|
||||
|
||||
def is_math(query):
|
||||
is_math = False
|
||||
characters = set(['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '/', '^', '%', '.', '+', '-', ','])
|
||||
numbers = 0
|
||||
|
||||
for i in query:
|
||||
if i in characters:
|
||||
numbers +=1
|
||||
|
||||
if len(query) < numbers+1:
|
||||
is_math = True
|
||||
return is_math
|
Loading…
Add table
Reference in a new issue