Repository navigation
fix(aggregator): fall back to full-text search for handle-shaped queries - #3841
Conversation
Any search query that parses as an AT Protocol handle or DID was only treated as a publisher lookup. When the handle didn't resolve, or resolved to a publisher with no packages, the endpoint returned no results without trying full-text search. Ordinary dotted terms such as `standard.site` or `node.js` therefore never matched packages that list them in keywords or descriptions. Run the full-text query whenever the publisher lookup produces no rows. Part of emdash-cms#3620 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
There was a problem hiding this comment.
The approach is right for #3620: keep the publisher-identity path first so a real publisher still wins, and fall back to FTS only when that path produces no rows. That fixes the standard.site-style case with minimal extra queries on the failure path, and the three new tests cover the unresolvable handle, resolved-but-empty publisher, and publisher-wins scenarios.
I read the changed searchPackages route, traced its SQL builders and the parsePublisherQuery/resolvePublisher flow, checked the new tests in read-api.test.ts, and confirmed @emdash-cms/aggregator is private so no changeset is required. The logic itself is sound, but I have two suggestions to tighten the change before merge:
- The module-level docstring no longer fully describes the endpoint — it says handle/DID queries resolve the publisher first and "other queries use FTS5", omitting the new fallback path.
- The fallback currently also runs for
handle/slugqueries, which can return literal FTS matches when a publisher resolves but doesn't have that exact slug. If the intent is specifically to rescue bare handle-shaped terms, the fallback should be gated to queries without a slug.
Findings
-
[suggestion]
apps/aggregator/src/routes/xrpc/searchPackages.ts:17-19The module docstring is now incomplete: it says handle/DID-shaped queries resolve the publisher first and that "other queries use FTS5", but after this change a handle/DID query also falls back to FTS5 when the publisher lookup returns no rows. Update the comment so future readers don't miss the fallback path.
* A query that is exactly a handle, DID, or either identity plus `/slug` * resolves the publisher first and queries by stable DID. If that lookup * produces no rows, the same query falls back to FTS5 with defensive quoting. * Other queries use FTS5 directly. Empty queries return all visible packages. -
[suggestion]
apps/aggregator/src/routes/xrpc/searchPackages.ts:112This fallback also runs for
handle/slugqueries. For example,publisher.example/nonexistentwould fall back to FTS and could return packages whose text contains that literal string, even though the user specified a concrete publisher+slug. If the intent is only to rescue bare handle-shaped terms likestandard.site, consider gating the fallback to queries without a slug.if (hasQuery && rows.length === 0 && publisherQuery?.slug === undefined) {
A `handle/slug` query names one specific package, so an empty publisher result should stay empty rather than return loose text matches. Also describe the fallback in the module comment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Both suggestions were applied in 627e6cc:
The aggregator suite passes locally (324 tests). |
What does this PR do?
Fixes the dotted-query case from #3620: any search query that looks like a handle or DID never reaches full-text search.
parsePublisherQueryaccepts anything that passesisHandle(), so ordinary terms likestandard.site,node.jsorjson-ld.orgtake the publisher-lookup path. If the handle doesn't resolve,searchPackagesreturned{ packages: [] }immediately. If it resolved to a DID with no packages, the result was also empty. Either way the FTS query never ran, sostandard.sitefound nothing even though the AT Protocol plugin lists it in its keywords and description.As suggested in the issue, the endpoint now runs the full-text query whenever the publisher lookup produces no rows. A real publisher match still wins: a resolved handle with packages returns those packages, as before. Pagination stays consistent, because a cursor is only issued when the path that served the page has more rows.
The rest of #3620 (indexing slugs, handles and capabilities, and prefix matching) needs schema and query changes, so I've kept it out of this PR.
Part of #3620
Type of change
Checklist
pnpm typecheckpasses (rantsgo --noEmitinapps/aggregator)pnpm lintpasses (ran type-awareoxlint --deny-warningson the changed files)pnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain. — n/a, no UI strings@emdash-cms/aggregatoris private and ignored by changesetsAI-generated code disclosure
Screenshots / test output
Not applicable (no UI change).
Three new tests in
apps/aggregator/test/read-api.test.ts:standard.siteas a keyword is found when the handle doesn't resolvestandard.siteas a keyword is found when the handle resolves to a publisher with no packagesWithout the fix:
2 failed | 47 passed (49)(both fallback tests return no packages). With the fix:49 passed (49). The full aggregator suite passes:12 passedfiles,323 passedtests.