Эх сурвалжийг харах

HUE-3294 [search] Add nested metric format instead of single function

Romain Rigaux 9 жил өмнө
parent
commit
454dcd8

+ 2 - 2
apps/search/src/search/static/search/js/search.ko.js

@@ -619,7 +619,7 @@ var Collection = function (vm, collection) {
       });
     }
     if (facet.properties.aggregate) {
-      facet.properties.aggregate.subscribe(function () {
+      facet.properties.aggregate.function.subscribe(function () {
         vm.search();
       });
     }
@@ -770,7 +770,7 @@ var Collection = function (vm, collection) {
             });
           }
           if (facet.properties.aggregate) {
-            facet.properties.aggregate.subscribe(function () {
+            facet.properties.aggregate.function.subscribe(function () {
               vm.search();
             });
           }

+ 22 - 8
apps/search/src/search/templates/common_search.mako

@@ -227,7 +227,7 @@ from django.utils.translation import ugettext as _
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Pie Chart')}" rel="tooltip" data-placement="top">
          <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
-                       <i class="hcha hcha-pie-chart"></i>
+                       <i class="fa fa-pie-chart"></i>
          </a>
     </div>
     <div data-bind="visible: ! $root.isLatest(),
@@ -247,7 +247,7 @@ from django.utils.translation import ugettext as _
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Chart')}" rel="tooltip" data-placement="top">
          <a data-bind="style: { cursor: $root.availableDraggableChart() ? 'move' : 'default' }">
-                       <i class="hcha hcha-bar-chart"></i>
+                       <i class="fa fa-bar-chart"></i>
          </a>
     </div>
     <div data-bind="visible: ! $root.isLatest(),
@@ -303,7 +303,7 @@ from django.utils.translation import ugettext as _
                               'stop': function(event, ui){$('.card-body').slideDown('fast', function(){$(window).scrollTop(lastWindowScrollPosition)});}}}"
          title="${_('Timeline')}" rel="tooltip" data-placement="top">
          <a data-bind="style: { cursor: $root.availableTimeline() ? 'move' : 'default' }">
-                       <i class="hcha hcha-timeline-chart"></i>
+                       <i class="fa fa-line-chart"></i>
          </a>
     </div>
     <div data-bind="visible: ! $root.isLatest(), css: { 'draggable-widget': true, 'disabled': ! availableDraggableMap() },
@@ -1974,11 +1974,8 @@ ${ dashboard.layout_skeleton() }
   <!-- 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())">
-      <div data-bind="visible: $root.isEditing" style="margin-bottom: 20px">
-        <span class="facet-field-label">${ _('Metric') }</span>
-        <select data-bind="options: HIT_OPTIONS, optionsText: 'label', optionsValue: 'value', value: properties.aggregate"></select>
-      </div>
-      <div data-bind="visible: ! $root.isEditing(), text: getHitOption(properties.aggregate())" class="muted"></div>
+      <span data-bind="template: { name: 'metric-form', data: properties.aggregate }"></span>
+      <span data-bind="template: { name: 'facet-toggle2' }"></span>
     </div>
     <span class="big-counter" data-bind="textSqueezer: counts"></span>
   </div>
@@ -1986,6 +1983,22 @@ ${ dashboard.layout_skeleton() }
 </script>
 
 
+<script type="text/html" id="metric-form">
+  <div data-bind="visible: $root.isEditing" style="margin-bottom: 20px">
+    <span class="facet-field-label">${ _('Metric') }</span>
+    <select data-bind="options: HIT_OPTIONS, optionsText: 'label', optionsValue: 'value', value: $data.function" class="input-medium"></select>
+    <br/>
+    <a href="javascript: void(0)" data-bind="click: function() { $data.ops.push(ko.mapping.fromJS({'function': 'unique', 'ops': []})); }">
+      <i class="fa fa-plus" title="${ _('Add formula operation') }"></i>
+    </a>
+    <!-- ko foreach: ops() -->
+      <span data-bind="template: { name: 'metric-form' }"></span>
+    <!-- /ko -->
+  </div>
+  <div data-bind="visible: ! $root.isEditing(), text: getHitOption($data.function)" class="muted"></div>
+</script>
+
+
 <script type="text/html" id="filter-widget">
   <div data-bind="visible: $root.query.fqs().length == 0" style="margin-top: 10px; min-height: 87px">
     ${ _('There are currently no filters applied.') }
@@ -2666,6 +2679,7 @@ var HIT_OPTIONS = [
   { value: "max", label: "${ _('Max') }" },
   { value: "median", label: "${ _('Median') }" },
   { value: "percentile", label: "${ _('Percentiles') }" },
+  { value: "mul", label: "${ _('Multiply') }" },
 ];
 
 function getHitOption(value){

+ 13 - 6
apps/search/src/search/views.py

@@ -565,13 +565,17 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     'limit': 10,
     'mincount': 0,
     'isDate': False,
-    'aggregate': 'unique'
+    'aggregate': {'function': 'unique', 'ops': []}
   }
 
+  # avg(stars)                      # {'function': 'avg', 'ops': []}
+  # avg(mul(stars,1))               # {'function': 'avg', 'ops': [{'function': 'mul', 'ops': ['stars', 1]}]}
+  # avg(mul(stars,1,max(f2)))       # {'function': 'avg', 'ops': [{'function': 'mul', 'ops': ['stars', 1, {'function': 'max', 'ops': ['f2']}]}]}
+  # avg(percentile(stars,50,100))   # {'function': 'avg', 'ops': [{'function': 'percentile', 'ops': ['stars', 50, 100]}]}
+  # percentile(mul(stars,2),50)     # {'function': 'percentile', 'ops': [{'function': 'mul', 'ops': ['stars', 2]}, extra: [50]]}
+
   if widget_type in ('tree-widget', 'heatmap-widget', 'map-widget'):
     facet_type = 'pivot'
-  elif widget_type == 'hit-widget':
-    facet_type = 'function'
   elif widget_type == 'gradient-map-widget':
     facet_type = 'nested'
     properties['facets'] = []
@@ -591,11 +595,14 @@ def _create_facet(collection, user, facet_id, facet_label, facet_field, widget_t
     else:
       facet_type = 'field'
 
-    if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget', 'tree2-widget', 'text-facet-widget'):
+    if widget_type in ('bucket-widget', 'pie2-widget', 'timeline-widget', 'tree2-widget', 'text-facet-widget', 'hit-widget'):
       if widget_type == 'text-facet-widget':
         properties['type'] = facet_type
-      facet_type = 'nested'
-      properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': 'count'}
+      if widget_type == 'hit-widget':
+        facet_type = 'function'
+      else:        
+        facet_type = 'nested'
+      properties['facets_form'] = {'field': '', 'mincount': 1, 'limit': 10, 'aggregate': {'function': 'unique', 'ops': []}}
       properties['facets'] = []
       properties['domain'] = {'blockParent': [], 'blockChildren': []}
       if widget_type == 'pie2-widget':

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

@@ -607,13 +607,25 @@ class SolrApi(object):
   def _get_aggregate_function(self, facet):
     props = {
         'field': facet['field'],
-        'aggregate': facet['properties']['aggregate'] if 'properties' in facet else facet['aggregate']
+        'aggregate': facet['properties']['aggregate']['function'] #if 'properties' in facet else facet['aggregate']
     }
 
-    if props['aggregate'] == 'percentile':
-      return 'percentile(%(field)s,50)' % props
+    if  facet['properties']['aggregate']['ops']:
+      a = self.__get_aggregate_function()
+      return ''
     else:
-      return '%(aggregate)s(%(field)s)' % props
+      return '%(aggregate)s(%(field)s)' % props 
+#     if props['aggregate'] == 'percentile':
+#       return 'percentile(%(field)s,50)' % props
+#     else:
+#       return '%(aggregate)s(%(field)s)' % props
+  
+  def __get_aggregate_function(self):
+    pass
+    
+  # 'aggregate': {'function': 'count', 'ops': []}
+  # avg(stars)                      # {'function': 'avg', 'ops': []}
+  # avg(mul(stars,1))               # {'function': 'avg', 'ops': [{'function': 'mul', 'ops': ['stars', 1]}]}
 
   def _get_range_borders(self, collection, query):
     props = {}