summary refs log tree commit diff
path: root/synapse/handlers/search.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-10-22 17:14:12 +0100
committerErik Johnston <erik@matrix.org>2015-10-22 17:14:12 +0100
commit53c679b59b664a248d4fce138806efe2e284c7e4 (patch)
treeabdddc0b5aadc1bd11b74c89cbf7af761d694885 /synapse/handlers/search.py
parentMerge pull request #319 from matrix-org/erikj/filter_refactor (diff)
parentActually filter results (diff)
downloadsynapse-53c679b59b664a248d4fce138806efe2e284c7e4.tar.xz
Merge pull request #324 from matrix-org/erikj/search
Add filters to search.
Diffstat (limited to 'synapse/handlers/search.py')
-rw-r--r--synapse/handlers/search.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/synapse/handlers/search.py b/synapse/handlers/search.py
index 22808b9c07..bbe82b1425 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")
 
+        search_filter = Filter(filter_dict)
+
         # TODO: Search through left rooms too
         rooms = yield self.store.get_rooms_for_user_where_membership_is(
             user.to_string(),
@@ -60,15 +64,18 @@ class SearchHandler(BaseHandler):
         )
         room_ids = set(r.room_id for r in rooms)
 
-        # TODO: Apply room filter to rooms list
+        room_ids = search_filter.filter_rooms(room_ids)
+
+        rank_map, event_map, _ = yield self.store.search_msgs(
+            room_ids, search_term, keys
+        )
 
-        rank_map, event_map = yield self.store.search_msgs(room_ids, search_term, keys)
+        filtered_events = search_filter.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()