mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
Fix elasticsearch custom_query.
This commit is contained in:
parent
f6f622f7e5
commit
bc5068fece
2 changed files with 147 additions and 6 deletions
|
|
@ -135,14 +135,38 @@ def _terms_query(query):
|
|||
|
||||
|
||||
def _custom_query(query):
|
||||
key, value = query.split(':')
|
||||
custom_query = custom_query_json
|
||||
key = value = None
|
||||
if any(placeholder in custom_query_json for placeholder in ["{{KEY}}", "{{VALUE}}", "{{VALUES}}"]):
|
||||
try:
|
||||
key, value = query.split(':', maxsplit=1)
|
||||
except Exception as e:
|
||||
raise ValueError('query format must be "key:value"') from e
|
||||
if not key:
|
||||
raise ValueError('empty key from "key:value" query')
|
||||
try:
|
||||
custom_query = loads(custom_query_json)
|
||||
except Exception as e:
|
||||
raise ValueError('invalid custom_query string') from e
|
||||
return _custom_query_r(query, key, value, custom_query)
|
||||
|
||||
|
||||
def _custom_query_r(query, key, value, custom_query):
|
||||
new_query = {}
|
||||
for query_key, query_value in custom_query.items():
|
||||
if query_key == '{{KEY}}':
|
||||
custom_query[key] = custom_query.pop(query_key)
|
||||
if query_value == '{{VALUE}}':
|
||||
custom_query[query_key] = value
|
||||
return custom_query
|
||||
query_key = key
|
||||
|
||||
if isinstance(query_value, dict):
|
||||
query_value = _custom_query_r(query, key, value, query_value)
|
||||
elif query_value == '{{VALUE}}':
|
||||
query_value = value
|
||||
elif query_value == '{{VALUES}}':
|
||||
query_value = value.split(',')
|
||||
elif query_value == '{{QUERY}}':
|
||||
query_value = query
|
||||
|
||||
new_query[query_key] = query_value
|
||||
return new_query
|
||||
|
||||
|
||||
def response(resp):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue