Repository navigation
fix(search): snippet centres on the window with most term co-occurrence - #10
Open
ashishbhateja wants to merge 1 commit into
Open
ashishbhateja wants to merge 1 commit into
ashishbhateja wants to merge 1 commit into
Conversation
For multi-term queries the old code centred the snippet on whichever matched term appeared earliest in the text, so a search for "integral yoga" would show context around a lone "yoga" near the top even when "integral yoga" appeared together further down. The new implementation scans every occurrence of every matched term and picks the position whose context window (contextChars wide) contains the most query terms. Ties break in favour of the earlier position, so single-term behaviour is unchanged. A new smoke-test assertion demonstrates and protects the improvement. Advances #3.
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
For multi-term queries,
snippet()previously centred its context window on the earliest matched term in the text, regardless of whether other query terms were nearby. That meant a search for"integral yoga"would show a snippet around a lone"yoga"near the top of the body, even when"integral yoga"appeared together further down — so the reader saw the less relevant context.This PR changes the selection rule: scan every occurrence of every matched term and pick the position whose context window (of
contextCharscharacters) contains the most query terms. When coverage is equal, the earlier position wins, so single-term behaviour is unchanged.Changes
src/search.js—snippet()replaces the linear "first occurrence" scan with a pass over all term occurrences, scoring each by how many other query terms fall within its window.scripts/smoke.mjs— one new assertion covers the multi-term case: a body with"yoga"alone early and"integral yoga"together 200+ characters later; the snippet must include"integral".Tests
npm run buildalso passes cleanly.Issue
Advances #3 (client-side search — result snippets and highlighting).
Generated by Claude Code