Skip to content
Snippets Groups Projects
Commit 9360d782237b authored by Arthur Lutz's avatar Arthur Lutz
Browse files

[views/facets] clickable facets

parent 7fe4a9f801f2
No related branches found
No related tags found
No related merge requests found
......@@ -80,4 +80,13 @@
query_string = xml_escape(self._cw.form.get('search', ''))
self.w(u'<h2>Résultats pour : <em>%s</em></h2>' % query_string)
get_connection(self._cw.vreg.config)
facet_selections = {}
start, stop = 0, 10
for key, value in self._cw.form.items():
if key.startswith('es_'):
facet_selections[key.replace('es_', '')] = value
if key == 'page':
start = (max(int(value) - 1, 0)) * 10
stop = start + 10
indexable = indexable_types(self._cw.vreg.schema)
search = CWFacetedSearch(query_string,
......@@ -83,7 +92,8 @@
search = CWFacetedSearch(query_string,
doc_types = indexable_types(self._cw.vreg.schema))
facet_selections,
doc_types=indexable)[start:stop]
try:
response = search.execute()
except NotFoundError:
self.w(u'index not found in elasticsearch')
return
......@@ -85,10 +95,11 @@
try:
response = search.execute()
except NotFoundError:
self.w(u'index not found in elasticsearch')
return
self.w(u'Resultats: %s' % response.hits.total)
self.display_facets(response)
self.w(u'Résultats: %s' % response.hits.total)
if response.facets:
self.display_facets(response)
self.display_results(response)
def display_results(self, response):
......@@ -121,7 +132,7 @@
self.w(u'''<aside id="aside-main-left" class="col-xs-2 cwjs-aside">
<div class="panel panel-default contextFreeBox facet_filterbox">
<div class="panel-heading">
<div class="panel-title">facettes</div>
<div class="panel-title">Facettes</div>
</div>
''')
for attribute in ('cw_etype', 'creation_date'):
......@@ -125,7 +136,8 @@
</div>
''')
for attribute in ('cw_etype', 'creation_date'):
url_params = self._cw.form.copy()
self.w(u'<div class="facetBody vocabularyFacet">')
self.w(u'<div class="facetTitle">{}</div>'.format(attribute))
for (tag, count, selected) in response.facets[attribute]:
# facetValueSelected / facetValueDisabled in class
......@@ -128,8 +140,19 @@
self.w(u'<div class="facetBody vocabularyFacet">')
self.w(u'<div class="facetTitle">{}</div>'.format(attribute))
for (tag, count, selected) in response.facets[attribute]:
# facetValueSelected / facetValueDisabled in class
facet_item = u'<div class="facetValue facetCheckBox"><span>{} {} {}</span></div>'
self.w(facet_item.format(tag, ' (SELECTED):' if selected else ':', count))
facet_item = u'<div class="facetValue facetCheckBox">' \
' <span>' \
' <a href="{}">{} {}</a>' \
' </span>' \
'</div>'
if url_params.get('es_{}'.format(attribute)) != tag:
url_params['es_{}'.format(attribute)] = str(tag)
else:
del url_params['es_{}'.format(attribute)]
url = self._cw.build_url(**url_params)
self.w(facet_item.format(url,
'<b>{}</b>'.format(tag) if selected else tag,
count))
self.w(u'</div>')
self.w(u'</div></aside>')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment