Explorar o código

HUE-7756 [dashboard] Add other as facet option

jdesjean %!s(int64=8) %!d(string=hai) anos
pai
achega
3da14665f2

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

@@ -370,6 +370,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     'stacked': False,
     'limit': 10,
     'mincount': 1,
+    'missing': False,
     'isDate': False,
     'aggregate': {'function': 'unique', 'formula': '', 'plain_formula': '', 'percentile': 50}
   }

+ 5 - 0
desktop/libs/dashboard/src/dashboard/models.py

@@ -135,6 +135,8 @@ class Collection2(object):
         properties['initial_end'] = properties['end']
       if 'domain' not in properties:
         properties['domain'] = {'blockParent': [], 'blockChildren': []}
+      if 'missing' not in properties:
+        properties['missing'] = False
 
       if facet['widgetType'] == 'histogram-widget':
         if 'timelineChartType' not in properties:
@@ -536,6 +538,9 @@ def augment_solr_response(response, collection, query):
 
         facet_one = collection_facet['properties']['facets'][0]
 
+        if 'missing' in value:
+          counts.append({'val': '', 'count': value['missing']['count']})
+
         # Number or Date range
         if facet_one['canRange'] and not facet_one['type'] == 'field':
           dimension = 3 if facet_one['isDate'] else 1

+ 10 - 0
desktop/libs/dashboard/src/dashboard/templates/common_search.mako

@@ -2141,6 +2141,16 @@ ${ dashboard.layout_skeleton(suffix='search') }
             <input type="text" class="input-medium" data-bind="spinedit: $parent.mincount"/>
           </span>
         </div>
+        <!-- ko if: $parentContext.$data.type() == 'field' && $parents[1].widgetType() != 'timeline-widget' && $parents[1].widgetType() != 'gradient-map-widget' && $parents[1].widgetType() != 'leafletmap-widget' && $parents[1].widgetType() != 'tree2-widget' -->
+          <div class="facet-field-cnt" data-bind="visible: $parent == $parentContext.$parentContext.$data.properties.facets()[0] && $root.collection.engine() == 'solr'"> <!-- visible on first element only -->
+            <span class="spinedit-cnt">
+              <span class="facet-field-label facet-field-label-fixed-width">
+                ${ _('Other') }
+              </span>
+              <input type="checkbox" data-bind="checked: $parent.missing"/>
+            </span>
+          </div>
+        <!-- /ko -->
       <!-- /ko -->
       <!-- /ko -->
 

+ 13 - 7
desktop/libs/libsolr/src/libsolr/api.py

@@ -281,7 +281,8 @@ class SolrApi(object):
           'mincount': int(facet['mincount']),
           'numBuckets': True,
           'allBuckets': True,
-          'sort': sort
+          'sort': sort,
+          'missing': facet.get('missing', False)
           #'prefix': '' # Forbidden on numeric fields
       }
 
@@ -956,12 +957,17 @@ class SolrApi(object):
             values = _filter['value'] if type(_filter['value']) == list else [_filter['value']] # 2D facets support
             if fields.index(field) < len(values): # Lowest common field denominator
               value = values[fields.index(field)]
-              exclude = '-' if _filter['exclude'] else ''
-              if value is not None and ' ' in force_unicode(value):
-                value = force_unicode(value).replace('"', '\\"')
-                f.append('%s%s:"%s"' % (exclude, field, value))
-              else:
-                f.append('%s{!field f=%s}%s' % (exclude, field, value))
+              if value:
+                exclude = '-' if _filter['exclude'] else ''
+                if value is not None and ' ' in force_unicode(value):
+                  value = force_unicode(value).replace('"', '\\"')
+                  f.append('%s%s:"%s"' % (exclude, field, value))
+                else:
+                  f.append('%s{!field f=%s}%s' % (exclude, field, value))
+              else: # Handle empty value selection that are returned using solr facet.missing
+                value = "*"
+                exclude = '-'
+                f.append('%s%s:%s' % (exclude, field, value))
           _params ='{!tag=%(id)s}' % fq + ' '.join(f)
           params += (('fq', urllib.unquote(utf_quoter(_params))),)
       elif fq['type'] == 'range':