Repository navigation
fix(search): extend snippet window to word boundary at trailing edge - #17
Open
ashishbhateja wants to merge 1 commit into
Open
ashishbhateja wants to merge 1 commit into
ashishbhateja wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
snippet()builds a context window ofidx ± halfcharacters 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.jssnippet(): extendendto the next word boundary when the raw window edge falls inside a word.scripts/smoke.mjssnippet does not cut mid-word at the trailing window edge— verifies the fix with a body where the half-window lands mid-word.monthsOfMovement returns a movement's months in calendar order—monthsOfMovementwas a public export with no direct test coverage; this pins its contract.mirrorOf returns null for months with no mirror partner— the interior-month (no-mirror) path ofmirrorOfwas not exercised; this covers it.Test results
Build:
node scripts/build.mjs content/sample-edition.json— clean.Advances #3 (search quality).
Generated by Claude Code