Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Order by if they have profile info
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Jun 1, 2017
1 parent a757dd4 commit 036362e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions synapse/storage/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,20 @@ def search_user_dir(self, search_term, limit):
]
}
"""

search_query = _parse_query(self.database_engine, search_term)

if isinstance(self.database_engine, PostgresEngine):
# We order by rank and then if they have profile info
sql = """
SELECT user_id, display_name, avatar_url
FROM user_directory_search
INNER JOIN user_directory USING (user_id)
WHERE vector @@ to_tsquery('english', ?)
ORDER BY ts_rank_cd(vector, to_tsquery('english', ?)) DESC
ORDER BY
ts_rank_cd(vector, to_tsquery('english', ?)) DESC,
display_name IS NULL,
avatar_url IS NULL
LIMIT ?
"""
args = (search_query, search_query, limit + 1,)
Expand All @@ -291,7 +297,10 @@ def search_user_dir(self, search_term, limit):
FROM user_directory_search
INNER JOIN user_directory USING (user_id)
WHERE value MATCH ?
ORDER BY rank(matchinfo(user_directory)) DESC
ORDER BY
rank(matchinfo(user_directory)) DESC,
display_name IS NULL,
avatar_url IS NULL
LIMIT ?
"""
args = (search_query, limit + 1)
Expand Down

0 comments on commit 036362e

Please sign in to comment.