IMAP4 Extension for Fuzzy Search
Extracted elements (22)
Fuzzy matching is extended to non-string keys (dates, sizes, flags) so that a single FUZZY qualifier covers an entire search expression. For example, date ranges may return messages outside the range with lower scores to model queries like "about a week ago".
Fuzzy search results are explicitly non-deterministic: the same query may return different results for the same user at different times, for different users simultaneously, or due to load-balancing decisions. Clients must warn users accordingly.
Relevancy score is defined as relevance to the search rather than precision of match. A fuzzy subject match may score higher than an exact body match mid-sentence, enabling servers to rank by user intent rather than literal string similarity.
The FUZZY key is permitted to ignore the active comparator (RFC 5255) because relevance-ranked full-text search algorithms require implementation freedom; forcing a specific comparator would prevent servers from using their best matching strategies.
When the server advertises CONTEXT=SORT or CONTEXT=SEARCH (RFC 5267), clients can use the PARTIAL return option to limit the number of returned messages, e.g., retrieving only the 10 most relevant results.
When the server also advertises the ESEARCH capability (RFC 4731), the RELEVANCY return option becomes available on SEARCH to retrieve per-message relevancy scores alongside the result set.
When the server also advertises the SORT capability (RFC 5256), results can be ordered by RELEVANCY sort criteria. When ESORT (CONTEXT, RFC 5267) is advertised, SORT RETURN (RELEVANCY ALL) can retrieve both sorted UIDs and their scores.
All search keys SHOULD be matched fuzzily, although the server may decide that fuzzy matching is meaningless for a particular key and fall back to exact matching.
Servers MAY limit the resources that a single search or a single user may use, to guard against denial-of-service attacks enabled by the fuzzy search extension.
Servers SHOULD assign a search relevancy score for each matched message when the FUZZY search key is given. Relevancy scores are given in the range 1-100, where 100 is the highest relevancy.
The RELEVANCY return option MUST NOT be used unless a FUZZY search key is also given in the SEARCH command.
The relevancy scores SHOULD use the full 1-100 range so that clients can display them meaningfully to users, e.g., as a percentage value.
The RELEVANCY sort criteria MUST NOT be used unless a FUZZY search key is also given in the SORT command.
The FUZZY search key takes another search key as its argument and allows the server to perform matching in an implementation-defined manner, including ignoring the active comparator. It enables inexact matching for string searches and other key types.
The RELEVANCY return option for SEARCH (when ESEARCH is advertised) returns a score-list alongside the matched message set, e.g., `* ESEARCH (TAG "B1") ALL 1,5,10 RELEVANCY (4 99 42)`.
The RELEVANCY sort criterion for SORT (when SORT capability is advertised) orders results so the message with the highest relevancy score is returned first.
This document registers the SEARCH=FUZZY capability in the IANA "Internet Message Access Protocol (IMAP) 4 Capabilities Registry".
Fuzzy search engines can have non-obvious resource usage patterns. Implementors should test with large messages containing very long words and/or unique random strings, and with very long search keys, to prevent excessive memory or CPU consumption.
Invalid input such as illegal UTF-8 sequences in message data fed to a UTF-8-expecting search engine may cause failures. Servers should validate input and replace illegal sequences, e.g., with the Unicode replacement character U+FFFD.
Relevancy rankings may be susceptible to poisoning by attackers using certain keywords or hidden markup (e.g., HTML) to boost message scores. Clients should mitigate this by allowing users to see all search results rather than hiding those below a score threshold.
A relevancy score is encoded as `score = 1*3DIGIT` with the constraint 1 <= n <= 100. A score-list is encoded as `"(" [score *(SP score)] ")"`, a space-separated list of scores in parentheses.
The SEARCH=FUZZY capability string is added to the IMAP capability response. The `search-key` production is extended with `"FUZZY" SP search-key`, and `sort-key` is extended with `"RELEVANCY"`.