diff --git a/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.test.ts b/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.test.ts index 3fcb6617107..1853d912e1e 100644 --- a/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.test.ts +++ b/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.test.ts @@ -23,7 +23,12 @@ describe('stringOperators', () => { it('should create a valid filter for stringMatches', () => { const filter = stringOperators.stringMatches.groqFilter({fieldPath, value}) - expect(filter).toEqual(`${fieldPath} match "${value}"`) + expect(filter).toEqual(`${fieldPath} match "*${value}*"`) + }) + + it('should create a valid filter for stringNotMatches', () => { + const filter = stringOperators.stringNotMatches.groqFilter({fieldPath, value}) + expect(filter).toEqual(`!(${fieldPath} match "*${value}*")`) }) it('should create a valid filter for stringNotEqual', () => { diff --git a/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.ts b/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.ts index 06188c70286..e51798b792d 100644 --- a/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.ts +++ b/packages/sanity/src/core/studio/components/navbar/search/definitions/operators/stringOperators.ts @@ -37,7 +37,7 @@ export const stringOperators = { nameKey: 'search.operator.string-contains.name', descriptionKey: 'search.operator.string-contains.description', groqFilter: ({fieldPath, value}) => - value && fieldPath ? `${fieldPath} match ${toJSON(value)}` : null, + value && fieldPath ? `${fieldPath} match "*${value}*"` : null, initialValue: null, inputComponent: SearchFilterStringInput as SearchOperatorInput, type: 'stringMatches', @@ -55,7 +55,7 @@ export const stringOperators = { nameKey: 'search.operator.string-not-contains.name', descriptionKey: 'search.operator.string-not-contains.description', groqFilter: ({fieldPath, value}) => - value && fieldPath ? `!(${fieldPath} match ${toJSON(value)})` : null, + value && fieldPath ? `!(${fieldPath} match "*${value}*")` : null, initialValue: null, inputComponent: SearchFilterStringInput as SearchOperatorInput, type: 'stringNotMatches',