Skip to content

fix(search): extend snippet window to word boundary at trailing edge - #17

Open
ashishbhateja wants to merge 1 commit into
mainfrom
fix/snippet-word-boundary
Open

ashishbhateja wants to merge 1 commit into
mainfrom
fix/snippet-word-boundary

Conversation

@ashishbhateja

Copy link
Copy Markdown
Owner

What and why

snippet() builds a context window of idx ± half characters around the first matched term. The trailing edge was computed as a raw character offset, which could bisect a word — for a literary publication, showing "…the ordinary consciousne …" instead of "…the ordinary consciousness …" is a noticeable rough edge.

The fix: after computing the raw end, extend it to the next space when it falls mid-word (/\S/.test(text[end])). If no subsequent space exists the window grows to end-of-text. Existing snippet behaviour is unchanged for texts that fit inside the window.

Changes

src/search.js

  • snippet(): extend end to the next word boundary when the raw window edge falls inside a word.

scripts/smoke.mjs

  • New test: snippet does not cut mid-word at the trailing window edge — verifies the fix with a body where the half-window lands mid-word.
  • New test: monthsOfMovement returns a movement's months in calendar order — monthsOfMovement was a public export with no direct test coverage; this pins its contract.
  • New test: mirrorOf returns null for months with no mirror partner — the interior-month (no-mirror) path of mirrorOf was not exercised; this covers it.

Test results

22 checks passed.  (was 19)

Build: node scripts/build.mjs content/sample-edition.json — clean.

Advances #3 (search quality).


Generated by Claude Code

The snippet() context window was computed as `idx ± half`, which
could slice text mid-word at the trailing edge (e.g., "consciousne …"
instead of "consciousness …"). Extend `end` to the next space when
it lands inside a word so displayed snippets always end on a complete
token — a visible quality improvement for a literary audience.

Also adds three targeted smoke tests:
- snippet trailing-edge word boundary (new behaviour)
- monthsOfMovement direct coverage (exported but untested)
- mirrorOf null for months with no mirror partner (untested path)

Advances #3 (search improvements) and general test coverage.

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.

2 participants