Просмотр исходного кода

Changed search result model to be more datasource agnostic

Torkel Ödegaard 11 лет назад
Родитель
Сommit
7be7b07c19

+ 1 - 1
src/app/controllers/search.js

@@ -61,7 +61,7 @@ function (angular, _, config, $) {
     $scope.searchDashboards = function(queryString) {
       return $scope.db.searchDashboards(queryString)
         .then(function(results) {
-          $scope.tagsOnly = results.dashboards.length === 0 && results.tags.length > 0;
+          $scope.tagsOnly = results.tagsOnly;
           $scope.results.dashboards = results.dashboards;
           $scope.results.tags = results.tags;
         });

+ 11 - 1
src/app/services/elasticsearch/es-datasource.js

@@ -211,7 +211,17 @@ function (angular, _, $, config, kbn, moment) {
             return { dashboards: [], tags: [] };
           }
 
-          return { dashboards: results.hits.hits, tags: results.facets.terms || [] };
+          var hits = { dashboards: [], tags: results.facets.tags.terms || [] };
+
+          for (var i = 0; i < results.hits.hits.length; i++) {
+            hits.dashboards.push({
+              id: results.hits.hits[i]._id,
+              tags: results.hits.hits[i]._source.tags
+            });
+          }
+
+          hits.tagsOnly = tagsOnly;
+          return hits;
         });
     };
 

+ 5 - 4
src/app/services/influxdb/influxdbDatasource.js

@@ -282,11 +282,12 @@ function (angular, _, kbn, InfluxSeries) {
       }
 
       return this._seriesQuery(influxQuery).then(function(results) {
+        var hits = { dashboards: [], tags: [], tagsOnly: false };
+
         if (!results || !results.length) {
-          return { dashboards: [], tags: [] };
+          return hits;
         }
 
-        var dashList = [];
         var dashCol = _.indexOf(results[0].columns, 'title');
         var tagsCol = _.indexOf(results[0].columns, 'tags');
 
@@ -296,9 +297,9 @@ function (angular, _, kbn, InfluxSeries) {
             tags: results[i].points[0][tagsCol].split(",")
           };
           hit.tags = hit.tags[0] ? hit.tags : [];
-          dashList.push(hit);
+          hits.dashboards.push(hit);
         }
-        return { dashboards: dashList, tags: [] };
+        return hits;
       });
     };