summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-05-31 18:17:47 +0100
committerErik Johnston <erik@matrix.org>2017-06-01 09:41:08 +0100
commit036362ede6cadc4d6f289dbcabfc5e06d370a587 (patch)
treee1b126f4c486f96a7b7697b5786ecb13a0641a9e /synapse
parentUse prefix matching (diff)
downloadsynapse-036362ede6cadc4d6f289dbcabfc5e06d370a587.tar.xz
Order by if they have profile info
Diffstat (limited to 'synapse')
-rw-r--r--synapse/storage/user_directory.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/synapse/storage/user_directory.py b/synapse/storage/user_directory.py
index ca2be9daf2..79161f2745 100644
--- a/synapse/storage/user_directory.py
+++ b/synapse/storage/user_directory.py
@@ -274,14 +274,20 @@ class UserDirectoryStore(SQLBaseStore):
                     ]
                 }
         """
+
         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,)
@@ -291,7 +297,10 @@ class UserDirectoryStore(SQLBaseStore):
                 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)