Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
51fb590c
Commit
51fb590c
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Use more efficient query form
parent
5577a610
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/storage/search.py
+13
-8
13 additions, 8 deletions
synapse/storage/search.py
with
13 additions
and
8 deletions
synapse/storage/search.py
+
13
−
8
View file @
51fb590c
...
...
@@ -143,7 +143,7 @@ class SearchStore(BackgroundUpdateStore):
search_query
=
search_query
=
_parse_query
(
self
.
database_engine
,
search_term
)
args
=
[
search_query
]
args
=
[]
# Make sure we don't explode because the person is in too many rooms.
# We filter the results below regardless.
...
...
@@ -164,16 +164,19 @@ class SearchStore(BackgroundUpdateStore):
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
sql
=
(
"
SELECT ts_rank_cd(vector, query) AS rank, room_id, event_id
"
"
FROM to_tsquery(
'
english
'
, ?) as query, event_search
"
"
WHERE vector @@ query
"
"
SELECT ts_rank_cd(vector, to_tsquery(
'
english
'
, ?)) AS rank,
"
"
room_id, event_id
"
"
FROM event_search
"
"
WHERE vector @@ to_tsquery(
'
english
'
, ?)
"
)
args
=
[
search_query
,
search_query
]
+
args
elif
isinstance
(
self
.
database_engine
,
Sqlite3Engine
):
sql
=
(
"
SELECT rank(matchinfo(event_search)) as rank, room_id, event_id
"
"
FROM event_search
"
"
WHERE value MATCH ?
"
)
args
=
[
search_query
]
+
args
else
:
# This should be unreachable.
raise
Exception
(
"
Unrecognized database engine
"
)
...
...
@@ -232,7 +235,7 @@ class SearchStore(BackgroundUpdateStore):
search_query
=
search_query
=
_parse_query
(
self
.
database_engine
,
search_term
)
args
=
[
search_query
]
args
=
[]
# Make sure we don't explode because the person is in too many rooms.
# We filter the results below regardless.
...
...
@@ -267,12 +270,13 @@ class SearchStore(BackgroundUpdateStore):
if
isinstance
(
self
.
database_engine
,
PostgresEngine
):
sql
=
(
"
SELECT ts_rank_cd(vector,
query
) as rank,
"
"
SELECT ts_rank_cd(vector,
to_tsquery(
'
english
'
, ?)
) as rank,
"
"
origin_server_ts, stream_ordering, room_id, event_id
"
"
FROM
to_tsquery(
'
english
'
, ?) as query,
event_search
"
"
FROM event_search
"
"
NATURAL JOIN events
"
"
WHERE vector @@
query
AND
"
"
WHERE vector @@
to_tsquery(
'
english
'
, ?)
AND
"
)
args
=
[
search_term
,
search_term
]
+
args
elif
isinstance
(
self
.
database_engine
,
Sqlite3Engine
):
# We use CROSS JOIN here to ensure we use the right indexes.
# https://sqlite.org/optoverview.html#crossjoin
...
...
@@ -292,6 +296,7 @@ class SearchStore(BackgroundUpdateStore):
"
CROSS JOIN events USING (event_id)
"
"
WHERE
"
)
args
=
[
search_term
]
+
args
else
:
# This should be unreachable.
raise
Exception
(
"
Unrecognized database engine
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment