summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-10-20 17:09:53 +0100
committerErik Johnston <erik@matrix.org>2015-10-21 10:08:53 +0100
commitc8baada94a6539cfcd1ec1316892302ae2271f4c (patch)
tree51eeeb56b37c00d9dc529405e410d8a701f71a30
parentMerge branch 'erikj/filter_refactor' into erikj/search (diff)
downloadsynapse-c8baada94a6539cfcd1ec1316892302ae2271f4c.tar.xz
Filter search results
-rw-r--r--synapse/handlers/search.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py
index 22808b9c07..473aab53f0 100644
--- a/synapse/handlers/search.py
+++ b/synapse/handlers/search.py
@@ -18,6 +18,7 @@ from twisted.internet import defer
 from ._base import BaseHandler
 
 from synapse.api.constants import Membership
+from synapse.api.filtering import Filter
 from synapse.api.errors import SynapseError
 from synapse.events.utils import serialize_event
 
@@ -49,9 +50,12 @@ class SearchHandler(BaseHandler):
             keys = content["search_categories"]["room_events"].get("keys", [
                 "content.body", "content.name", "content.topic",
             ])
+            filter_dict = content["search_categories"]["room_events"].get("filter", {})
         except KeyError:
             raise SynapseError(400, "Invalid search query")
 
+        filtr = Filter(filter_dict)
+
         # TODO: Search through left rooms too
         rooms = yield self.store.get_rooms_for_user_where_membership_is(
             user.to_string(),
@@ -64,11 +68,12 @@ class SearchHandler(BaseHandler):
 
         rank_map, event_map = yield self.store.search_msgs(room_ids, search_term, keys)
 
+        filtered_events = filtr.filter(event_map.values())
+
         allowed_events = yield self._filter_events_for_client(
-            user.to_string(), event_map.values()
+            user.to_string(), filtered_events
         )
 
-        # TODO: Filter allowed_events
         # TODO: Add a limit
 
         time_now = self.clock.time_msec()