← Context/ issues
Search Ranks Passing Mentions Above Real Matches
A two-word search returned one email about the subject and three that mentioned it in passing. Search does require every word; it sorts newest first and shows one excerpt, so the real match was buried and the others looked wrong.
What we saw
Claude searched a deal name plus a vehicle type (two words). Only the first
result was about the deal; the other three seemed to mention only the vehicle
type. Claude concluded that search matches any of the words and suggested
quoting the phrase or adding AND.
What's actually happening
The conclusion is wrong; the complaint is right.
Search already requires every word. In SQLite FTS5, space-separated terms are an implicit AND. For the newest four results, D1 shows both words present in each: the deal name in the subject and body of the first, and in the body of the other three.
It sorts newest first.
search_mailorders bym.date DESCunless the caller passesrelevance: true(connector/src/tools.ts). The one email about the deal, with the name in its subject, ranks no higher than three that mention it once in a long body.The excerpt hides the match.
snippet(messages_fts, 3, …)returns one window from the body. When the second word is far from the first, or in the subject, the excerpt shows only one of them, and the result looks like a false match.
Fix
Default to relevance for keyword searches, with date as the tie-breaker. Keep newest-first when there's no query, and as an explicit option.
Weight the fields.
bm25(messages_fts, 10.0, 3.0, 1.0, 1.0, 2.0)(subject, from, to, body, attachments) so a word in the subject outranks the same word in a quoted reply.Show why it matched. Return which fields matched, or a subject snippet alongside the body one, so a reader (or Claude) can see the second word.
Say how queries work in the tool description: words are ANDed,
ORand quotes are available. Claude reached for workarounds because the description didn't say.
How we'll know
The same two-word search puts the email about the deal first, and every result's excerpt shows both words or names the field the other one is in.
Resolved (2026-11-27)
Relevance by default for keyword searches:
ORDER BY bm25(messages_fts, 10, 3, 1, 1, 2), date DESC(subject, from, to, body, attachments), so a word in the subject counts ten times one in the body.relevance: falsesorts newest first.Why it matched: results carry
subject_match, a subject excerpt, beside the bodysnippet.The tool description says how queries work: words are ANDed;
OR, quotes, prefixes, andsubject:are available.Test: "a keyword search ranks the email about it above newer ones that mention it in passing". The laptop's
kaymail.py searchkeeps its old ordering for now.