summary refs log tree commit diff
path: root/synapse/storage/schema
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-10-23 15:41:36 +0100
committerErik Johnston <erik@matrix.org>2015-10-23 15:41:36 +0100
commit4cf633d5e9628a56cf9b400ee3e073fcdcb365f0 (patch)
treed7bc50e3a8bee30e0f9fa63937f18ca10087fec5 /synapse/storage/schema
parentImplement rank function for SQLite FTS (diff)
downloadsynapse-4cf633d5e9628a56cf9b400ee3e073fcdcb365f0.tar.xz
Pull out sender when computing search results
Diffstat (limited to 'synapse/storage/schema')
-rw-r--r--synapse/storage/schema/delta/25/fts.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/synapse/storage/schema/delta/25/fts.py b/synapse/storage/schema/delta/25/fts.py
index 3f0b02d119..056487af30 100644
--- a/synapse/storage/schema/delta/25/fts.py
+++ b/synapse/storage/schema/delta/25/fts.py
@@ -26,22 +26,23 @@ POSTGRES_SQL = """
 CREATE TABLE IF NOT EXISTS event_search (
     event_id TEXT,
     room_id TEXT,
+    sender TEXT,
     key TEXT,
     vector tsvector
 );
 
 INSERT INTO event_search SELECT
-    event_id, room_id, 'content.body',
+    event_id, room_id, json::json->>'sender', 'content.body',
     to_tsvector('english', json::json->'content'->>'body')
     FROM events NATURAL JOIN event_json WHERE type = 'm.room.message';
 
 INSERT INTO event_search SELECT
-    event_id, room_id, 'content.name',
+    event_id, room_id, json::json->>'sender', 'content.name',
     to_tsvector('english', json::json->'content'->>'name')
     FROM events NATURAL JOIN event_json WHERE type = 'm.room.name';
 
 INSERT INTO event_search SELECT
-    event_id, room_id, 'content.topic',
+    event_id, room_id, json::json->>'sender', 'content.topic',
     to_tsvector('english', json::json->'content'->>'topic')
     FROM events NATURAL JOIN event_json WHERE type = 'm.room.topic';
 
@@ -99,26 +100,28 @@ def run_sqlite_upgrade(cur):
 
             rows = []
             for ev in events:
-                if ev["type"] == "m.room.message":
+                content = ev.get("content", {})
+                body = content.get("body", None)
+                name = content.get("name", None)
+                topic = content.get("topic", None)
+                sender = ev.get("sender", None)
+                if ev["type"] == "m.room.message" and body:
                     rows.append((
-                        ev["event_id"], ev["room_id"], "content.body",
-                        ev["content"]["body"]
+                        ev["event_id"], ev["room_id"], sender, "content.body", body
                     ))
-                if ev["type"] == "m.room.name":
+                if ev["type"] == "m.room.name" and name:
                     rows.append((
-                        ev["event_id"], ev["room_id"], "content.name",
-                        ev["content"]["name"]
+                        ev["event_id"], ev["room_id"], sender, "content.name", name
                     ))
-                if ev["type"] == "m.room.topic":
+                if ev["type"] == "m.room.topic" and topic:
                     rows.append((
-                        ev["event_id"], ev["room_id"], "content.topic",
-                        ev["content"]["topic"]
+                        ev["event_id"], ev["room_id"], sender, "content.topic", topic
                     ))
 
             if rows:
                 logger.info(rows)
                 cur.executemany(
-                    "INSERT INTO event_search (event_id, room_id, key, value)"
-                    " VALUES (?,?,?,?)",
+                    "INSERT INTO event_search (event_id, room_id, sender, key, value)"
+                    " VALUES (?,?,?,?,?)",
                     rows
                 )