summary refs log tree commit diff
path: root/synapse/handlers/search.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-11-27 16:40:42 +0000
committerErik Johnston <erik@matrix.org>2015-11-27 16:40:42 +0000
commit76936f43ae0f88d4523fe07b7a9ccf8ddb5563ac (patch)
tree0d5fe0c4ca6536dff2220c594427a1cb1568e713 /synapse/handlers/search.py
parentMerge pull request #397 from matrix-org/erikj/redaction_inequality (diff)
downloadsynapse-76936f43ae0f88d4523fe07b7a9ccf8ddb5563ac.tar.xz
Return words to highlight in search results
Diffstat (limited to 'synapse/handlers/search.py')
-rw-r--r--synapse/handlers/search.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py
index 50688e51a8..6d2197339e 100644
--- a/synapse/handlers/search.py
+++ b/synapse/handlers/search.py
@@ -139,11 +139,18 @@ class SearchHandler(BaseHandler):
         # Holds the next_batch for the entire result set if one of those exists
         global_next_batch = None
 
+        highlights = set()
+
         if order_by == "rank":
-            results = yield self.store.search_msgs(
+            search_result = yield self.store.search_msgs(
                 room_ids, search_term, keys
             )
 
+            if search_result["highlights"]:
+                highlights.update(search_result["highlights"])
+
+            results = search_result["results"]
+
             results_map = {r["event"].event_id: r for r in results}
 
             rank_map.update({r["event"].event_id: r["rank"] for r in results})
@@ -187,11 +194,16 @@ class SearchHandler(BaseHandler):
                 # But only go around 5 times since otherwise synapse will be sad.
                 while len(room_events) < search_filter.limit() and i < 5:
                     i += 1
-                    results = yield self.store.search_room(
+                    search_result = yield self.store.search_room(
                         room_id, search_term, keys, search_filter.limit() * 2,
                         pagination_token=pagination_token,
                     )
 
+                    if search_result["highlights"]:
+                        highlights.update(search_result["highlights"])
+
+                    results = search_result["results"]
+
                     results_map = {r["event"].event_id: r for r in results}
 
                     rank_map.update({r["event"].event_id: r["rank"] for r in results})
@@ -347,7 +359,8 @@ class SearchHandler(BaseHandler):
 
         rooms_cat_res = {
             "results": results,
-            "count": len(results)
+            "count": len(results),
+            "highlights": list(highlights),
         }
 
         if state_results: