Skip to content

fix: member search matches substrings, not just prefixes#2529

Open
yoamomonstruos wants to merge 4 commits into
mainfrom
tbates/add-members-search
Open

fix: member search matches substrings, not just prefixes#2529
yoamomonstruos wants to merge 4 commits into
mainfrom
tbates/add-members-search

Conversation

@yoamomonstruos

Copy link
Copy Markdown

Member search (and every other user-picker surface) only matched from the start of a name. Searching "matt" found mattkursmark; searching "kurs" returned nothing.

Root cause. User pickers search kind-0 profiles through the relay's NIP-50 FTS path with search_mode: "prefix". Profile content is indexed as a whole JSON blob, so a name is a single simple lexeme, and the prefix tsquery ('kurs':*) can never match mid-token. No existing mode could: full-text needs the whole word.

Fix, in commit order:

  1. buzz-search gains SearchMode::Contains: case-insensitive substring matching via escaped ILIKE on raw content, with the community fence, pagination, and the search-allowlist exclusion (search_tsv IS NOT NULL, so gift wraps and friends stay invisible) all unchanged. The bridge accepts search_mode: "contains".
  2. Desktop and mobile user pickers send contains instead of prefix. Desktop message typeahead keeps true prefix.
  3. buzz_db::user::search_users is deleted. It had no callers and no reachable surface; leaving it invites the "just wire it up" confusion that shaped the original issue report.
  4. The bridge upgrades profile-only prefix typeahead (prefix + kinds:[0]) to contains. Shipped desktop and mobile builds can't be taught the new mode, and every prefix hit is a substring hit, so installed apps get mid-token matching as soon as the relay deploys, with no client update. This also covers the rollout window where new clients talk to old relays: those degrade to whole-word matching, so the server-side upgrade is what actually fixes fleets in the wild.

Verification. New FTS integration tests cover mid-token matching, case-insensitivity, LIKE-metacharacter escaping, community isolation, and the allowlist fence (cargo test -p buzz-search -- --include-ignored, requires Postgres). Bridge unit tests pin the mode parsing and the prefix upgrade. Verified live against a local relay over POST /query: prefix kurs and contains kurs both return the seeded mattkursmark profile, % stays literal, and message-kind prefix search is unchanged.

Deferred. A pg_trgm index is not included. The contains scan is index-narrowed to a community's kind-0 rows, so cost scales with member count, not message volume; below ~50k members it is single-digit milliseconds. If relay timing ever shows profile search above ~50ms, a partial trigram index on kind-0 content is a one-migration follow-up.

yoamomonstruos and others added 4 commits July 23, 2026 11:14
Neither FullText nor Prefix FTS can match a fragment inside a single
lexeme: kind-0 profile content is tokenized as whole names, so a member
search for "kurs" never finds "mattkursmark". Contains mode matches the
raw content with an escaped ILIKE pattern instead of a tsquery, keeping
the community fence and the search_tsv allowlist exclusion (gift wraps
et al stay invisible). Accepted on the bridge as search_mode="contains".

Co-authored-by: Cursor <cursoragent@cursor.com>
Flip the user-search filters from search_mode="prefix" to "contains" so
every picker surface (member add, @mentions, DM recipients, topbar
people) matches any typed fragment of a name. Message typeahead stays on
prefix.

Co-authored-by: Cursor <cursoragent@cursor.com>
buzz_db::user::search_users, UserSearchProfile, and escape_like had no
callers anywhere and no relay-facing surface; relay user search now goes
through buzz-search contains mode.

Co-authored-by: Cursor <cursoragent@cursor.com>
Shipped desktop and mobile builds send search_mode="prefix" for user
pickers over kinds:[0] and can't be retroactively taught "contains".
Every prefix hit is a substring hit and profile-only searches are always
picker typeaheads, so the bridge maps that shape to contains — installed
apps get mid-token matching as soon as the relay deploys, no client
update needed. Message typeahead queries other kinds and keeps true
prefix matching.

Co-authored-by: Cursor <cursoragent@cursor.com>
@yoamomonstruos
yoamomonstruos marked this pull request as ready for review July 23, 2026 15:27
@yoamomonstruos
yoamomonstruos requested a review from a team as a code owner July 23, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant