summary refs log tree commit diff
path: root/synapse/storage/room.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-10-12 10:49:53 +0100
committerErik Johnston <erik@matrix.org>2015-10-12 10:49:53 +0100
commit61561b9df791ec90e287e535cc75831c2016bf36 (patch)
tree903d6e26bc4bc3892c59c0a38bc9e2d3eccad96e /synapse/storage/room.py
parentAdd basic full text search impl. (diff)
downloadsynapse-61561b9df791ec90e287e535cc75831c2016bf36.tar.xz
Keep FTS indexes up to date. Only search through rooms currently joined
Diffstat (limited to 'synapse/storage/room.py')
-rw-r--r--synapse/storage/room.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 5e07b7e0e5..e4e830944a 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -175,6 +175,10 @@ class RoomStore(SQLBaseStore):
                 },
             )
 
+            self._store_event_search_txn(
+                txn, event, "content.topic", event.content["topic"]
+            )
+
     def _store_room_name_txn(self, txn, event):
         if hasattr(event, "content") and "name" in event.content:
             self._simple_insert_txn(
@@ -187,6 +191,24 @@ class RoomStore(SQLBaseStore):
                 }
             )
 
+            self._store_event_search_txn(
+                txn, event, "content.name", event.content["name"]
+            )
+
+    def _store_room_message_txn(self, txn, event):
+        if hasattr(event, "content") and "body" in event.content:
+            self._store_event_search_txn(
+                txn, event, "content.body", event.content["body"]
+            )
+
+    def _store_event_search_txn(self, txn, event, key, value):
+        sql = (
+            "INSERT INTO event_search (event_id, room_id, key, vector)"
+            " VALUES (?,?,?,to_tsvector('english', ?))"
+        )
+
+        txn.execute(sql, (event.event_id, event.room_id, key, value,))
+
     @cachedInlineCallbacks()
     def get_room_name_and_aliases(self, room_id):
         def f(txn):