0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 14:53:50 +01:00

Actually filter results

This commit is contained in:
Erik Johnston 2015-10-22 16:54:56 +01:00
parent 2980136d75
commit 671ac699f1

View file

@ -48,7 +48,7 @@ class SearchStore(SQLBaseStore):
args = [] args = []
# Make sure we don't explode because the person is in too many rooms. # Make sure we don't explode because the person is in too many rooms.
# We filter the results regardless. # We filter the results below regardless.
if len(room_ids) < 500: if len(room_ids) < 500:
clauses.append( clauses.append(
"room_id IN (%s)" % (",".join(["?"] * len(room_ids)),) "room_id IN (%s)" % (",".join(["?"] * len(room_ids)),)
@ -66,13 +66,13 @@ class SearchStore(SQLBaseStore):
if isinstance(self.database_engine, PostgresEngine): if isinstance(self.database_engine, PostgresEngine):
sql = ( sql = (
"SELECT ts_rank_cd(vector, query) AS rank, event_id" "SELECT ts_rank_cd(vector, query) AS rank, room_id, event_id"
" FROM plainto_tsquery('english', ?) as query, event_search" " FROM plainto_tsquery('english', ?) as query, event_search"
" WHERE vector @@ query" " WHERE vector @@ query"
) )
elif isinstance(self.database_engine, Sqlite3Engine): elif isinstance(self.database_engine, Sqlite3Engine):
sql = ( sql = (
"SELECT 0 as rank, event_id FROM event_search" "SELECT 0 as rank, room_id, event_id FROM event_search"
" WHERE value MATCH ?" " WHERE value MATCH ?"
) )
else: else:
@ -90,6 +90,8 @@ class SearchStore(SQLBaseStore):
"search_msgs", self.cursor_to_dict, sql, *([search_term] + args) "search_msgs", self.cursor_to_dict, sql, *([search_term] + args)
) )
results = filter(lambda row: row["room_id"] in room_ids, results)
events = yield self._get_events([r["event_id"] for r in results]) events = yield self._get_events([r["event_id"] for r in results])
event_map = { event_map = {