浏览代码

HUE-5077 [metadata] Provide more facets

Romain Rigaux 9 年之前
父节点
当前提交
cf0b845

+ 1 - 9
desktop/core/src/desktop/static/desktop/js/apiHelper.js

@@ -1194,20 +1194,12 @@ var ApiHelper = (function () {
     }));
   };
 
-  var AVAILABLE_NAV_FACETS = {
-    hive: '["lastModified","originalDescription","owner","tags","type"]',
-    impala: '["lastModified","originalDescription","owner","tags","type"]',
-    hdfs: '["clusterName","lastModified","group","owner","tags","type"]',
-    default: '["tags","type"]'
-  };
-
   ApiHelper.prototype.navSearchAutocomplete = function (options) {
     var self = this;
     $.post('/metadata/api/navigator/search_entities_interactive', {
       query_s: options.query,
       limit: 5,
-      sources: '["' + options.source + '"]',
-      field_facets: AVAILABLE_NAV_FACETS[options.source] || AVAILABLE_NAV_FACETS.default
+      sources: '["' + options.source + '"]'
     }).done(function (data) {
       if (data.status === 0 && !self.successResponseIsError(data)) {
         options.successCallback(data);

+ 4 - 14
desktop/core/src/desktop/templates/assist.mako

@@ -1350,17 +1350,7 @@ from metadata.conf import has_navigator
         });
       }
 
-      var NAV_FACET_ICONS = {
-        'tags': 'fa-tags',
-        'tag': 'fa-tag',
-        'lastModified': 'fa-clock-o',
-        'originalDescription': 'fa-comment-o',
-        'owner': 'fa-user',
-        'type': 'fa-info',
-        'clusterName': 'fa-server',
-        'group': 'fa-users'
-      };
-
+      var NAV_FACET_ICON = 'fa-tags';
       var NAV_TYPE_ICONS = {
         'DATABASE': 'fa-database',
         'TABLE': 'fa-table',
@@ -1595,7 +1585,7 @@ from metadata.conf import has_navigator
                 if (typeof data.facets[facetInQuery] !== 'undefined') {
                   Object.keys(data.facets[facetInQuery]).forEach(function (facetValue) {
                     if (partial === '' || facetValue.indexOf(partial) !== -1) {
-                      values.push({ data: { label: facetInQuery + ':' + facetValue, icon: NAV_FACET_ICONS[facetInQuery.toLowerCase()], description: '' }, value: beforePartial + facetValue})
+                      values.push({ data: { label: facetInQuery + ':' + facetValue, icon: NAV_FACET_ICON, description: '' }, value: beforePartial + facetValue})
                     }
                   });
                 }
@@ -1604,12 +1594,12 @@ from metadata.conf import has_navigator
                   Object.keys(data.facets).forEach(function (facet) {
                     if (partial.length === 0 || facet.indexOf(partial) !== -1) {
                       if (Object.keys(data.facets[facet]).length > 0) {
-                        values.push({ data: { label: facet + ':', icon: NAV_FACET_ICONS[facet], description: Object.keys(data.facets[facet]).join(', ') }, value: beforePartial + facet + ':'});
+                        values.push({ data: { label: facet + ':', icon: NAV_FACET_ICON, description: Object.keys(data.facets[facet]).join(', ') }, value: beforePartial + facet + ':'});
                       }
                     } else if (partial.length > 0) {
                       Object.keys(data.facets[facet]).forEach(function (facetValue) {
                         if (facetValue.indexOf(partial) !== -1) {
-                          values.push({ data: { label: facet + ':' + facetValue, icon: NAV_FACET_ICONS[facet], description: facetValue }, value: beforePartial + facet + ':' + facetValue });
+                          values.push({ data: { label: facet + ':' + facetValue, icon: NAV_FACET_ICON, description: facetValue }, value: beforePartial + facet + ':' + facetValue });
                         }
                       });
                     }

+ 93 - 3
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -102,6 +102,94 @@ def search_entities_interactive(request):
   field_facets = json.loads(request.POST.get('field_facets') or '[]')
   sources = json.loads(request.POST.get('sources') or '[]')
 
+
+  f = {
+      "outputFormat" : {
+        "type" : "dynamic"
+      },
+      "name" : {
+        "type" : "dynamic"
+      },
+      "lastModified" : {
+        "type" : "date"
+      },
+      "sourceType" : {
+        "type" : "dynamic"
+      },
+      "parentPath" : {
+        "type" : "dynamic"
+      },
+      "deleteTime" : {
+        "type" : "date"
+      },
+      "lastAccessed" : {
+        "type" : "date"
+      },
+      "type" : {
+        "type" : "dynamic"
+      },
+      "sourceId" : {
+        "type" : "dynamic"
+      },
+      "partitionColNames" : {
+        "type" : "dynamic"
+      },
+      "serDeName" : {
+        "type" : "dynamic"
+      },
+      "created" : {
+        "type" : "date"
+      },
+      "fileSystemPath" : {
+        "type" : "dynamic"
+      },
+      "compressed" : {
+        "type" : "bool"
+      },
+      "clusteredByColNames" : {
+        "type" : "dynamic"
+      },
+      "deleted" : {
+        "type" : "bool"
+      },
+      "originalName" : {
+        "type" : "dynamic"
+      },
+      "owner" : {
+        "type" : "dynamic"
+      },
+      "extractorRunId" : {
+        "type" : "dynamic"
+      },
+      "userEntity" : {
+        "type" : "bool"
+      },
+      "sortByColNames" : {
+        "type" : "dynamic"
+      },
+      "inputFormat" : {
+        "type" : "dynamic"
+      },
+      "serDeLibName" : {
+        "type" : "dynamic"
+      },
+      "originalDescription" : {
+        "type" : "dynamic"
+      },
+      "lastModifiedBy" : {
+        "type" : "dynamic"
+      }
+    }
+
+  field_facets = ["tags", "type"] + f.keys()
+
+  last_query_term = [term for term in query_s.strip().split()][-1]
+
+  if last_query_term and last_query_term != '*':
+    last_query_term = last_query_term.rstrip('*')
+    field_facets = [f for f in field_facets if f.startswith(last_query_term)]
+  field_facets = field_facets[:10]
+
   response = api.search_entities_interactive(
       query_s=query_s,
       limit=limit,
@@ -113,9 +201,11 @@ def search_entities_interactive(request):
       sources=sources
   )
 
-  if response.get('facets'):
-    for facet in response['facets']:
-      response['facets'][facet] = dict((k, v) for k, v in response['facets'][facet].items() if v > 0)
+  if response.get('facets'): # Remove empty facets
+    for fname, fvalues in response['facets'].items():
+      response['facets'][fname] = dict((k, v) for k, v in fvalues.items() if v > 0)
+      if not response['facets'][fname]:
+        del response['facets'][fname]
 
   response['status'] = 0