Repository navigation
fix(datasets): include dataset_id + source_id in search clause - #539
Merged
Merged
Conversation
Searching by exact dataset id returned 0 results for many datasets
because the LIKE clause only matched against name, description, and
nemar_catalog.search_text. search_text isn't uniformly populated --
nm000103 happens to include the id, nm000166 doesn't. Same problem
on the catalog half: c.id was never matched directly, so a catalog
ds row would only surface if its search_text happened to include
the id.
Repro on production:
GET /datasets?search=nm000166 -> total_count=0 (catalog has it as
a public active row)
GET /datasets?search=on002718 -> total_count=0 (same)
Fix: explicitly LIKE-match dataset_id (and source_id for openneuro
mirrors) on the managed side, and c.id on the catalog side. No new
indexes needed; the dataset table is small (a few hundred rows).
Adds a regression test that picks any managed dataset from the
unfiltered list and asserts search=<id> returns it.
Refs nemarOrg/website#1 (Discover search by id).
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR539Version: 🤖 Updated on each push. |
Addresses pr-review-toolkit findings on PR #539: - The api-test test passes against the buggy code too, because it picks whichever managed dataset is first in /datasets?limit=50, and that row may already have its id embedded in c.search_text. Replace as the contract guard with a deterministic unit test on the now-exported buildFilterClauses that asserts dataset_id, source_id, and c.id appear in the clauses and the pattern is bound the right number of times. - Pre-existing LIKE-injection gap (a literal '%' or '_' in user input was treated as a SQL wildcard) is now propagated through the new id columns too. Escape '%', '_', and '\' in the search input and pair every LIKE predicate with ESCAPE '\\'. Unit tests cover both the escape function and the per-clause ESCAPE attachment. - Export buildFilterClauses + escapeLikePattern so the unit tests can call them directly. The api.test.ts integration test stays as a smoke check but is no longer the contract guard.
Contributor
Author
pr-review-toolkit review (sonnet)Two reviewers converged on the same top finding (test doesn't catch the bug) plus a pre-existing LIKE-injection gap. Both addressed in 035d631.
Tests: 9/9 unit pass, typecheck clean. The integration test stays as a smoke check; the unit tests are the contract guard going forward. |
This branch was previously 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.
Symptom
Search by exact dataset id returns 0 results for catalog rows whose enrichment didn't write the id into `nemar_catalog.search_text`. The website's Discover search box, which hits `GET /datasets?search=`, silently hides such datasets even when they're public, active, and freshly reindexed.
Live repro on api.nemar.org today:
`nm000166` is public, active, has `latest_version_doi`, and `data.nemar.org/nm000166/` returns a healthy landing payload with `v1.0.0`.
Cause
`backend/src/routes/datasets.ts:638-645` (the `buildFilterClauses` search block):
Neither side LIKE-matches the dataset id directly. The id only surfaces via `c.search_text`, which is populated inconsistently across the corpus.
Fix
Add explicit id columns to both clauses:
No new indexes. The dataset table is a few hundred rows; the extra LIKEs cost nothing measurable.
Test
New regression test: pick any managed dataset from the unfiltered list, assert that `search=` returns it. Catches any future search-clause that drops the id columns.
Acceptance