فهرست منبع

HUE-2348 [search] Highlight terms inplace in the field

Return the full fragment when matching
Fix missing matches when ids are not string
Escape highlighted HTML
Romain Rigaux 11 سال پیش
والد
کامیت
dc5db15
2فایلهای تغییر یافته به همراه12 افزوده شده و 3 حذف شده
  1. 10 2
      apps/search/src/search/models.py
  2. 2 1
      desktop/libs/libsolr/src/libsolr/api.py

+ 10 - 2
apps/search/src/search/models.py

@@ -540,8 +540,16 @@ def augment_solr_response(response, collection, query):
     id_field = collection.get('idField')
     if id_field:
       for doc in response['response']['docs']:
-        if id_field in doc and doc[id_field] in highlighted_fields:
-          doc.update(response['highlighting'][doc[id_field]])
+        if id_field in doc and str(doc[id_field]) in highlighted_fields:
+          highlighting = response['highlighting'][str(doc[id_field])]
+
+          if highlighting:
+            escaped_highlighting = {}
+            for field, hls in highlighting.iteritems():
+              _hls = [escape(smart_unicode(hl, errors='replace')).replace('&lt;em&gt;', '<em>').replace('&lt;/em&gt;', '</em>') for hl in hls]
+              escaped_highlighting[field] = _hls
+  
+            doc.update(escaped_highlighting)
     else:
       response['warning'] = _("The Solr schema requires an id field for performing the result highlighting")
 

+ 2 - 1
desktop/libs/libsolr/src/libsolr/api.py

@@ -165,7 +165,8 @@ class SolrApi(object):
     params += (
       ('hl', 'true'),
       ('hl.fl', '*'),
-      ('hl.snippets', 3)
+      ('hl.snippets', 3),
+      ('hl.fragsize', 0),
     )
 
     if collection['template']['fieldsSelected']: