ソースを参照

HUE-2173 [dashboard] First pass of backend to support recursive facets

Romain Rigaux 8 年 前
コミット
cce050c

+ 1 - 0
desktop/libs/dashboard/src/dashboard/api.py

@@ -410,6 +410,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       properties['facets_form'] = NESTED_FACET_FORM
       facet = NESTED_FACET_FORM.copy()
       facet['field'] = facet_field
+      facet['limit'] = 10
       facet['aggregate']['function'] = 'count'
       properties['facets'] = [facet]
       properties['domain'] = {'blockParent': [], 'blockChildren': []}

+ 10 - 6
desktop/libs/dashboard/src/dashboard/models.py

@@ -457,9 +457,9 @@ def augment_solr_response(response, collection, query):
         if collection_facet['properties']['canRange'] and not facet['properties'].get('type') == 'field':
           dimension = 3 if collection_facet['properties']['isDate'] else 1
           # Single dimension or dimension 2 with analytics
-          if not collection_facet['properties']['facets'] or collection_facet['properties']['facets'][0]['aggregate']['function'] != 'count' and len(collection_facet['properties']['facets']) == 1:
+          if len(collection_facet['properties']['facets']) == 1 or len(collection_facet['properties']['facets']) == 2 and collection_facet['properties']['facets'][1]['aggregate']['function'] != 'count':
             column = 'count'
-            if len(collection_facet['properties']['facets']) == 1:
+            if len(collection_facet['properties']['facets']) == 2:
               agg_keys = [key for key, value in counts[0].items() if key.lower().startswith('agg_')]
               legend = agg_keys[0].split(':', 2)[1]
               column = agg_keys[0]
@@ -508,13 +508,13 @@ def augment_solr_response(response, collection, query):
 
           #_convert_nested_to_augmented_pivot_nd(facet_fields, facet['id'], count, selected_values, dimension=2)
           dimension = len(facet_fields)
-        elif not collection_facet['properties']['facets'] or (collection_facet['properties']['facets'][0]['aggregate']['function'] != 'count' and len(collection_facet['properties']['facets']) == 1):
+        elif len(collection_facet['properties']['facets']) == 1 or (len(collection_facet['properties']['facets']) == 2 and collection_facet['properties']['facets'][1]['aggregate']['function'] != 'count'):
           # Dimension 1 with 1 count or agg
           dimension = 1
 
           column = 'count'
           agg_keys = counts and [key for key, value in counts[0].items() if key.lower().startswith('agg_')]
-          if len(collection_facet['properties']['facets']) == 1 and agg_keys:
+          if len(collection_facet['properties']['facets']) == 2 and agg_keys:
             column = agg_keys[0]
           else:
             agg_keys = [column]
@@ -530,12 +530,16 @@ def augment_solr_response(response, collection, query):
           agg_keys = counts and [key for key, value in counts[0].items() if key.lower().startswith('agg_') or key.lower().startswith('dim_')]
           agg_keys.sort(key=lambda a: a[4:])
 
-          if len(agg_keys) == 1 and agg_keys[0].lower().startswith('dim_'):
+          if len(agg_keys) == 1 and agg_keys[0].lower().startswith('dim_'): #PB
             agg_keys.insert(0, 'count')
           counts = _augment_stats_2d(name, facet, counts, selected_values, agg_keys, rows)
-          actual_dimension = 1 + sum([_f['aggregate']['function'] == 'count' for _f in collection_facet['properties']['facets']])
+          actual_dimension = sum([_f['aggregate']['function'] == 'count' for _f in collection_facet['properties']['facets']])
+          print actual_dimension
+          print counts
+          print collection_facet['properties']['facets']
 
           counts = filter(lambda a: len(a['fq_fields']) == actual_dimension, counts)
+          print counts
 
         num_bucket = response['facets'][name]['numBuckets'] if 'numBuckets' in response['facets'][name] else len(response['facets'][name])
         facet = {

+ 1 - 1
desktop/libs/dashboard/src/dashboard/static/dashboard/js/search.ko.js

@@ -1010,7 +1010,7 @@ var Collection = function (vm, collection) {
     facet.properties.facets_form.mincount(1);
     facet.properties.facets_form.sort('desc');
 
-    facet.properties.facets_form.aggregate.function('count');
+    //facet.properties.facets_form.aggregate.function('count');
     facet.properties.facets_form.aggregate.formula('');
     facet.properties.facets_form.aggregate.percentiles.removeAll();
     facet.properties.facets_form.aggregate.percentiles.push({'value': 50});

+ 21 - 4
desktop/libs/libsolr/src/libsolr/api.py

@@ -194,9 +194,26 @@ class SolrApi(object):
               _fname = _f['facet'].keys()[0]
               _f['sort'] = {_fname: facet['properties']['sort']}
               # domain = '-d2:NaN' # Solr 6.4
-          # _f = _f['facet']
-          print _f
-          json_facets[facet['id']] = _f['facet']['dim_01:country_code3']
+
+          if _f:
+            sort = {'count': facet['properties']['facets'][0]['sort']}
+            for i, agg in enumerate(self._get_dimension_aggregates(facet['properties']['facets'][1:])):
+              if agg['sort'] != 'default':
+                agg_function = self._get_aggregate_function(agg)
+                sort = {'agg_%02d_%02d:%s' % (1, i, agg_function): agg['sort']}
+   
+            if sort.get('count') == 'default':
+              sort['count'] = 'desc'            
+            dim_key = [key for key in _f['facet'].keys() if 'dim' in key][0]
+            _f['facet'][dim_key].update({
+                  'excludeTags': facet['id'],
+                  'offset': 0,
+                  'numBuckets': True,
+                  'allBuckets': True,
+                  'sort': sort
+                  #'prefix': '' # Forbidden on numeric fields
+              })
+            json_facets[facet['id']] = _f['facet'][dim_key]
         elif facet['type'] == 'function':
           json_facets[facet['id']] = self._get_aggregate_function(facet)
           json_facets['processEmpty'] = True
@@ -942,7 +959,7 @@ class SolrApi(object):
 
   def _get_dimension_aggregates(self, facets):
     aggregates = []
-    for agg in facets[0:]:
+    for agg in facets:
       if agg['aggregate']['function'] != 'count':
         aggregates.append(agg)
       else: