element-hq / element-hq/synapse
User directory search doesn't work when searching for user IDs.
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#7588](https://github.com/matrix-org/synapse/issues/7588).
---
### Description
The [spec states](https://matrix.org/docs/spec/client_server/r0.6.1#post-matrix-client-r0-user-directory-search) that the user directory search should be "performed case-insensitively on user IDs and display names preferably using a collation determined based upon the Accept-Language header provided in the request, if present".
The user directory works by performing a full text search on text vectors extracted from user IDs, for example:
```
synapse=# select * from user_directory_search limit 5;
user_id | vector
-------------------------------+---------------------------------------------
@negritoofcourse:matrix.org | 'matrix.org':2 'negritoofcours':1A,3B
@freenode_jin1200:matrix.org | 'freenod':1A 'jin1200':2A,4B 'matrix.org':3
@freenode_Xenguy__:matrix.org | 'freenod':1A 'matrix.org':3 'xenguy':2A,4B
@morethanabitoff:matrix.org | 'matrix.org':2 'morethanabitoff':1A,3B
@curtisthe:matrix.org | 'curtisth':1A,3B 'matrix.org':2
(5 rows)
```
The query doesn't seem to take into account searching for user IDs: https://github.com/matrix-org/synapse/blob/ed630ea17c40d328cc0796e35d37287768c7140d/synapse/storage/data_stores/main/user_directory.py#L718-L773
(The `user_id` bit at the top only being for excluding the current user from search results and/or user whom the requester does not search a public room with, depending on the value of `user_directory_search_all_users`).
The query should be updated to search by the user ID.
Additionally, we don't do anything with respect to "preferably using a collation determined based upon the Accept-Language header provided in the request, if present", but as we're just searching user ID parts here, I'm not sure how that applies.
The `tsquery` bit specifies `'english'`. Perhaps we should be modifying that based on `Accept-Language` headers.
Synapse v1.14.0.
Contributor guide
Assessment
This issue has not been assessed yet.