Skip to content

fix(search): snippet falls back to title and author fields - #20

Open
ashishbhateja wants to merge 1 commit into
mainfrom
fix/snippet-covers-title-and-author
Open

ashishbhateja wants to merge 1 commit into
mainfrom
fix/snippet-covers-title-and-author

Conversation

@ashishbhateja

Copy link
Copy Markdown
Owner

What

snippet() builds the contextual excerpt shown beneath a search result. It previously scanned only article.summary and article.body for the matched term. When a query matched only the title or author field — 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 author field 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:

- for (const text of [article.summary, article.body]) {
+ for (const text of [article.summary, article.body, article.title, article.author]) {

Tests

Two new smoke checks cover both new fallback paths:

  • snippet falls back to the title when only the title contains the matched term
  • snippet falls back to the author when only the author contains the matched term

All 21 checks pass. Build succeeds (node scripts/build.mjs content/sample-edition.json).

Advances #3.


Generated by Claude Code

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

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