Browse Source

[search] Make corrrect the counts of an esc range facet

Fix the rounding of upper side too.
Romain Rigaux 10 years ago
parent
commit
423b76abd6
2 changed files with 3 additions and 3 deletions
  1. 2 2
      apps/search/src/search/models.py
  2. 1 1
      desktop/libs/libsolr/src/libsolr/api.py

+ 2 - 2
apps/search/src/search/models.py

@@ -468,13 +468,12 @@ def range_pair(field, cat, fq_filter, iterable, end, collection_facet):
   a, to = itertools.tee(iterable)
   a, to = itertools.tee(iterable)
   next(to, None)
   next(to, None)
   counts = iterable[1::2]
   counts = iterable[1::2]
-  total_counts = 0
+  total_counts = counts.pop(0) if collection_facet['properties']['sort'] == 'asc' else 0
 
 
   for element in a:
   for element in a:
     next(to, None)
     next(to, None)
     to_value = next(to, end)
     to_value = next(to, end)
     count = next(a)
     count = next(a)
-    total_counts += counts.pop(0)
 
 
     pairs.append({
     pairs.append({
         'field': field, 'from': element, 'value': count, 'to': to_value, 'selected': element in selected_values,
         'field': field, 'from': element, 'value': count, 'to': to_value, 'selected': element in selected_values,
@@ -483,6 +482,7 @@ def range_pair(field, cat, fq_filter, iterable, end, collection_facet):
         'total_counts': total_counts,
         'total_counts': total_counts,
         'is_up': is_up
         'is_up': is_up
     })
     })
+    total_counts += counts.pop(0) if counts else 0
 
 
   if collection_facet['properties']['sort'] == 'asc' and collection_facet['type'] != 'range-up':
   if collection_facet['properties']['sort'] == 'asc' and collection_facet['type'] != 'range-up':
     pairs.reverse()
     pairs.reverse()

+ 1 - 1
desktop/libs/libsolr/src/libsolr/api.py

@@ -101,7 +101,7 @@ class SolrApi(object):
                     utf_quoter('%s%s:[%s TO %s}' % ('-' if field['exclude'] else '', fq['field'], f['from'], f['to']))) for field, f in zip(fq['filter'], fq['properties'])])),)
                     utf_quoter('%s%s:[%s TO %s}' % ('-' if field['exclude'] else '', fq['field'], f['from'], f['to']))) for field, f in zip(fq['filter'], fq['properties'])])),)
       elif fq['type'] == 'range-up':
       elif fq['type'] == 'range-up':
         params += (('fq', '{!tag=%s}' % fq['field'] + ' '.join([urllib.unquote(
         params += (('fq', '{!tag=%s}' % fq['field'] + ' '.join([urllib.unquote(
-                    utf_quoter('%s%s:[%s TO %s]' % ('-' if field['exclude'] else '', fq['field'], f['from'] if fq['is_up'] else '*', '*' if fq['is_up'] else f['from'])))
+                    utf_quoter('%s%s:[%s TO %s}' % ('-' if field['exclude'] else '', fq['field'], f['from'] if fq['is_up'] else '*', '*' if fq['is_up'] else f['from'])))
                                                           for field, f in zip(fq['filter'], fq['properties'])])),)
                                                           for field, f in zip(fq['filter'], fq['properties'])])),)
     return params
     return params