Browse Source

[search] Logic for combining different date fields on the same dashboard

e.g.
indexed datetime
birthday date

with a timeline and a text widget on the indexed time
Romain Rigaux 10 years ago
parent
commit
0c9feb7

+ 3 - 1
apps/search/src/search/api.py

@@ -129,8 +129,10 @@ def _guess_range_facet(widget_type, solr_api, collection, facet_field, propertie
         gap = '+7DAYS'
         gap = '+7DAYS'
       elif difference < 3600 * 24 * 40:
       elif difference < 3600 * 24 * 40:
         gap = '+1MONTHS'
         gap = '+1MONTHS'
-      else:
+      elif difference < 3600 * 24 * 40 * 12:
         gap = '+1YEARS'
         gap = '+1YEARS'
+      else:
+        gap = '+10YEARS'
 
 
     properties.update({
     properties.update({
       'min': stats_min,
       'min': stats_min,

+ 5 - 1
desktop/core/src/desktop/static/desktop/js/ko.hue-bindings.js

@@ -275,6 +275,10 @@ ko.bindingHandlers.daterangepicker = {
     {
     {
       value: "+1YEARS",
       value: "+1YEARS",
       label: "1y"
       label: "1y"
+    },
+    {
+      value: "+10YEARS",
+      label: "10y"
     }
     }
   ],
   ],
   EXTRA_INTERVAL_OPTIONS: [],
   EXTRA_INTERVAL_OPTIONS: [],
@@ -616,7 +620,7 @@ ko.bindingHandlers.daterangepicker = {
         _opts = enableOptions("1DAYS", "7DAYS", "1MONTHS", "6MONTHS");
         _opts = enableOptions("1DAYS", "7DAYS", "1MONTHS", "6MONTHS");
       }
       }
       if (_calculatedEndDate.diff(_calculatedStartDate, 'months') > 12) {
       if (_calculatedEndDate.diff(_calculatedStartDate, 'months') > 12) {
-        _opts = enableOptions("7DAYS", "1MONTHS", "6MONTHS", "1YEARS");
+        _opts = enableOptions("7DAYS", "1MONTHS", "6MONTHS", "1YEARS", "10YEARS");
       }
       }
 
 
       $(".interval-select").html(renderOptions(_opts));
       $(".interval-select").html(renderOptions(_opts));

+ 9 - 5
desktop/libs/libsolr/src/libsolr/api.py

@@ -127,11 +127,15 @@ class SolrApi(object):
             'facet-widget': {'coeff': '+1', 'unit': 'YEARS'},
             'facet-widget': {'coeff': '+1', 'unit': 'YEARS'},
         }
         }
     }
     }
-    fq_fields = [fq['field'] for fq in query['fqs']]
+
     time_field = collection['timeFilter'].get('field')
     time_field = collection['timeFilter'].get('field')
+    
+    if time_field:
+      # fqs overrides main time filter
+      fq_time_ids = [fq['id'] for fq in query['fqs'] if fq['field'] == time_field]
+      props['time_filter_overrides'] = fq_time_ids
+      props['time_field'] = time_field
 
 
-    # fqs overrides main time filter
-    if time_field and time_field not in fq_fields or True:
       if collection['timeFilter']['type'] == 'rolling' and collection['timeFilter']['value'] != 'all': # todo all for chart range? guess based on min
       if collection['timeFilter']['type'] == 'rolling' and collection['timeFilter']['value'] != 'all': # todo all for chart range? guess based on min
         props['field'] = collection['timeFilter']['field']
         props['field'] = collection['timeFilter']['field']
         props['from'] = 'NOW-%s' % collection['timeFilter']['value']
         props['from'] = 'NOW-%s' % collection['timeFilter']['value']
@@ -148,7 +152,7 @@ class SolrApi(object):
     params = ()
     params = ()
 
 
     timeFilter = self._get_range_borders(collection, query)
     timeFilter = self._get_range_borders(collection, query)
-    if timeFilter:
+    if timeFilter and not timeFilter.get('time_filter_overrides'):
       params += (('fq', urllib.unquote(utf_quoter('%(field)s:[%(from)s TO %(to)s}' % timeFilter))),)
       params += (('fq', urllib.unquote(utf_quoter('%(field)s:[%(from)s TO %(to)s}' % timeFilter))),)
 
 
     # Merge facets queries on same fields
     # Merge facets queries on same fields
@@ -232,7 +236,7 @@ class SolrApi(object):
               'mincount': int(facet['properties']['mincount'])
               'mincount': int(facet['properties']['mincount'])
           }
           }
 
 
-          if timeFilter:
+          if timeFilter and timeFilter['time_field'] == facet['field'] and (facet['id'] not in timeFilter['time_filter_overrides'] or facet['widgetType'] != 'histogram-widget'):
             gap = timeFilter['gap'][facet['widgetType']]
             gap = timeFilter['gap'][facet['widgetType']]
             keys.update({
             keys.update({
               'start': '%(from)s/%(unit)s' % {'from': timeFilter['from'], 'unit': gap['unit']},
               'start': '%(from)s/%(unit)s' % {'from': timeFilter['from'], 'unit': gap['unit']},