diff --git a/packages/sanity/src/core/search/common/types.ts b/packages/sanity/src/core/search/common/types.ts index 3b4784f9b5fd..43da95b73d0e 100644 --- a/packages/sanity/src/core/search/common/types.ts +++ b/packages/sanity/src/core/search/common/types.ts @@ -107,6 +107,7 @@ export type SearchOptions = { cursor?: string limit?: number perspective?: string + bundlePerspective?: string isCrossDataset?: boolean queryType?: 'prefixLast' | 'prefixNone' } diff --git a/packages/sanity/src/core/search/weighted/createSearchQuery.ts b/packages/sanity/src/core/search/weighted/createSearchQuery.ts index 1b83a0967b86..f2d49627c0aa 100644 --- a/packages/sanity/src/core/search/weighted/createSearchQuery.ts +++ b/packages/sanity/src/core/search/weighted/createSearchQuery.ts @@ -146,7 +146,7 @@ export function createSearchQuery( // Default to `_id asc` (GROQ default) if no search sort is provided const sortOrder = toOrderClause(searchOpts?.sort || [{field: '_id', direction: 'asc'}]) - const projectionFields = ['_type', '_id', '_version'] + const projectionFields = ['_type', '_id', '_originalId', '_version'] const selection = selections.length > 0 ? `...select(${selections.join(',\n')})` : '' const finalProjection = projectionFields.join(', ') + (selection ? `, ${selection}` : '') @@ -186,7 +186,11 @@ export function createSearchQuery( __limit: limit, ...(params || {}), }, - options: {tag, perspective: searchOpts.perspective}, + options: { + tag, + perspective: searchOpts.perspective, + bundlePerspective: searchOpts.bundlePerspective, + }, searchSpec: specs, terms, } diff --git a/packages/sanity/src/core/util/draftUtils.ts b/packages/sanity/src/core/util/draftUtils.ts index 3d34a6351a10..d184e8516a34 100644 --- a/packages/sanity/src/core/util/draftUtils.ts +++ b/packages/sanity/src/core/util/draftUtils.ts @@ -1,6 +1,6 @@ import {type SanityDocument, type SanityDocumentLike} from '@sanity/types' -import {getBundleSlug} from '../bundles/util/util' +import {getBundleSlug} from '../bundles' import {isNonNullable} from './isNonNullable' /** @internal */ @@ -175,6 +175,7 @@ interface CollateOptions { export function collate< T extends { _id: string + _originalId: string _type: string }, >(documents: T[], {bundlePerspective}: CollateOptions = {}): CollatedHit[] { @@ -200,21 +201,17 @@ export function collate< } if (!isVersion) { - entry[publishedId === doc._id ? 'published' : 'draft'] = doc + const isPublished = publishedId === doc._id + entry[isPublished ? 'published' : 'draft'] = doc + if (isPublished) { + entry.version = doc + } } return res }, new Map()) - return ( - Array.from(byId.values()) - // Remove entries that have no data, because all the following conditions are true: - // - // 1. They have no published version. - // 2. They have no draft version. - // 3. They have a version, but not the one that is currently checked out. - .filter((entry) => entry.published ?? entry.version ?? entry.draft) - ) + return Array.from(byId.values()) } /** @internal */ diff --git a/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts b/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts index 19c321bf663d..4c9022f08e70 100644 --- a/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts +++ b/packages/sanity/src/structure/panes/documentList/listenSearchQuery.ts @@ -127,6 +127,9 @@ export function listenSearchQuery(options: ListenQueryOptions): Observable