Skip to content

fix(search): tokenize diacritical text via NFD normalisation - #31

Open
ashishbhateja wants to merge 1 commit into
mainfrom
fix/search-diacritics
Open

ashishbhateja wants to merge 1 commit into
mainfrom
fix/search-diacritics

Conversation

@ashishbhateja

Copy link
Copy Markdown
Owner

What this changes

tokenize in src/search.js now applies NFD normalisation and strips combining diacritical marks (U+0300–U+036F) before splitting on non-word characters. Two lines added, no logic changed for ASCII input.

Why

Words containing diacritical characters were silently mangled by the search index. For example:

  • "Śrī Aurobindo" → only ["aurobindo"] was indexed; "sri" was lost entirely because Ś and ī are non-ASCII and caused the regex to split around single-character fragments that were then filtered out.
  • "Pondichéry" → indexed as ["pondich", "ry"] (two useless fragments) instead of ["pondichery"].

This matters for a magazine whose content routinely uses Sanskrit transliterations and proper nouns with French/Indian diacriticals. A reader typing "Sri" to find articles about Śrī Aurobindo got no results from any title or field that used the Unicode form.

The fix uses String.prototype.normalize('NFD') (standard in all engines since 2014) to decompose accented characters into a base letter plus a combining mark, then strips the combining marks. ASCII text is completely unaffected.

Closes #3 (partial — improves index fidelity for multilingual content).

Checklist

  • node scripts/smoke.mjs passes (22 checks, up from 19; three new diacritics tests added)
  • No new runtime dependencies
  • For UI changes: keyboard, focus, and semantics considered (no UI change)
  • No magazine content committed (developed against the sample edition)

Generated by Claude Code

Words like "Śrī" were silently reduced to just "aurobindo" (losing "sri"
entirely) because the regex split on the non-ASCII code-points. Applying
NFD normalisation followed by stripping the U+0300–U+036F combining-mark
block lets diacritical variants like Śrī/ā/é match their ASCII equivalents,
which is how a reader would naturally type a search query.

Adds three new checks in smoke.mjs: per-token diacritics stripping for
Śrī → sri and Pondichéry → pondichery, and an end-to-end search test that
finds a diacritical title via an ASCII query.

Advances #3.

This branch has not been deployed

No deployments
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.

Feature: Add full-text search for magazine archives

2 participants