Przeglądaj źródła

HUE-2173 [dashboard] Hit widget compatibility with recursive facets

Romain Rigaux 8 lat temu
rodzic
commit
fcc9ca1

+ 8 - 6
desktop/libs/dashboard/src/dashboard/api.py

@@ -402,19 +402,21 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       if widget_type == 'text-facet-widget':
         properties['type'] = facet_type
 
-      if widget_type == 'hit-widget':
-        facet_type = 'function'
-      else:
-        facet_type = 'nested'
-
       properties['facets_form'] = NESTED_FACET_FORM
       facet = NESTED_FACET_FORM.copy()
       facet['field'] = facet_field
       facet['limit'] = 10
-      facet['aggregate']['function'] = 'count'
+      properties['canRange'] = False
       properties['facets'] = [facet]
       properties['domain'] = {'blockParent': [], 'blockChildren': []}
 
+      if widget_type == 'hit-widget':
+        facet_type = 'function'
+        facet['aggregate']['function'] = 'unique'
+      else:
+        facet_type = 'nested'
+        facet['aggregate']['function'] = 'count'
+
       if widget_type == 'pie2-widget':
         properties['scope'] = 'stack'
         properties['timelineChartType'] = 'bar'

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

@@ -34,7 +34,14 @@ from dashboard.dashboard_api import get_engine
 
 LOG = logging.getLogger(__name__)
 
-NESTED_FACET_FORM = {'field': '', 'mincount': 1, 'limit': 5, 'sort': 'desc', 'aggregate': {'function': 'unique', 'formula': '', 'plain_formula': '', 'percentiles': [{'value': 50}]}}
+
+NESTED_FACET_FORM = {
+    'field': '',
+    'mincount': 1,
+    'limit': 5,
+    'sort': 'desc',
+    'aggregate': {'function': 'unique', 'formula': '', 'plain_formula': '', 'percentiles': [{'value': 50}]}
+}
 
 
 class Collection2(object):
@@ -442,7 +449,7 @@ def augment_solr_response(response, collection, query):
         cols = ['%(field)s' % facet, 'count(%(field)s)' % facet]
         last_x_col = 0
         last_xx_col = 0
-        for i, f in enumerate(facet['properties']['facets']):
+        for i, f in enumerate(facet['properties']['facets'][1:]):
           if f['aggregate']['function'] == 'count':
             cols.append(f['field'])
             last_xx_col = last_x_col
@@ -534,12 +541,8 @@ def augment_solr_response(response, collection, query):
             agg_keys.insert(0, 'count')
           counts = _augment_stats_2d(name, facet, counts, selected_values, agg_keys, rows)
           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 = {

+ 3 - 2
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -2089,7 +2089,8 @@ ${ dashboard.layout_skeleton(suffix='search') }
   <!-- ko if: $root.getFacetFromQuery(id()).has_data() -->
   <div class="row-fluid" data-bind="with: $root.getFacetFromQuery(id())">
     <div data-bind="with: $root.collection.getFacetById($parent.id())">
-      <span data-bind="template: { name: 'metric-form' }"></span>
+      ##<span data-bind="template: { name: 'metric-form' }"></span>
+      <span data-bind="template: { name: 'facet-toggle2' }"></span>
       ## TODO: Range if numeric
     </div>
     <span class="big-counter" data-bind="textSqueezer: counts"></span>
@@ -2106,7 +2107,7 @@ ${ dashboard.layout_skeleton(suffix='search') }
     <div>
       ## For Counter widget
       <!-- ko if: $data.function() != 'field' && $parent.properties -->
-        <select data-bind="options: $parent.properties.facets_form.aggregate.metrics, optionsText: 'label', optionsValue: 'value', value: $data.function" class="input-small"></select>
+        <select data-bind="options: $parents[1].properties.facets_form.aggregate.metrics, optionsText: 'label', optionsValue: 'value', value: $data.function" class="input-small"></select>
       <!-- /ko -->
 
       <!-- ko if: $data.function() != 'field' -->

+ 3 - 2
desktop/libs/libsolr/src/libsolr/api.py

@@ -215,8 +215,9 @@ class SolrApi(object):
               })
             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
+          if facet['properties']['facets']:
+            json_facets[facet['id']] = self._get_aggregate_function(facet['properties']['facets'][0])
+            json_facets['processEmpty'] = True
         elif facet['type'] == 'pivot':
           if facet['properties']['facets'] or facet['widgetType'] == 'map-widget':
             fields = facet['field']