From 9c7cd28023a9700ad87c072e26129c508bd5997a Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Wed, 20 Feb 2013 09:10:03 -0700 Subject: [PATCH] added detection of empty fields --- common/lib/shared.js | 10 ++++++- panels/fields/module.js | 5 +--- panels/table/module.js | 4 +-- sharable.json | 59 ----------------------------------------- 4 files changed, 11 insertions(+), 67 deletions(-) delete mode 100644 sharable.json diff --git a/common/lib/shared.js b/common/lib/shared.js index f8bdc678109..16e0faefd09 100644 --- a/common/lib/shared.js +++ b/common/lib/shared.js @@ -134,7 +134,7 @@ function get_field_value(object,field,opt) { function get_all_values_for_field(docs,field) { var field_array = []; _.each(docs, function(doc,k) { - var value = doc[field] + var value = doc[field] || "" if(typeof value === 'object' && value != null) { field_array.push.apply(field_array,value); } else { @@ -149,6 +149,14 @@ function top_field_values(docs,field,count) { return _.pairs(counts).sort(function(a, b) {return a[1] - b[1]}).reverse().slice(0,count) } +function add_to_query(original,field,value) { + if(value !== '') + var query = field + ":" + "\"" + addslashes(value.toString()) + "\""; + else + var query = "_missing_:" + field; + var glue = original != "" ? " AND " : ""; + return original + glue + query; +} /** * Calculate a graph interval * diff --git a/panels/fields/module.js b/panels/fields/module.js index b5695bebecc..622baefa710 100644 --- a/panels/fields/module.js +++ b/panels/fields/module.js @@ -24,7 +24,6 @@ angular.module('kibana.fields', []) } $scope.toggle_micropanel = function(field) { - //console.log(top_field_values($scope.docs,field,10)) $scope.micropanel = { field: field, values : top_field_values($scope.docs,field,10) @@ -45,9 +44,7 @@ angular.module('kibana.fields', []) } $scope.build_search = function(field, value) { - var query = field + ":" + "\"" + addslashes(value.toString()) + "\""; - var glue = $scope.panel.query != "" ? " AND " : ""; - $scope.panel.query = $scope.panel.query + glue + query; + $scope.panel.query = add_to_query($scope.panel.query,field,value) eventBus.broadcast($scope.$id,$scope.panel.group,'query',$scope.panel.query); } diff --git a/panels/table/module.js b/panels/table/module.js index f6f4e9cd29e..e3df5c92094 100644 --- a/panels/table/module.js +++ b/panels/table/module.js @@ -68,9 +68,7 @@ angular.module('kibana.table', []) } $scope.build_search = function(field, value) { - var query = field + ":" + "\"" + addslashes(value.toString()) + "\""; - var glue = $scope.panel.query != "" ? " AND " : ""; - $scope.panel.query = $scope.panel.query + glue + query; + $scope.panel.query = add_to_query($scope.panel.query,field,value) $scope.panel.offset = 0; $scope.get_data(); eventBus.broadcast($scope.$id,$scope.panel.group,'query',$scope.panel.query); diff --git a/sharable.json b/sharable.json deleted file mode 100644 index d36872113ef..00000000000 --- a/sharable.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "title":"Monkey Showdown", - "rows":{ - "row2":{ - "height":"270px", - "panels":{ - "Hamlet vs macbeth":{ - "type":"stackedquery", - "span":8, - "queries":[ - "play_name:Hamlet", - "play_name:macbeth" - ], - "show": [ "lines", "fill" ] - }, - "Hamlet vs Macbeth":{ - "type":"piequery", - "span":4, - "donut":true, - "queries":[ - "play_name:Hamlet", - "play_name:macbeth" - ], - "colors":[ - "#B07737", - "#85004B", - "#7BA4AF" - ], - "field":"@message" - } - } - }, - "row3":{ - "height":"130px", - "panels":{ - "Hamlet's Lines":{ - "type":"histogram", - "span":8, - "show":[ - "bars" - ], - "label":"lines", - "query":"speaker:HAMLET", - "color":"#4A8737" - }, - "Speakers":{ - "type":"pieterms", - "donut":false, - "tilt":false, - "legend":true, - "field":"speaker", - "span":4, - "size":6, - "query":"play_name:Hamlet OR play_name:macbeth" - } - } - } - } -}