Commit dbb919a2 authored by Guillaume Vandevelde's avatar Guillaume Vandevelde
Browse files

[es7] Adapt to es7 new total hits mechanic

parent e275070e9e2f
......@@ -47,6 +47,7 @@ class CWFacetedSearch(FacetedSearch):
doc_types=None,
index=None,
form=None,
track_total_hits=True,
**kwargs):
if index:
self.index = index
......@@ -56,9 +57,16 @@ class CWFacetedSearch(FacetedSearch):
self.form = form
else:
self.form = {}
# Count all the hits by default
self.track_total_hits = track_total_hits
self.extra_kwargs = kwargs
super(CWFacetedSearch, self).__init__(query, filters)
def search(self):
# override methods to add custom pieces
s = super(CWFacetedSearch, self).search()
return s.extra(track_total_hits=self.track_total_hits)
def query(self, search, query):
if query:
common = 'debug-es-disable-common' not in self.form # default True
......@@ -144,10 +152,10 @@ class ElasticSearchView(StartupView):
query_string = self._cw.form.get('q', self._cw.form.get('search', ''))
self.w(u'<h1>%s</h1>' % self._cw._(self.title))
response = self.do_search(query_string)
if response.hits.total:
if response.hits.total.value:
self.w(u'<h2>Resultats pour : <em>%s</em></h2>' %
xml_escape(query_string))
self.w(u'Resultats: %s' % response.hits.total)
self.w(u'Resultats: %s' % response.hits.total.value)
if hasattr(response, 'facets'):
self.display_facets(response)
self.display_results(response)
......@@ -217,7 +225,7 @@ class ElasticSearchView(StartupView):
'''
Pagination HTML generation
'''
if response.hits.total <= 10:
if response.hits.total.value <= 10:
return
url_params = self._cw.form.copy()
with t.ul(self.w, klass="pagination") as ul:
......@@ -228,7 +236,7 @@ class ElasticSearchView(StartupView):
href=xml_escape(self._cw.build_url(**url_params)))))
else:
ul(t.li(t.a(self.previous_link)))
total_pages = min((response.hits.total // 10) + 2, 1000)
total_pages = min((response.hits.total.value // 10) + 2, 1000)
page_padding = 3
if current_page > page_padding:
......
......@@ -140,7 +140,10 @@ def mock_execute(count):
return FacetedResponse(search, {
'hits': {
'hits': [_result(i) for i in range(count)],
'total': count,
'total': {
"value": count,
"relation": "eq"
},
}
})
......
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