Commit 40dae047 authored by Élodie Thiéblin's avatar Élodie Thiéblin
Browse files

[do_search] Deal with list as parameter value

A list of values for a parameter is obtained with a URL
such as &param=value1&param=value2
The returned dictionary will be:
{ param : [value1, value2]}
parent 9f3bcbc769dc
Pipeline #13402 passed with stage
in 2 minutes and 18 seconds
......@@ -32,6 +32,20 @@ from cubicweb_elasticsearch.es import get_connection
from cubicweb_elasticsearch.search_helpers import compose_search
def normalize_value(value):
# FIXME TODO have better typing mechanisme (inspect facets?)
try:
if value.lower() == 'true':
return True
elif value.lower() == 'false':
return False
else:
return int(value)
except ValueError:
pass
return value
class CWFacetedSearch(FacetedSearch):
# fields that should be searched
fields = ["title^3", "description^2", 'alltext']
......@@ -107,16 +121,12 @@ class ElasticSearchView(StartupView):
start, stop = 0, 10
for key, value in self._cw.form.items():
if key.startswith('es_'):
# FIXME TODO have better typing mechanisme (inspect facets?)
try:
if value.lower() == 'true':
value = True
elif value.lower() == 'false':
value = False
else:
value = int(value)
except ValueError:
pass
if isinstance(value, list):
for index in range(len(value)):
value[index] = normalize_value(value[index])
else:
value = normalize_value(value)
facet_selections[key.replace('es_', '')] = value
if key == 'page':
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment