fix(core): search across all collections fails when one has no title field (#1178)#1550
Open
marcusbellamyshaw-cell wants to merge 1 commit into
Conversation
…eld (emdash-cms#1178) `title` is an optional user-defined field, not a system column on `ec_*` tables. `searchSingleCollection` and `getSuggestions` selected `c.title` unconditionally, so searching across all collections (no `collections` filter) threw `D1_ERROR: no such column: c.title` whenever any search-enabled collection lacked a `title` field. Scoping to collections that happen to have a title masked the bug. Add `FTSManager.hasTitleColumn` and use it to select `NULL` for the title when the column is absent (results keep their slug) in `searchSingleCollection`, and to skip title-less collections in `getSuggestions` (a suggestion requires a title and the query already filters on `c.title IS NOT NULL`). Adds a regression test covering the cross-collection search and suggestion paths with a collection that has no title field. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 0b66374 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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 does this PR do?
Fixes the
searchAPI and MCPsearchtool throwingD1_ERROR: no such column: c.titlewhen searching across all collections (nocollectionsfilter) and any search-enabled collection has notitlefield.titleis an optional user-defined field, not a system column onec_*tables (the system columns areid, slug, status, author_id, primary_byline_id, created_at, updated_at, published_at, scheduled_at, deleted_at, version, live_revision_id, draft_revision_id, locale, translation_group).searchSingleCollectionandgetSuggestionsselectedc.titleunconditionally, so the cross-collection path errored whenever it reached a collection without atitlefield. Passing an explicitcollectionslist that happened to have titles masked the bug — which matches the report (works with["pages","posts"], fails withoutcollections).The codebase already handles this exact gotcha in
api/handlers/dashboard.ts(fetchRecentItemschecks_emdash_fieldsfor atitlefield and falls back toslug); this PR applies the same precedent to search.Changes
FTSManager.hasTitleColumn(slug)— checks_emdash_fieldsfor atitlefield (mirrors the dashboard handler).searchSingleCollection: selectNULL as titlewhen the collection has notitlecolumn (results keep theirslug;SearchResult.titleis already optional).getSuggestions: skip collections without atitlefield (aSuggestion.titleis required and the query already filters onc.title IS NOT NULL, so these collections contribute nothing anyway).searchWithDbandgetSuggestions"all collections" paths.Closes #1178
Type of change
Checklist
pnpm typecheckpassespnpm lintpasses (oxlint, 0 diagnostics on changed files)pnpm testpasses (targeted: all search/MCP-search/suggest/i18n/schema suites — 138 tests green, incl. the new regression test)pnpm formathas been run (tabs; consistent with surrounding code)emdashpatch)AI-generated code disclosure
Screenshots / test output
Before (new test on the unpatched tree):
After: