浏览代码

[search] Do not miss out values above the rounded max value of a range

Same for the minimum value
Romain Rigaux 10 年之前
父节点
当前提交
2fa2a9d
共有 2 个文件被更改,包括 12 次插入0 次删除
  1. 2 0
      apps/search/src/search/api.py
  2. 10 0
      apps/search/src/search/tests.py

+ 2 - 0
apps/search/src/search/api.py

@@ -68,6 +68,8 @@ def _guess_range_facet(widget_type, solr_api, collection, facet_field, propertie
         gap = int((end - start) / SLOTS)
       if gap < 1:
         gap = 1
+      start = min(start, stats_min)
+      end = max(end, stats_max)
     elif re.match('\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d\d?\d?)?Z', stat_facet['min']):
       is_date = True
       stats_min = stat_facet['min']

+ 10 - 0
apps/search/src/search/tests.py

@@ -27,11 +27,21 @@ from desktop.lib.django_test_util import make_logged_in_client
 from desktop.lib.test_utils import grant_access
 from desktop.lib.rest import resource
 
+from search.api import _round_number_range
 from search.models import Collection
 
 
 QUERY = {'qs': [{'q': ''}], 'fqs': [], 'start': 0}
 
+
+def test_ranges():
+  assert_equal((90.0, 100.0), _round_number_range(99))
+  assert_equal((0.0, 100.0), _round_number_range(100))
+  assert_equal((0.0, 100.0), _round_number_range(101))
+
+  assert_equal((8000000.0, 9000000.0), _round_number_range(9045352))
+
+
 class MockResource():
   RESPONSE = None