Skip to content

Discover: show results for the corrected query - #520

Merged
neuromechanist merged 10 commits into
stagingfrom
feature/issue-516-corrected-query
Nov 11, 2026
Merged

neuromechanist merged 10 commits into
stagingfrom
feature/issue-516-corrected-query

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Part of OpenScience-Collective/osa#652, E6.4 first step (no AI).

Closes #516 (GitHub will not close it: staging is not the default branch, so close it by hand after the merge, naming this PR).

Summary

When GET /datasets/search answers with corrected_query, /discover prints "Showing results for bilingual." under the search box (board D2: 13px-class muted text, the corrected words in strong and the foreground color), followed by "Search for bilinugual instead", which searches the reader's own words. Nothing else from D2 is touched.

  • DatasetSearchResponse.corrected_query is typed (src/lib/types.ts).
  • correctionNotice(state, res) in src/lib/discover-search.ts is pure and returns {corrected, originalHref} or null. Null when the field is absent, not a string, blank, or equal to the query after trim, space collapse, case fold and accent fold (the API folds accents before it corrects). originalHref is /discover with the current filters, no page, q set to the original words, and exact=1. pageSearch includes it in SearchPage as correction.
  • src/components/CorrectedQueryNote.astro: scoped styles from tokens only (--fs-sm, --color-fg-muted, --color-fg), no hex, text interpolated (never set:html). Rendered in .discover__head after SearchBar when !fetchError && isSearch && correction. Caching is unchanged (the page is already keyed on the full URL).

The known trap, and what this PR does about it

The API cannot turn correction off: analyzeQuery corrects the original words again, so a plain link would reload the same results (checked against production: q=bilinugual&correct=0 still answers corrected_query: "bilingual").

  • nemar-cli issue asking for a correct=0 parameter: Search: accept correct=0 to turn off spelling correction nemar-cli#2132. nemar-cli is not changed here.
  • FilterState.exact (URL exact=1) is added, carried by paging and by filter changes (a hidden field in the filter form), and dropped when the reader types other words (isStaleExact).
  • searchDatasets sends correct=0 in exact mode only. An unknown parameter is ignored by today's API, so this is safe now.
  • In exact mode, when the answer still carries corrected_query because the backend predates the parameter, the same line is shown without the link, so the page never claims words it did not search.

The link works end to end only after nemar-cli#2132 ships. Until then, following it lands on the same results with the line and no link.

Staging limitation

The correction runs only in a catalog of at least 100 datasets (MIN_CORPUS_FOR_DF, nemar-cli search-query.ts). Staging holds only the xx0999NN test datasets, so test.nemar.org can never show the line. Its check is that /discover?q=<anything> still renders with no line and no error. That check is for after a human merges (curl -s https://test.nemar.org/version.json first); not done here.

Verification

  • bun run typecheck: 0 errors, 0 warnings (18 existing hints)
  • bun run lint: clean
  • bun run test: 170 files passed, 4687 tests passed, 14 skipped (skip count varies by environment; green is the criterion)
  • bun run build: complete
  • Live, with PUBLIC_API_BASE_URL=https://api.nemar.org bun run dev, production search answering:
    • /discover?q=bilinugual&modality=EEG shows "Showing results for bilingual." and a link to /discover?q=bilinugual&modality=EEG&exact=1
    • /discover?q=bilinugual&exact=1&modality=EEG shows the line with no link (today's API ignores correct=0), and the filter form carries exact=1
    • /discover?q=bilingual and ?q=zzzz show no line
  • test/fixtures/search-corrected-query.json is a recorded production answer for q=bilinugual&limit=3; the unit tests use it. No mocks.

Tests added: src/lib/discover-search.test.ts (present, absent, empty and whitespace, equal after normalization, exact mode, pageSearch), src/lib/filters.test.ts (exact round trip), src/lib/filter-form.test.ts (isStaleExact), src/lib/api.test.ts (correct=0 only in exact mode), test/discover-corrected-query.test.ts (source-level guard).

Out of scope

AI Mode toggle, overview panel, ai=1, reranked and modality_boost display, sidebar changes beyond carrying exact, the nemar-cli change, version bump, merge.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Deploying nemar-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: cf9c3b8
Status: ✅  Deploy successful!
Preview URL: https://6bbdb6ba.nemar-website.pages.dev
Branch Preview URL: https://feature-issue-516-corrected.nemar-website.pages.dev

View logs

@neuromechanist

neuromechanist commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Review round 1 outcomes (pushed to the branch; bun run test 4687 passed, biome check and astro check clean):

  • Important, link distinguished only by color (CorrectedQueryNote.astro): fixed in c746c50. Scoped .corrected-note a now underlines with text-underline-offset: 0.15em; a source guard in test/discover-corrected-query.test.ts pins it.
  • Suggestion, stale exact=1 with JS off (FilterSidebar.astro): fixed by accepting and documenting it, in 1938296 and b4d52b2. The comment above the hidden input and the CHANGELOG entry now say that without the script new words are searched as typed, without typo correction. Two assertions in the FilterSidebar describe pin isStaleExact( and event.formData.delete("exact"), so removing the script wiring fails a test. Moving the decision server-side was not done, because the form is still usable and the degradation is mild.
  • Suggestion, bare angle-bracket placeholders in CHANGELOG.md: fixed in 1938296; they are now corrected words and your words in backticks.
  • Suggestion, fixture case only echoes its own value (discover-search.test.ts): fixed in a4769ae and cf9c3b8. It now also asserts that results is non-empty, count >= returned and method is a string.
  • Suggestion, wrap the original words in typographic quotes: rejected. The link wording "Search for instead" comes from board D2, and I could not confirm there that quotes are allowed. Astro escapes the text and overflow-wrap handles long queries. This can be revisited if the board is updated.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 2 outcomes (no code change; the branch head is unchanged, bun run test re-run on it: 170 files, 4687 passed, 14 skipped):

  • Suggestion, stale test counts in the PR body: fixed by editing the PR body. The Verification line now reports 4687 passed, matching the round-1 comment, and notes that the skip count varies by environment (14 here, 17 in another run). No commit was needed.

@neuromechanist
neuromechanist merged commit bc28c9c into staging Nov 11, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-516-corrected-query branch November 11, 2026 19:38
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.

1 participant