summary refs log tree commit diff
path: root/synapse/storage/room.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2015-10-21 15:48:34 +0100
committerMark Haines <mark.haines@matrix.org>2015-10-21 15:48:34 +0100
commit5201c661082cb66e544c968ab3d5d97278509774 (patch)
tree1a23e19f9be1c6139fbff4052b416261d6aadcd6 /synapse/storage/room.py
parentDoc string for the SyncHandler.typing_by_room method (diff)
parentMerge pull request #316 from matrix-org/markjh/v2_sync_archived (diff)
downloadsynapse-5201c661082cb66e544c968ab3d5d97278509774.tar.xz
Merge branch 'develop' into markjh/v2_sync_typing
Conflicts:
	synapse/handlers/sync.py
Diffstat (limited to 'synapse/storage/room.py')
-rw-r--r--synapse/storage/room.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 5e07b7e0e5..13441fcdce 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -19,6 +19,7 @@ from synapse.api.errors import StoreError
 
 from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cachedInlineCallbacks
+from .engines import PostgresEngine, Sqlite3Engine
 
 import collections
 import logging
@@ -175,6 +176,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 +192,33 @@ 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):
+        if isinstance(self.database_engine, PostgresEngine):
+            sql = (
+                "INSERT INTO event_search (event_id, room_id, key, vector)"
+                " VALUES (?,?,?,to_tsvector('english', ?))"
+            )
+        elif isinstance(self.database_engine, Sqlite3Engine):
+            sql = (
+                "INSERT INTO event_search (event_id, room_id, key, value)"
+                " VALUES (?,?,?,?)"
+            )
+        else:
+            # This should be unreachable.
+            raise Exception("Unrecognized database engine")
+
+        txn.execute(sql, (event.event_id, event.room_id, key, value,))
+
     @cachedInlineCallbacks()
     def get_room_name_and_aliases(self, room_id):
         def f(txn):