summary refs log tree commit diff
path: root/synapse/storage/search.py
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-02-03 22:57:33 +0000
committerRichard van der Hoff <richard@matrix.org>2018-02-05 15:43:22 +0000
commitc46e75d3d8311f378f234e3de4719d6fa5d380c9 (patch)
treedaa341d9c9ef90d0b3b6ceef655122485cfa841d /synapse/storage/search.py
parentMerge pull request #2844 from matrix-org/rav/evicted_metrics (diff)
downloadsynapse-c46e75d3d8311f378f234e3de4719d6fa5d380c9.tar.xz
Move store_event_search_txn to SearchStore
... as a precursor to making event storing and doing the bg update share some
code.
Diffstat (limited to '')
-rw-r--r--synapse/storage/search.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/synapse/storage/search.py b/synapse/storage/search.py
index 479b04c636..4f38a587c8 100644
--- a/synapse/storage/search.py
+++ b/synapse/storage/search.py
@@ -242,6 +242,39 @@ class SearchStore(BackgroundUpdateStore):
 
         defer.returnValue(num_rows)
 
+    def store_event_search_txn(self, txn, event, key, value):
+        """Add event to the search table
+
+        Args:
+            txn (cursor):
+            event (EventBase):
+            key (str):
+            value (str):
+        """
+        if isinstance(self.database_engine, PostgresEngine):
+            sql = (
+                "INSERT INTO event_search"
+                " (event_id, room_id, key, vector, stream_ordering, origin_server_ts)"
+                " VALUES (?,?,?,to_tsvector('english', ?),?,?)"
+            )
+            txn.execute(
+                sql,
+                (
+                    event.event_id, event.room_id, key, value,
+                    event.internal_metadata.stream_ordering,
+                    event.origin_server_ts,
+                )
+            )
+        elif isinstance(self.database_engine, Sqlite3Engine):
+            sql = (
+                "INSERT INTO event_search (event_id, room_id, key, value)"
+                " VALUES (?,?,?,?)"
+            )
+            txn.execute(sql, (event.event_id, event.room_id, key, value,))
+        else:
+            # This should be unreachable.
+            raise Exception("Unrecognized database engine")
+
     @defer.inlineCallbacks
     def search_msgs(self, room_ids, search_term, keys):
         """Performs a full text search over events with given keys.