Browse Source

HUE-2173 [search] Support nested text facet with &up

Romain Rigaux 9 years ago
parent
commit
f7bb58a

+ 3 - 3
apps/search/src/search/models.py

@@ -681,7 +681,7 @@ def range_pair(field, cat, fq_filter, iterable, end, collection_facet):
   is_single_unit_gap = re.match('^[\+\-]?1[A-Za-z]*$', str(collection_facet['properties']['gap'])) is not None
   is_up = collection_facet['properties']['sort'] == 'asc'
 
-  if collection_facet['properties']['sort'] == 'asc' and collection_facet['type'] == 'range-up':
+  if collection_facet['properties']['sort'] == 'asc' and (collection_facet['type'] == 'range-up' or collection_facet['properties'].get('type') == 'range-up'):
     prev = None
     n = []
     for e in iterable:
@@ -713,7 +713,7 @@ def range_pair(field, cat, fq_filter, iterable, end, collection_facet):
     })
     total_counts += counts.pop(0) if counts else 0
 
-  if collection_facet['properties']['sort'] == 'asc' and collection_facet['type'] != 'range-up':
+  if collection_facet['properties']['sort'] == 'asc' and collection_facet['type'] != 'range-up' and collection_facet['properties'].get('type') != 'range-up':
     pairs.reverse()
 
   return pairs
@@ -813,7 +813,7 @@ def augment_solr_response(response, collection, query):
         counts = response['facets'][name]['buckets']
 
         # Number or Date range
-        if collection_facet['properties']['canRange']:
+        if collection_facet['properties']['canRange'] and not facet['properties'].get('type') == 'field':
           dimension = 3
           # Single dimension or dimension 2 with analytics
           if not collection_facet['properties']['facets'] or collection_facet['properties']['facets'][0]['aggregate'] not in ('count', 'unique'):

+ 29 - 1
apps/search/src/search/static/search/js/search.ko.js

@@ -1112,7 +1112,21 @@ var Collection = function (vm, collection) {
     vm.search();
   };
 
-  self.toggleRangeFacet = function (facet_field, event) {
+  self.toggleSortFacet2 = function (facet_field, event) {
+    if (facet_field.properties.sort() == 'desc') {
+      facet_field.properties.sort('asc');
+    } else {
+      facet_field.properties.sort('desc');
+    }
+
+    if (facet_field.properties.type() == 'range-up') {
+      vm.query.removeFilter(ko.mapping.fromJS({'id': facet_field.id})); // Reset filter query
+    }
+
+    vm.search();
+  };
+
+  self.toggleRangeFacet = function (facet_field, event) { // Deprecated after Hue 4
     vm.query.removeFilter(ko.mapping.fromJS({'id': facet_field.id})); // Reset filter query
 
     if (facet_field.type() == 'field') {
@@ -1126,6 +1140,20 @@ var Collection = function (vm, collection) {
     vm.search();
   };
 
+  self.toggleRangeFacet2 = function (facet_field, event) {
+    vm.query.removeFilter(ko.mapping.fromJS({'id': facet_field.id})); // Reset filter query
+
+    if (facet_field.properties.type() == 'field') {
+       facet_field.properties.type('range');
+     } else if (facet_field.properties.type() == 'range') {
+       facet_field.properties.type('range-up')
+     } else if (facet_field.properties.type() == 'range-up') {
+       facet_field.properties.type('field')
+     }
+
+    vm.search();
+  };
+
   self.selectTimelineFacet = function (data) {
     var facet = self.getFacetById(data.widget_id);
 

+ 5 - 5
apps/search/src/search/templates/common_search.mako

@@ -508,18 +508,18 @@ ${ dashboard.layout_skeleton() }
     <!-- ko if: properties.canRange() && typeof properties.type != "undefined" -->
     <div class="facet-field-cnt">
       <span class="facet-field-label facet-field-label-fixed-width">${ _('Type') }</span>
-      <a href="javascript: void(0)" title="${ _('Toggle how to group the values') }" data-bind="click: $root.collection.toggleRangeFacet">
+      <a href="javascript: void(0)" title="${ _('Toggle how to group the values') }" data-bind="click: $root.collection.toggleRangeFacet2">
         <i class="fa" data-bind="css: { 'fa-arrows-h': properties.type() == 'range', 'fa-circle': properties.type() == 'field', 'fa-level-up': properties.type() == 'range-up' }, attr: { title: properties.type() == 'field' ? 'Range' : properties.type() == 'range-up' ? 'Range and up' : 'Term' }"></i>
-        <span data-bind="visible: type() == 'range'">${_('range')}</span>
-        <span data-bind="visible: type() == 'range-up'">${_('range & up')}</span>
-        <span data-bind="visible: type() == 'field'">${_('field')}</span>
+        <span data-bind="visible: properties.type() == 'range'">${_('range')}</span>
+        <span data-bind="visible: properties.type() == 'range-up'">${_('range & up')}</span>
+        <span data-bind="visible: properties.type() == 'field'">${_('field')}</span>
       </a>
     </div>
     <!-- /ko -->
 
     <div class="facet-field-cnt">
       <span class="facet-field-label facet-field-label-fixed-width">${ _('Sorting') }</span>
-      <a href="javascript: void(0)" title="${ _('Toggle sort order') }" data-bind="click: $root.collection.toggleSortFacet">
+      <a href="javascript: void(0)" title="${ _('Toggle sort order') }" data-bind="click: $root.collection.toggleSortFacet2">
         <i class="fa" data-bind="css: { 'fa-caret-down': properties.sort() == 'desc', 'fa-caret-up': properties.sort() == 'asc' }"></i>
         <span data-bind="visible: properties.sort() == 'desc'">${_('descending')}</span>
         <span data-bind="visible: properties.sort() == 'asc'">${_('ascending')}</span>

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

@@ -340,7 +340,7 @@ class SolrApi(object):
               'sort': {'count': facet['properties']['sort']}
           }
 
-          if 'start' in facet['properties']:
+          if 'start' in facet['properties'] and not facet['properties'].get('type') == 'field':
             _f.update({
                 'type': 'range',
                 'start': facet['properties']['start'],
@@ -355,6 +355,8 @@ class SolrApi(object):
                 'field': facet['field'],
                 'excludeTags': facet['id']
             })
+            if facet['properties']['canRange'] and not facet['properties']['isDate']:
+              del _f['mincount'] # Numeric fields do not support
 
           if facet['properties']['facets']:
             if facet['properties']['facets'][0]['aggregate'] == 'count':
@@ -375,7 +377,7 @@ class SolrApi(object):
                   'd2': self._get_aggregate_function(facet['properties']['facets'][0])
               }
               _f['sort'] = {'d2': facet['properties']['sort']}
-              # filter = '-d2:NaN' # Solr 6.4
+              # domain = '-d2:NaN' # Solr 6.4
 
           json_facets[facet['id']] = _f
         elif facet['type'] == 'function':