Explorar o código

HUE-2981 [search] Support nested document faceting

Romain Rigaux %!s(int64=9) %!d(string=hai) anos
pai
achega
b523bac

+ 11 - 8
apps/search/src/search/models.py

@@ -510,16 +510,17 @@ class Collection2(object):
       props['collection']['nested'] = {
         'enabled': False,
         'schema': [
-          {'filter': 'type_s:book', 'name': 'books', 'selected': False, 'values': [ # limit 10 # parentFilterSelected # childrenFilterSelected
+          {'filter': 'type_s:book', 'name': 'books', 'selected': False, 'values': [ # limit 10
             {'filter': 'type_s:review', 'name': 'reviews', 'selected': False, 'values': [
-              {'filter': 'type_s:review2', 'name': 'reviews2', 'selected': False, 'values': []},
-              {'filter': 'type_s:review3', 'name': 'reviews3', 'selected': False, 'values': []}]}]},
-          {'filter': 'type_s:map', 'name': 'maps', 'selected': False, 'values': [
-            {'filter': 'type_s:review', 'name': 'reviews', 'selected': False, 'values': []}]},
-          {'filter': 'type_s:notebook', 'name': 'notebooks', 'selected': False, 'values': [
-            {'filter': 'type_s:sheet', 'name': 'sheets', 'selected': False, 'values': []}]}
+#               {'filter': 'type_s:review2', 'name': 'reviews2', 'selected': False, 'values': []},
+#               {'filter': 'type_s:review3', 'name': 'reviews3', 'selected': False, 'values': []}]}]},
+#           {'filter': 'type_s:map', 'name': 'maps', 'selected': False, 'values': [
+#             {'filter': 'type_s:review', 'name': 'reviews', 'selected': False, 'values': []}]},
+#           {'filter': 'type_s:notebook', 'name': 'notebooks', 'selected': False, 'values': [
+#             {'filter': 'type_s:sheet', 'name': 'sheets', 'selected': False, 'values': []}]}
         ]
-      }
+             
+      }]}]}
 
     for facet in props['collection']['facets']:
       properties = facet['properties']
@@ -529,6 +530,8 @@ class Collection2(object):
         properties['initial_start'] = properties['start']
       if 'end' in properties and not 'initial_end' in properties:
         properties['initial_end'] = properties['end']
+      if 'domain' not in properties:
+        properties['domain'] = {'blockParent': [], 'blockChildren': []}
 
       if facet['widgetType'] == 'histogram-widget':
         if 'timelineChartType' not in properties:

+ 13 - 0
apps/search/src/search/static/search/js/search.ko.js

@@ -451,6 +451,19 @@ var Collection = function (vm, collection) {
   self.description = ko.observable(typeof collection.description != "undefined" && collection.description != null ? collection.description : "");
   self.suggest = ko.mapping.fromJS(collection.suggest);
   self.nested = ko.mapping.fromJS(collection.nested);
+  self.nestedNames = ko.computed(function() {
+	function flatten(values) {
+		var fields = [];
+		$.each(values, function (index, facet) {
+	      fields.push(facet.filter());
+		  if (facet.values().length > 0) {
+			fields.push.apply(fields, flatten(facet.values()));
+		  }
+		});
+		return fields;
+	  }
+	  return flatten(self.nested.schema());
+  });
   self.enabled = ko.mapping.fromJS(collection.enabled);
   self.autorefresh = ko.mapping.fromJS(collection.autorefresh);
   self.autorefreshSeconds = ko.mapping.fromJS(collection.autorefreshSeconds || 60);

+ 15 - 1
apps/search/src/search/templates/common_search.mako

@@ -548,6 +548,20 @@ ${ dashboard.layout_skeleton() }
       </span>
     </div>
 
+    <div class="facet-field-cnt">
+      <span class="spinedit-cnt">
+        <span class="facet-field-label">
+          ${ _('Domain') }
+        </span>
+        ${ _('Parent') }
+        <select data-bind="selectedOptions: properties.domain.blockParent, options: $root.collection.nestedNames" size="5" multiple="true"></select>
+        ${ _('Children') }
+        <select data-bind="selectedOptions: properties.domain.blockChildren, options: $root.collection.nestedNames" size="5" multiple="true"></select>
+
+        <input type="text" class="input-medium" data-bind="spinedit: properties.mincount"/>
+      </span>
+    </div>
+
   ## Dimensions > 1
   <!-- ko if: $root.isEditing -->  
   <span data-bind="foreach: properties.facets, visible: !$parents[1].isLoading()">
@@ -2350,7 +2364,7 @@ ${ dashboard.layout_skeleton() }
                 <label class="checkbox" style="padding-top:0">
                   <input type="checkbox" style="margin-right: 4px; margin-top: 9px" data-bind="checked: $root.collection.nested.enabled">
                   <span data-bind="visible: $root.collection.nested.enabled">
-                    ${ _('Levels') }
+                    ${ _('Schema') }
                     <span data-bind="template: {name: 'nested-document-schema-level', data: $root.collection.nested.schema()}"></span> 
                   </span>
                 </label>

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

@@ -572,6 +572,7 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
       facet_type = 'nested'
       properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': 'count'}
       properties['facets'] = []
+      properties['domain'] = {'blockParent': [], 'blockChildren': []}
       if widget_type == 'pie2-widget':
         properties['scope'] = 'stack'
         properties['timelineChartType'] = 'bar'

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

@@ -129,6 +129,7 @@ class SolrApi(object):
               'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'facet-widget' else 0),
               'mincount': int(facet['properties']['mincount'])
           }
+
           params += (
               ('facet.field', '{!key=%(key)s ex=%(id)s f.%(field)s.facet.limit=%(limit)s f.%(field)s.facet.mincount=%(mincount)s}%(field)s' % keys),
           )
@@ -137,9 +138,16 @@ class SolrApi(object):
               'field': facet['field'],
               'limit': int(facet['properties'].get('limit', 10)) + (1 if facet['widgetType'] == 'text-facet-widget' else 0),
               'mincount': int(facet['properties']['mincount']),
-              'sort': {'count': facet['properties']['sort']}, 
+              'sort': {'count': facet['properties']['sort']},
           }
 
+          if facet['properties']['domain'].get('blockParent') or facet['properties']['domain'].get('blockChildren'):
+            _f['domain'] = {}
+            if facet['properties']['domain'].get('blockParent'):
+              _f['domain']['blockParent'] = ' OR '.join(facet['properties']['domain']['blockParent'])
+            if facet['properties']['domain'].get('blockChildren'):
+              _f['domain']['blockChildren'] = ' OR '.join(facet['properties']['domain']['blockChildren'])
+
           if 'start' in facet['properties'] and not facet['properties'].get('type') == 'field':
             _f.update({
                 'type': 'range',