Skip to content

Commit

Permalink
fix(sanity): issue where wrong versions were appearing in the global …
Browse files Browse the repository at this point in the history
…search when version was pinned
  • Loading branch information
RitaDias committed Nov 18, 2024
1 parent a3818dd commit 4f46e7b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const createTextSearch: SearchStrategyFactory<TextSearchResults> = (
factoryOptions,
) => {
const {perspective} = factoryOptions
const isRaw = perspective === 'raw'

// Search currently supports both strings (reference + cross dataset reference inputs)
// or a SearchTerms object (omnisearch).
Expand All @@ -147,12 +148,12 @@ export const createTextSearch: SearchStrategyFactory<TextSearchResults> = (
// Versions are collated server-side using the `bundlePerspective` option. Therefore, they
// must not be fetched individually.
// This should only be added if the search needs to be narrow to the perspective
!perspective && '!(_id in path("versions.**"))',
isRaw ? '' : '!(_id in path("versions.**"))',
].filter((baseFilter): baseFilter is string => Boolean(baseFilter))

const textSearchParams: TextSearchParams = {
perspective: searchOptions.perspective,
bundlePerspective: searchOptions.bundlePerspective,
perspective: isRaw ? undefined : searchOptions.perspective,
bundlePerspective: isRaw ? undefined : searchOptions.bundlePerspective,
query: {
string: getQueryString(searchTerms.query, searchOptions),
},
Expand Down
7 changes: 4 additions & 3 deletions packages/sanity/src/core/search/weighted/createSearchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export function createSearchQuery(
// Extract search terms from string query, factoring in phrases wrapped in quotes
const terms = extractTermsFromQuery(searchTerms.query)
const {perspective} = searchOpts
const isRaw = perspective === 'raw'

// Construct search filters used in this GROQ query
const filters = [
Expand All @@ -138,7 +139,7 @@ export function createSearchQuery(
searchTerms.filter ? `(${searchTerms.filter})` : '',
// Versions are collated server-side using the `bundlePerspective` option. Therefore, they must
// not be fetched individually. This should only be added if the search needs to be narrow to the perspective
!perspective && '!(_id in path("versions.**"))',
isRaw ? '' : '!(_id in path("versions.**"))',
].filter(Boolean)

const selections = specs.map((spec) => {
Expand Down Expand Up @@ -192,8 +193,8 @@ export function createSearchQuery(
},
options: {
tag,
perspective: undefined,
bundlePerspective: undefined,
perspective: isRaw ? undefined : searchOpts.perspective,
bundlePerspective: isRaw ? undefined : searchOpts.bundlePerspective,
},
searchSpec: specs,
terms,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export function SearchProvider({

const perspectives =
state.perspective === 'raw'
? {bundlePerspective: undefined}
? {bundlePerspective: undefined, perspective: undefined}
: resolvePerspectiveOptions(bundlesPerspective)

handleSearch({
Expand Down

0 comments on commit 4f46e7b

Please sign in to comment.