Преглед изворни кода

HUE-5135 [metadata] Add proper autocomplete highlighting to matching facets

Romain Rigaux пре 9 година
родитељ
комит
b307b78

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

@@ -1680,7 +1680,7 @@ from metadata.conf import has_navigator
               }
               if (typeof data.results !== 'undefined') {
                 data.results.forEach(function (result) {
-                  values.push({ data: { label: result.originalName, icon: NAV_TYPE_ICONS[result.type],  description: result.parentPath }, value: beforePartial + result.originalName });
+                  values.push({ data: { label: result.hue_name, icon: NAV_TYPE_ICONS[result.type],  description: result.hue_description }, value: beforePartial + result.originalName });
                 });
               }
 

+ 20 - 0
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -217,6 +217,26 @@ def search_entities_interactive(request):
       if ':' in query_s and not response['facets'][fname]:
         del response['facets'][fname]
 
+  # Highlighting
+  fs = {}
+  ts = []
+  for term in query_s.split():
+    if ':' in term:
+      fname, fval = term.split(':', 1)
+      if fval and fval.strip('*'):
+        fs[fname] = fval.strip('*')
+    else:
+      if term.strip('*'):
+        ts.append(term.strip())
+
+  # facets:aa
+  # originalName', 'name', tags 'description', 'originalDescription'
+  for record in response.get('results'):
+    record['hue_description'] = ''
+    record['hue_name'] = record.get('parentPath', '').replace('/', '') + record.get('originalName', '')
+    for fname, fval in fs.iteritems():
+      if record.get(fname, ''):
+        record['hue_description'] += re.sub('(%s)' % fval, '<em>\\1</em>', record[fname], count=1)
 
   response['status'] = 0