Skip to content

fix(search): ignore accents when matching - #845

Draft
SebastienSyd wants to merge 1 commit into
cooklang:mainfrom
snicot:fix/search-ignore-accents
Draft

SebastienSyd wants to merge 1 commit into
cooklang:mainfrom
snicot:fix/search-ignore-accents

Conversation

@SebastienSyd

Copy link
Copy Markdown
Contributor

Fixes #844: search treats accented letters as different letters, so crepes misses Crêpes.cook in cook search, /api/search, the header dropdown and /search.

Draft, depends on cooklang/cooklang-find#41. This uses cooklang_find::normalize_for_search, which only exists on that branch, so CI won't compile until it's released and cooklang-find is bumped in both Cargo.toml and crates/core/Cargo.toml. I'll push the bump here once there's a version.

Change

  • crates/core/src/search.rs: terms, file stems and contents are folded with cooklang_find::normalize_for_search instead of to_lowercase(). Using the library's own function keeps the invariant documented on matches_every_term: the AND filter can't drop a recipe the library matched.
  • static/js/search.js (static cook build sites): the same fold in the browser, via toLowerCase().normalize("NFD").replace(/\p{M}/gu, "").
  • Module docs now say matching ignores accents as well as case.

Tests

  • New terms_match_regardless_of_accents: an unaccented term finds an accented file name, unaccented terms find accented contents (ANDed), and an accented term finds unaccented text.

Run locally against the cooklang-find branch through a temporary [patch.crates-io] (not committed):

  • cargo fmt --all --check and cargo clippy --all-targets -- -D warnings: clean.
  • cargo test: all search, server and API tests pass. Three tests failed, and all three are environment-specific: two pantry permission tests (the run was as root, as noted in CLAUDE.md) and update::tests::release_workflow_builds_this_platform (aarch64 Linux isn't in the release matrix).

🤖 Generated with Claude Code

Fold terms, file stems and contents with
`cooklang_find::normalize_for_search`, the same function the library
scores with, so the AND filter keeps the recipes `cooklang-find` now
matches without accents. Fold the same way in the static site's
`search.js`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst

LeMyst commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks, this works, and it covers every place search runs. I tested the PR head merged with today's main, with cooklang-find bumped to 0.12.2 locally.

Left to do before it can land

  1. cooklang-find 0.12.2, with feat(search): ignore accents when matching cooklang-find#41, came out on 2026-11-24. Raise the minimum version in both manifests, not just the lock, because normalize_for_search doesn't exist before 0.12.2:
    sed -i 's/^cooklang-find = { version = "0.12.0"/cooklang-find = { version = "0.12.2"/' Cargo.toml crates/core/Cargo.toml
    cargo update -p [email protected] --precise 0.12.2
    The lock only changes the version and adds unicode-normalization, which is already in the tree (0.1.26).
  2. docs/search.md:39 still says "Case-insensitive". Something like: "Ignores case and accents: crepes finds Crêpes, and crêpes finds crepes".

The branch merges with main cleanly, so it doesn't need a rebase.

What I checked (with the bump)

  • cargo fmt --all --check, CI's cargo clippy --workspace --all-targets --all-features -- -D warnings and cargo test --workspace --no-fail-fast all pass.
  • cook search on the issue's reproduction: crepes, cre, creme fraiche and CRÉPES all find their recipes. AND still narrows (farine creme finds nothing). A decomposed file name (Pâte.cook, as macOS writes it) is found by both pate and pâte.
  • Static site: I ran cook build web on the same folder, then ran the built search.js against its search-index.js in node. crepes, cre and pate now find Crêpes, Gratin and Pâte; main's search.js finds nothing for any of them.
  • On the server, /api/search, the /search page, the header dropdown and the menu editor's recipe picker all go through cookcli_core::search, so nothing else needs the fold.
  • The library drops General_Category=Mark (unicode_normalization::char::is_combining_mark), which is the same set as JS \p{M}, in the same order: lowercase, NFD, then drop. So the static site and the server agree.

Nit (optional): text_around_an_invalid_byte_still_matches (crates/core/src/search.rs, about line 641) still builds its terms with str::to_lowercase, while matches_every_term now expects them folded by normalize_for_search. It makes no difference with its ASCII terms, but the helper would then follow the documented contract.

Worth knowing, not for this PR: General_Category=Mark covers more than accents. Japanese voicing marks come apart under NFD and get dropped, so パン (bread) finds ハンバーグ (hamburg steak), and ぶた (pork) folds the same as ふた (lid). Devanagari vowel signs go too (दाल folds to दल). This only adds results and never loses one, and this PR has to match the library either way. If it's worth refining (ja-JP is one of the UI languages), the change belongs in cooklang-find's fold, for example keeping U+3099/U+309A and the vowel signs of Indic scripts, with search.js following.

Analysis and recommendations/changes made by Claude, posted on behalf of @LeMyst.

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.

Search does not ignore accents: crepes misses Crêpes

2 participants