Sfoglia il codice sorgente

HUE-5149 [metadata] Support tags:hue syntax in result view

Romain Rigaux 9 anni fa
parent
commit
2e50b41
1 ha cambiato i file con 11 aggiunte e 4 eliminazioni
  1. 11 4
      desktop/libs/metadata/src/metadata/navigator_api.py

+ 11 - 4
desktop/libs/metadata/src/metadata/navigator_api.py

@@ -246,12 +246,13 @@ def _augment_highlighting(query_s, records):
     for term in ts:
       name = _highlight(term, name)
       if record.get('tags'):
-        for tag in record['tags']:
-          if re.match(term, tag):
-            record['hue_description'] += ' tags:%s' % _highlight(term, tag)
+        _highlight_tags(record, term)
     for fname, fval in fs.iteritems(): # e.g. owner:<em>hu</em>e
       if record.get(fname, ''):
-        record['hue_description'] += ' %s:%s' % (fname, _highlight(fval, record[fname]))
+        if fname == 'tags':
+          _highlight_tags(record, fval)
+        else:
+          record['hue_description'] += ' %s:%s' % (fname, _highlight(fval, record[fname]))
 
     record['hue_name'] += name
     record['hue_name'] = escape(record['hue_name']).replace('&lt;em&gt;', '<em>').replace('&lt;/em&gt;', '</em>')
@@ -262,6 +263,12 @@ def _highlight(pattern, string):
   return re.sub('(%s)' % pattern, '<em>\\1</em>', string, count=1)
 
 
+def _highlight_tags(record, term):
+    for tag in record['tags']:
+      if re.match(term, tag):
+        record['hue_description'] += ' tags:%s' % _highlight(term, tag)
+
+
 @error_handler
 def list_tags(request):
   api = NavigatorApi()