Browse Source

HUE-5646 [editor] Include table and column comments in the autocomplete filter

Johan Ahlen 8 years ago
parent
commit
18f996ae83

+ 19 - 9
desktop/core/src/desktop/static/desktop/js/sqlAutocompleter3.js

@@ -159,17 +159,27 @@ var SqlAutocompleter3 = (function () {
         result = result.filter(function (suggestion) {
           // TODO: Extend with fuzzy matches
           var foundIndex = suggestion.value.toLowerCase().indexOf(lowerCaseFilter);
-          if (foundIndex === -1) {
-            return false;
+          if (foundIndex !== -1) {
+            if (foundIndex === 0 || (suggestion.filterValue && suggestion.filterValue.toLowerCase().indexOf(lowerCaseFilter) === 0)) {
+              suggestion.filterWeight = 3;
+            } else  {
+              suggestion.filterWeight = 2;
+            }
+          } else {
+            if (suggestion.details && suggestion.details.comment) {
+              foundIndex = suggestion.details.comment.toLowerCase().indexOf(lowerCaseFilter);
+              if (foundIndex !== -1) {
+                suggestion.filterWeight = 1;
+                suggestion.matchComment = true;
+              }
+            }
           }
-          if (foundIndex === 0 || (suggestion.filterValue && suggestion.filterValue.toLowerCase().indexOf(lowerCaseFilter) === 0)) {
-            suggestion.filterWeight = 2;
-          } else if (foundIndex > 0) {
-            suggestion.filterWeight = 1;
+          if (foundIndex !== -1) {
+            suggestion.matchIndex = foundIndex;
+            suggestion.matchLength = self.filter().length;
+            return true;
           }
-          suggestion.matchIndex = foundIndex;
-          suggestion.matchLength = self.filter().length;
-          return true;
+          return false;
         });
         huePubSub.publish('hue.ace.autocompleter.match.updated');
       }

+ 9 - 7
desktop/libs/notebook/src/notebook/templates/hue_ace_autocompleter.mako

@@ -267,7 +267,7 @@ from desktop.views import _ko
         </div>
         <!-- /ko -->
         <!-- ko if: typeof details.comment !== 'undefined' && details.comment !== null -->
-        <div class="details-comment" data-bind="text: details.comment"></div>
+        <div class="details-comment" data-bind="matchedText: { suggestion: $data, filter: $parent.suggestions.filter, isComment: true }"></div>
         <!-- /ko -->
       </div>
     </div>
@@ -288,7 +288,7 @@ from desktop.views import _ko
         </div>
         <!-- /ko -->
         <!-- ko if: typeof details.comment !== 'undefined' && details.comment !== null -->
-        <div class="details-comment" data-bind="text: details.comment"></div>
+        <div class="details-comment" data-bind="matchedText: { suggestion: $data, filter: $parent.suggestions.filter, isComment: true }"></div>
         <!-- /ko -->
       </div>
     </div>
@@ -425,15 +425,17 @@ from desktop.views import _ko
           var refresh = function () {
             $element.empty();
             var suggestion = options.suggestion;
-            if (options.filter() && suggestion.matchIndex > -1) {
-              var before = suggestion.value.substring(0, suggestion.matchIndex);
-              var match = suggestion.value.substring(suggestion.matchIndex, suggestion.matchIndex + suggestion.matchLength);
-              var after = suggestion.value.substring(suggestion.matchIndex + suggestion.matchLength);
+            var value = options.isComment ? suggestion.details.comment : suggestion.value;
+
+            if (options.filter() && suggestion.matchIndex > -1 && ((!options.isComment && !suggestion.matchComment) || (options.isComment && suggestion.matchComment))) {
+              var before = value.substring(0, suggestion.matchIndex);
+              var match = value.substring(suggestion.matchIndex, suggestion.matchIndex + suggestion.matchLength);
+              var after = value.substring(suggestion.matchIndex + suggestion.matchLength);
               $element.append(document.createTextNode(before));
               $('<b>').text(match).appendTo($element);
               $element.append(document.createTextNode(after));
             } else {
-              $element.text(suggestion.value);
+              $element.text(value);
             }
           };