Repository navigation
fix(search): snippet falls back to title and author fields - #20
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 a query matches only the title or author (e.g. an author-name search), snippet() previously returned the start of the summary — an irrelevant fallback. Extend the field scan to include title and author so the user sees context that explains why the result appeared. Two new smoke tests cover both cases. 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
snippet()builds the contextual excerpt shown beneath a search result. It previously scanned onlyarticle.summaryandarticle.bodyfor the matched term. When a query matched only thetitleorauthorfield — a common case for author-name searches — the function fell back to the beginning of the summary, which is unrelated to why the result appeared.Before
Searching "Nirodbaran" would surface the article correctly (the
authorfield is indexed), but the displayed snippet would show the first line of the summary — telling the reader nothing about why this result matched.After
The field scan is extended to
[summary, body, title, author]. The existing priority is preserved (summary > body), with title and author tried before giving up. For an author-name search the snippet now reads, e.g.,Nirodbaran— directly confirming the match.Change
One-line diff in
src/search.js:Tests
Two new smoke checks cover both new fallback paths:
snippet falls back to the title when only the title contains the matched termsnippet falls back to the author when only the author contains the matched termAll 21 checks pass. Build succeeds (
node scripts/build.mjs content/sample-edition.json).Advances #3.
Generated by Claude Code