# Fuzzy clause of a term query uses the raw text, so typos in capitalized or stemmed words never match

**URL:** <https://discuss.codelibs.org/t/fuzzy-clause-of-a-term-query-uses-the-raw-text-so-typos-in-capitalized-or-stemmed-words-never-match/2782>\
**Category:** English:Fess\
**Created:** [November 1, 2026, 9:36pm UTC](https://discuss.codelibs.org/t/fuzzy-clause-of-a-term-query-uses-the-raw-text-so-typos-in-capitalized-or-stemmed-words-never-match/2782 "2026-11-01T21:36:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram-fabian-heinrich](https://discuss.codelibs.org/user_avatar/discuss.codelibs.org/ram-fabian-heinrich/32/909_2.png) [@ram-fabian-heinrich](https://discuss.codelibs.org/u/ram-fabian-heinrich)\
**Post date:** [November 1, 2026, 9:36pm UTC](https://discuss.codelibs.org/t/fuzzy-clause-of-a-term-query-uses-the-raw-text-so-typos-in-capitalized-or-stemmed-words-never-match/2782/1 "2026-11-01T21:36:12Z")

</div>

**Fess version:** 15.9.0

**Problem**

`TermQueryCommand#buildDefaultTermQuery` adds `fuzzyQuery(title, text)` and `fuzzyQuery(content, text)` with the text exactly as typed. A fuzzy query is term-level and not analyzed, but `title` and `content` are indexed with `standard_analyzer` (asciifolding, lowercase, `stemmer_en_filter`, …). So the edit distance is measured against the analyzed terms:

- an uppercase letter costs one edit by itself;
- a word the English stemmer shortens is stored stemmed, so a typo in it is several edits away.

**Examples** (index contains “Fabian” and “Onboarding”)

| query | hits | why |
| --- | --- | --- |
| `fbian` | 2,524 | 1 edit to `fabian` |
| `Fbian` | 0 | `F` → `f` + missing `a` = 2 edits, `AUTO` allows 1 for 5 characters |
| `onbording` | 0 | indexed term is `onboard` (stemmed), 4 edits away |

Capitalized nouns (German) and inflected words (English `-ing`, `-s`, `-ed`) are common, so the fuzzy clause rarely helps.

**Proposed fix**

Use an analyzed query with fuzziness instead of a raw `fuzzyQuery`, e.g. `matchQuery(field, text).fuzziness(...).prefixLength(...).maxExpansions(...).fuzzyTranspositions(...)`. The text then goes through the field’s search analyzer first (`Onbording` → `onbord`, 1 edit to `onboard`; `Fbian` → `fbian`, 1 edit to `fabian`).

Tested on the same index with `fuzziness: AUTO`, `max_expansions: 10` on `content`:

| query | `fuzzy` (current) | `match` + fuzziness |
| --- | --- | --- |
| `Onbording` | 0 | 1,556 |
| `Fbian` | 0 | 2,524 |

---

<div class="post-metadata">

**Author:** ![shinsuke](https://discuss.codelibs.org/user_avatar/discuss.codelibs.org/shinsuke/32/6_2.png) [@shinsuke](https://discuss.codelibs.org/u/shinsuke)\
**Post date:** [November 2, 2026, 9:51pm UTC](https://discuss.codelibs.org/t/fuzzy-clause-of-a-term-query-uses-the-raw-text-so-typos-in-capitalized-or-stemmed-words-never-match/2782/2 "2026-11-02T21:51:33Z")

</div>

Thanks for the detailed report — you were right. The fuzzy clause compared the raw text against the analyzed index terms, so capitalized or stemmed typos (e.g. Fbian, Onbording) never matched.

This is fixed in Fess 15.10: the clause is now a match query with fuzziness, so the text goes through the analyzer first.

> <https://github.com/codelibs/fess/pull/3726>
>
> \## Summary
> 
> The implicit fuzzy clause that \`TermQueryCommand\` adds for plain ter…ms (4+ characters) used a term-level \`fuzzy\` query with the text exactly as typed. \`title\` and \`content\` are indexed with \`standard\_analyzer\`, so the edit distance was measured against the analyzed form of the word:
> 
> | query | before | after | why |
> |---|---|---|---|
> | \`fbian\` | 2 | 2 | 1 edit to \`fabian\` |
> | \`Fbian\` | 0 | 2 | before: \`F\`→\`f\` plus the missing \`a\` = 2 edits, \`AUTO\` allows 1 for 5 characters |
> | \`Onbording\` | 0 | 71 | before: the indexed term is the stem \`onboard\`, 4 edits away; after: analyzed to \`onbord\`, 1 edit |
> 
> Reported in https://discuss.codelibs.org/t/fuzzy-clause-of-a-term-query-uses-the-raw-text-so-typos-in-capitalized-or-stemmed-words-never-match/2782 (counts above come from a local index built with the shipped \`fess.json\` / \`doc.json\`).
> 
> \## Change
> 
> \- \`fuzzy(field, text)\` becomes \`match(field, text)\` with \`operator(AND)\`, \`fuzziness\`, \`prefixLength\`, \`maxExpansions\` and \`fuzzyTranspositions\` taken from the existing \`query.boost.fuzzy.\*\` settings. The text goes through the search analyzer first.
> \- \`AND\`, because text that analyzes to several tokens (\`foo-bar\`, \`wi-fi\`) must match all of them. With the default \`OR\`, \`foo-bar\` matched 85 documents instead of 1.
> \- By default, no clause for text containing Han, Hiragana, Katakana or Hangul. The analyzer produces two-character bigrams, \`AUTO\` allows no edit for two characters, so the old clause never matched a CJK typo (0% recall measured for ja/zh/ko). An \`OR\` match there hit hundreds of documents even for correctly spelled words.
> \- New setting \`query.boost.fuzzy.cjk.enabled\` (default \`false\`, behavior unchanged). Set \`true\` to add the clause for CJK text too, for setups whose \`title\` / \`content\` analyzer does not produce bigrams (for example a morphological analyzer). Not measured with a custom analyzer.
> \- The \`match\_phrase\` clauses and the language-specific fields are untouched. \`match\_phrase\` has no fuzziness option, so it cannot take over this role.
> \- \`FuzzyQueryCommand\` (the explicit \`foo~1\` syntax) is not changed.
> 
> \## Behavior changes to be aware of
> 
> \- \`AUTO\` now applies to the length of each analyzed token, not of the typed text. The \`query.boost.fuzzy.min.length\` check still uses the typed text.
> \- Text that analyzes to only stopwords no longer gets fuzzy neighbour hits (\`zero\_terms\_query\` is \`NONE\`).
> \- Latin-script queries get more low-ranked hits from the fuzzy clauses, because stemmed words are short and have more neighbours. Measured on the fess-docs 15.9 corpus (en/de/es/fr, 30-40 words each): fuzzy-only documents for a correctly spelled word rose about 1.2x to 2.8x. Boosts are unchanged (0.01 / 0.005).
> \- Top-10 order for correctly spelled English words was identical for 62 of 100 words; the old fuzzy clause versus no fuzzy clause was identical for 51 of 100.
> \- CJK behavior is unchanged: the clause was inert there.
> \- One setting is added (\`query.boost.fuzzy.cjk.enabled\`, default keeps the behavior above) and none is renamed, so no upgrade note is needed.
> 
> Recall of typo queries against the documents the correct spelling finds (same corpus):
> 
> | typo | before | lowercase only | this PR |
> |---|---|---|---|
> | lowercase typo | 58-90% | 58-90% | 82-93% |
> | capitalized typo | 15-69% | 58-90% | 82-93% |
> 
> \## Test plan
> 
> \- \[x\] \`TermQueryCommandTest\`: asserts the emitted \`match\` JSON, the analyzed-text behavior for \`Fbian\` / \`onbording\` / \`Servers\`, no clause for CJK text and none below the minimum length, and a clause for CJK text when \`query.boost.fuzzy.cjk.enabled=true\`.
> \- \[x\] \`QueryHelperTest\` expectations updated to the new clause.
> \- \[x\] Full unit suite: 9187 tests, 0 failures.
> \- \[x\] The emitted JSON was run against \`fess-opensearch:3.9.0\` with the shipped index settings (counts in the table above); synonym expansion (\`fess\`) and hyphenated terms run without errors.
