Possible to make "exact phrase" email searches work?
-
At present searching for an exact phrase (e.g. wrapping words in quotes in Roundcube or SnappyMail) doesn't actually return only messages where those words appear together and in order. Instead it seems to return any message containing all the individual words, regardless of order or adjacency.
Digging into this with Claude, it seems this comes down to how
fts_solrbuilds its query. IMAP's baseSEARCHcommand requires strict substring matching forTEXT/BODYsearches, i.e. word order and adjacency should matter - this is specified in RFC 9051.There's a separate
FUZZYextension (RFC 6203) specifically for inexact, stemmed, token-based matching, meant to be opt-in. RFC 7377 makes the same point explicitly:The base IMAP SEARCH command (Section 6.4.4. of [RFC3501]) requires strict substring matching in text searches. Many servers, however, use search engines that match strings in different ways... This is covered by the "Fuzzy Search" extension to IMAP [RFC6203]...
It looks like Dovecot's
fts_solrcurrently searches the same way regardless of whetherFUZZYwas requested, essentially always doing the fuzzy/token-AND behaviour. There's an old Dovecot mailing list thread from a few years back where this exact same point was raised, with a proposedfts_fuzzy_defaultsetting so non-fuzzy search would actually behave as the default, non-fuzzy per the spec, withFUZZYbeing needed to get the current AND-of-tokens behaviour.I appreciate this isn't a trivial one-line fix, especially since Cloudron's Solr schema uses edge n-grams for partial-word matching (which came up in the previous thread), and phrase queries don't play nicely with n-gram-tokenized fields. It'd probably need a second, position-aware field for exact/phrase queries alongside the existing n-gram field. But given @girish is one of Dovecot's top contributors, I wondered whether this might be something worth raising upstream, since it'd presumably benefit every
fts_solruser, not just Cloudron's setup.Happy to help test if you want to try anything.
Thanks, Josef
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login