element-hq / element-hq/synapse

Local users don't always appear first even with `prefer_local_users: true`

Open
#15,521 0 comments 0 reactions 0 assignees View on GitHub
A-User-Directory T-Enhancement
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#15521](https://github.com/matrix-org/synapse/issues/15521).

---

### Description

This might be somewhere between bug and feature request, since the description of the configuration setting says it *prefers* them but does not put them first. Depending on the use case (i.e. schools and other organizations), it is ideal to show the local users first and foremost.

> prefer_local_users: Defines whether to prefer local users in search query results. If set to true, local users are **more likely** to appear above remote users when searching the user directory. Defaults to false.

### Steps to reproduce

1. In `homeserver.yaml` config, set `prefer_local_users: true`
1. Search for a user by localpart using `/user_directory/search`
1. Notice that results from my homeserver (`matrix.mit.edu`) appears in fourth place whereas I expected it to be above the other remove homeservers.

![](https://user-images.githubusercontent.com/24363938/235733495-4f876231-e957-44b9-8ac7-ac91699be9c4.png)

![](https://user-images.githubusercontent.com/24363938/235733839-3a81fb3b-746a-4cfb-ab05-9a03c5640661.png)

### Homeserver

matrix.mit.edu

### Synapse Version

1.81.0+jammy1

### Installation Method

Debian packages from packages.matrix.org

### Database

Single PostgreSQL 14+238 server, no ports or restores

### Workers

Single process

### Platform

Ubuntu 20.04

### Configuration

```
user_directory:
enabled: true
search_all_users: true
prefer_local_users: true
```

### Relevant log output

```shell
{@rgabriel:matrix.mit.edu} Processed request: 0.027sec/0.000sec (0.000sec, 0.000sec) (0.000sec/0.017sec/1) 554B 200 "POST /_matrix/client/r0/user_directory/search HTTP/1.1" "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0" [0 dbevts]
```

### Anything else that would be useful to know?

_No response_

Related: #12958 (asks for ability to only show local users, this is an in-between)

Contributor guide

Open the contributing guide

Research direction

Start by tracing the /user_directory/search endpoint and the prefer_local_users setting described in homeserver.yaml, then inspect how search results are ordered. Compare the current behavior with the documented preference and the reproduction; done means local users consistently appear before remote users when the setting is enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.