Repository navigation
fix(search): snippet always fills the full context window - #13
Open
ashishbhateja wants to merge 1 commit into
Open
ashishbhateja wants to merge 1 commit into
ashishbhateja wants to merge 1 commit into
Conversation
When the matched term was near the start or end of the text, the [idx - half, idx + half] window was clipped by the text boundary, producing a snippet half the intended width. Replace the two-variable window with a sliding approach: compute start = max(0, min(idx - half, text.length - contextChars)) and derive end from start, so the window always spans contextChars characters (or the full text when shorter). The matched term is guaranteed to remain visible because the original half-window still centres on it before clamping. Advances issue #3 (search result snippets).
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
The
snippet()function insrc/search.jshad an off-by-half bug: when a matched term appeared near the start or end of the text, the context window was clipped to half ofcontextCharsinstead of the full width.Before (simplified):
When the match was at
idx = 0, the window was[0, 60]— 60 chars instead of the intended 120.When the match was near the end (e.g.
idx = len - 5), the window was[len - half - 5, len]— again roughly half.After:
The window slides to compensate for edge clamping, so it always spans
contextCharscharacters when the text is long enough. The matched term is guaranteed to remain visible:start ≤ idxby construction.Tests
Two new cases added to
scripts/smoke.mjs(now 21 checks, up from 19) that would have caught this bug:snippet fills the full context window when the matched term is near the startsnippet fills the full context window when the matched term is near the endAll 21 checks pass.
npm run buildsucceeds.Issue
Advances #3 — specifically the "result snippets" part: a term that leads an article's summary or body now shows the reader a useful 120-char window instead of a half-width stub.
Generated by Claude Code