Bladeren bron

HUE-2173 [search] Preparing multi series analytics charts

Romain Rigaux 10 jaren geleden
bovenliggende
commit
73c52359f4

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

@@ -732,9 +732,12 @@ def augment_solr_response(response, collection, query):
         value = response['facets'][name]
         collection_facet = get_facet_field(category, name, collection['facets'])
 
-        # if 2D
+        # none empty
+
+        countss = []
         buckets = []
-        for bucket in response['facets'][name]['buckets']:
+        print response['facets'][name]['buckets']
+        for bucket in response['facets'][name]['buckets']:          
           buckets.append(bucket['val'])
           if 'd2' in bucket:
             buckets.append(bucket['d2'])
@@ -751,6 +754,7 @@ def augment_solr_response(response, collection, query):
           'label': collection_facet['label'],
           'counts': counts,
         }
+        print facet['counts']
         normalized_facets.append(facet)
 
     # Remove unnecessary facet data

+ 2 - 1
apps/search/src/search/templates/search.mako

@@ -296,7 +296,7 @@ ${ dashboard.layout_skeleton() }
       </div>
     <!-- /ko -->
 
-    <!-- ko if: type() == 'range' || type() == 'range-up' -->
+    <!-- ko if: type() == 'range' || type() == 'range-up' || (type() == 'terms' && properties.min)-->
       <!-- ko ifnot: properties.isDate() -->
         <div class="slider-cnt" data-bind="slider: {start: properties.min, end: properties.max, gap: properties.initial_gap, min: properties.initial_start, max: properties.initial_end, properties: properties, labels: SLIDER_LABELS}"></div>
       <!-- /ko -->
@@ -1632,6 +1632,7 @@ function _barChartDataTransformer(rawDatum, isUp) {
     key: rawDatum.label,
     values: _data
   });
+
   return _datum;
 }
 

+ 6 - 0
apps/search/src/search/views.py

@@ -497,6 +497,12 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       properties['initial_gap'] = properties['gap']
       properties['initial_start'] = properties['start']
       properties['initial_end'] = properties['end']
+      
+      facet_type = 'terms' # if 5.2+ --> unify all
+      properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'function': 'count'}
+      properties['facets'] = []
+      properties['scope'] = 'stack'
+      
     else:
       #facet_type = 'field'
       facet_type = 'terms' # if 5.2+

+ 28 - 10
desktop/libs/libsolr/src/libsolr/api.py

@@ -166,17 +166,35 @@ class SolrApi(object):
               'key': '%(field)s-%(id)s' % facet
           }
           props.update(facet)
-          print facet
-          _f = {
-              'type': 'terms',
-              'field': facet['field'],
-              'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'facet-widget' else 0),
-              'mincount': int(facet['properties']['mincount'])
-          }
-          if facet['properties']['facets']: # [{u'field': u'salary_d', u'functionz': u'avg', u'limit': 10, u'mincount': 1}
-            _f['facet'] = {
-                'd2': '%(functionz)s(%(field)s)' % facet['properties']['facets'][0] 
+          if 'start' in facet['properties']:
+            _f = {
+                'type': 'range',
+                'field': facet['field'],
+                'start': facet['properties']['start'],
+                'end': facet['properties']['end'],
+                'gap': facet['properties']['gap'],
+                'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'facet-widget' else 0),
+                'mincount': int(facet['properties']['mincount'])
+            }
+            if facet['properties']['facets']: # [{u'field': u'salary_d', u'functionz': u'avg', u'limit': 10, u'mincount': 1}
+              _f['facet'] = {
+                  'd2': {
+                      'type': 'terms',
+                      'field': '%(field)s' % facet['properties']['facets'][0]
+                  } 
+              }
+                        
+          else:
+            _f = {
+                'type': 'terms',
+                'field': facet['field'],
+                'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'facet-widget' else 0),
+                'mincount': int(facet['properties']['mincount'])
             }
+            if facet['properties']['facets']: # [{u'field': u'salary_d', u'functionz': u'avg', u'limit': 10, u'mincount': 1}
+              _f['facet'] = {
+                  'd2': '%(functionz)s(%(field)s)' % facet['properties']['facets'][0] 
+              }
             
           json_facets['%(key)s' % props] = _f
         elif facet['type'] == 'function':