Skip to content

feat(platform): match questions, not just typed names, in entity search - #2983

Merged
Israeltheminer merged 1 commit into
mainfrom
feat/work-search-matcher
Aug 17, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
feat/work-search-matcher

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Why

Entity search has exactly one matching rule (convex/lib/search/relevance.ts): every whitespace-delimited token must hit some configured field. That is the right rule when a person typed the term into a picker or a mention autocomplete. It is the wrong rule when the term is a question, because most of a question's words are absent from the data by construction.

Concretely — a real query that came back empty:

recruitment ads Facebook ad account project tasks

cannot match a task titled "Set up Facebook ad account". recruitment alone sinks it, and so do project and tasks.

This is groundwork: it unblocks giving the chat assistant reach into tasks, projects and conversations, where the search term is always a question rather than a typed name.

What changed

An opt-in matchMode on the scan engine. 'all' (the default, unchanged) requires every token. 'any':

  • drops function words across the three locales the app ships (en, de, fr) — an English-only list would leave German and French questions full of tokens that match every row;
  • keeps a row when a surviving token hits at word-start or better, so a bare mid-word substring (ad inside overhead) is not enough on its own once tokens are OR-ed;
  • leaves the existing relevance scoring to order results, so the row that answered the most of the question comes first;
  • matches nothing when the query is nothing but function words, rather than everything — that lets a caller report "too general" instead of returning the whole org.

Matching and ranking now read the same queryTokens, so a row can never be kept by one rule and ordered by another.

The stopword list deliberately carries no domain vocabulary — open, done and review are board statuses, and dropping them would make the most common question about a board unanswerable.

Two new strategies, tasks and projects, following the shape and doc-comment convention of strategies/contacts.ts. Both note the index-name trap: tasks/projects name their org index by_organization, not by_organizationId, and scopedSubstringSearch @ts-expect-errors its withIndex call — so a wrong name fails at runtime with no type error.

One duplicate collapsed. contacts/list_contacts_paginated.ts had grown its own byte-identical copy of contactsSearchStrategy while importing runEntitySearch from the shared barrel. It now imports the shared one.

Verification

bun run check clean. 424 tests pass across convex/lib/search, convex/contacts, convex/documents; typecheck, oxlint and oxfmt clean; SAST 0 findings.

Every new assertion was mutation-tested — seen red before being accepted:

Mutation Tests that caught it
'any' matches with AND instead of OR 2
stopword filtering removed 5
MIN_ANY_TIER lowered to accept mid-word substrings 1
ranking reads raw tokens instead of filtered ones 1

Two tests initially passed under the stopword mutation for the wrong reason — their fixtures did not actually contain the function words being filtered. Both were rewritten against fixtures that do, and now fail as intended.

The reported query is pinned as a regression test asserting both halves: it must not match under 'all', and must match under 'any'.

Note

tasksSearchStrategy and projectsSearchStrategy have no runtime caller yet — they are exercised by tests here and consumed by the follow-up that adds the chat legs.

Entity search has one matching rule: every whitespace token must hit some
field. That is right when a person TYPED the term into a picker, and wrong
when the term is a question, because most of a question's words are absent
from the data by construction. "recruitment ads Facebook ad account project
tasks" cannot match a task titled "Set up Facebook ad account" — "recruitment"
alone sinks it.

Add an opt-in `matchMode: 'any'` to the scan engine for callers whose term is a
question. It drops function words across the three locales the app ships,
keeps rows that hit a surviving token at word-start or better, and leaves the
existing relevance scoring to put the row that answered the most of the
question first. A query that is nothing but function words matches NOTHING
rather than everything, so a caller can report "too general" instead of
returning the whole org.

`'all'` stays the default, so every existing caller is untouched.

Also add tasks and projects strategies, and collapse the second copy of
`contactsSearchStrategy` that had grown in `list_contacts_paginated.ts` onto
the shared one.

Matching and ranking now read the same `queryTokens`, so a row can never be
kept by one rule and ordered by another.
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