File tree Expand file tree Collapse file tree 2 files changed +41
-5
lines changed
packages/instant-meilisearch/src/adapter/search-request-adapter Expand file tree Collapse file tree 2 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -240,6 +240,39 @@ describe('Parameters adapter', () => {
240240
241241 expect ( searchParams . distinct ) . toBe ( indexDistinctSearchConfig )
242242 } )
243+
244+ test ( 'filter can be set via global override when IS filters are empty' , ( ) => {
245+ const globalFilter = 'category = "books"'
246+
247+ const searchParams = adaptSearchParams ( {
248+ ...DEFAULT_CONTEXT ,
249+ // No facetFilters, filters, or numericFilters - empty IS filters
250+ meiliSearchParams : {
251+ filter : globalFilter ,
252+ } ,
253+ } )
254+
255+ expect ( searchParams . filter ) . toBe ( globalFilter )
256+ } )
257+
258+ test ( 'filter can be set via per-index override when IS filters are empty' , ( ) => {
259+ const globalFilter = 'category = "books"'
260+ const indexFilter = 'status = "active"'
261+
262+ const searchParams = adaptSearchParams ( {
263+ ...DEFAULT_CONTEXT ,
264+ // No facetFilters, filters, or numericFilters - empty IS filters
265+ meiliSearchParams : {
266+ filter : globalFilter ,
267+ indexesOverrides : {
268+ test : { filter : indexFilter } ,
269+ } ,
270+ } ,
271+ } )
272+
273+ // Per-index override should take precedence over global override
274+ expect ( searchParams . filter ) . toBe ( indexFilter )
275+ } )
243276} )
244277
245278describe ( 'Geo filter adapter' , ( ) => {
Original file line number Diff line number Diff line change @@ -133,11 +133,14 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
133133 }
134134 } ,
135135 addFilters ( ) {
136- if ( meilisearchFilters . length ) {
137- meiliSearchParams . filter =
138- overrideParams ?. indexesOverrides ?. [ indexUid ] ?. filter ??
139- overrideParams ?. filter ??
140- meilisearchFilters
136+ const overrideFilter =
137+ overrideParams ?. indexesOverrides ?. [ indexUid ] ?. filter ??
138+ overrideParams ?. filter
139+
140+ if ( overrideFilter !== undefined ) {
141+ meiliSearchParams . filter = overrideFilter
142+ } else if ( meilisearchFilters . length ) {
143+ meiliSearchParams . filter = meilisearchFilters
141144 }
142145 } ,
143146 addAttributesToRetrieve ( ) {
You can’t perform that action at this time.
0 commit comments