瀏覽代碼

HUE-7362 [assist] Extend the global search parser to also include the facet values in the parse results

Johan Ahlen 8 年之前
父節點
當前提交
d4acb30

文件差異過大導致無法顯示
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/globalSearchParser.js


+ 12 - 6
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/globalSearchParser.jison

@@ -64,7 +64,7 @@ GlobalSearchAutocomplete
  | SearchParts_EDIT 'EOF'
    {
      if (!$1.facets) {
-       $1.facets = [];
+       $1.facets = {};
      }
      return $1;
    }
@@ -75,11 +75,11 @@ GlobalSearchAutocomplete
  ;
 
 SearchParts
- : SearchPart                   -->  { facets: $1.facet ? [ $1.facet ] : [] }
+ : SearchPart                   -->  { facets: $1.facets ? $1.facets : {} }
  | SearchParts SearchPart
    {
-     if ($2.facet) {
-       $1.facets.push($2.facet);
+     if ($2.facets) {
+       parser.mergeFacets($1.facets, $2.facets);
      }
    }
  ;
@@ -97,7 +97,8 @@ SearchParts_EDIT
    }
  | SearchParts SearchPart_EDIT SearchParts
    {
-     $2.facets = $1.facets.concat($3.facets);
+     $2.facets = $1.facets;
+     parser.mergeFacets($2.facets, $3.facets);
      $$ = $2;
    }
  ;
@@ -113,7 +114,12 @@ SearchPart_EDIT
  ;
 
 Facet
- : 'FACET' FreeText     --> { facet: $1.substring(0, $1.length - 1) }
+ : 'FACET' FreeText
+   {
+     var facet = {};
+     facet[$1.substring(0, $1.length - 1)] = [ $2 ];
+     $$ = { facets: facet };
+   }
  ;
 
 Facet_EDIT

+ 12 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -1903,6 +1903,18 @@ var SqlParseSupport = (function () {
       return {left: beforeMatch ? beforeMatch[0].length : 0, right: afterMatch ? afterMatch[0].length : 0};
     };
 
+    parser.mergeFacets = function (a, b) {
+      if (a && b) {
+        Object.keys(b).forEach(function (key) {
+          if (a[key]) {
+            a[key] = a[key].concat(b[key]);
+          } else {
+            a[key] = b[key];
+          }
+        });
+      }
+    };
+
     parser.parseGlobalSearch = function (beforeCursor, afterCursor, debug) {
       delete parser.yy.cursorFound;
 

+ 18 - 4
desktop/core/src/desktop/static/desktop/spec/autocomplete/globalSearchParserSpec.js

@@ -25,7 +25,7 @@
       testParser('', '', {
         suggestFacets: true,
         suggestResults: true,
-        facets: [ ]
+        facets: {}
       });
     });
 
@@ -33,21 +33,35 @@
       testParser('TAGS: asdf ', '', {
         suggestFacets: true,
         suggestResults: true,
-        facets: [ 'TAGS' ]
+        facets: {
+          'TAGS' : ['asdf']
+        }
       });
     });
 
     it('should suggest facet values for "type:table tags:"', function() {
       testParser('type:table tags: ', '', {
         suggestFacetValues: 'tags',
-        facets: ['type']
+        facets: {
+          'type': ['table']
+        }
+      });
+    });
+
+    it('should give correct facet values for "type:table type:column"', function() {
+      testParser('type:table type:column ', '', {
+        suggestFacets: true,
+        suggestResults: true,
+        facets: {
+          'type': ['table', 'column']
+        }
       });
     });
 
     it('should suggest facet values for "tags: |"', function () {
       testParser('tags: ', '', {
         suggestFacetValues: 'tags',
-        facets: []
+        facets: {}
       });
     });
   });

+ 1 - 1
desktop/core/src/desktop/templates/ko_components.mako

@@ -848,7 +848,7 @@ from desktop.views import _ko
         if (self.lastResult.suggestFacets) {
           var existingFacetIndex = {};
           if (self.lastResult.facets) {
-            self.lastResult.facets.forEach(function (facet) {
+            Object.keys(self.lastResult.facets).forEach(function (facet) {
               existingFacetIndex[facet.toLowerCase()] = true;
             })
           }

部分文件因文件數量過多而無法顯示