diff --git a/packages/core/src/api/schema/common/common-types.graphql b/packages/core/src/api/schema/common/common-types.graphql index 1189fd8933..3f5f5b633b 100644 --- a/packages/core/src/api/schema/common/common-types.graphql +++ b/packages/core/src/api/schema/common/common-types.graphql @@ -178,7 +178,9 @@ input SearchInput { facetValueOperator: LogicalOperator @deprecated(reason: "Use `facetValueFilters` instead") facetValueFilters: [FacetValueFilterInput!] collectionId: ID + collectionIds: [ID!] collectionSlug: String + collectionSlugs: [String!] groupByProduct: Boolean take: Int skip: Int diff --git a/packages/elasticsearch-plugin/src/build-elastic-body.spec.ts b/packages/elasticsearch-plugin/src/build-elastic-body.spec.ts index e52d30887c..c484820837 100644 --- a/packages/elasticsearch-plugin/src/build-elastic-body.spec.ts +++ b/packages/elasticsearch-plugin/src/build-elastic-body.spec.ts @@ -210,6 +210,15 @@ describe('buildElasticBody()', () => { }); }); + it('collectionIds', () => { + const result = buildElasticBody({ collectionIds: ['1', '2'] }, searchConfig, CHANNEL_ID, LanguageCode.en); + expect(result.query).toEqual({ + bool: { + filter: [CHANNEL_ID_TERM, LANGUAGE_CODE_TERM, { terms: { collectionIds: ['1', '2'] } }], + }, + }); + }); + it('collectionSlug', () => { const result = buildElasticBody( { collectionSlug: 'plants' }, @@ -224,6 +233,20 @@ describe('buildElasticBody()', () => { }); }); + it('collectionSlugs', () => { + const result = buildElasticBody( + { collectionSlugs: ['plants', 'tree'] }, + searchConfig, + CHANNEL_ID, + LanguageCode.en, + ); + expect(result.query).toEqual({ + bool: { + filter: [CHANNEL_ID_TERM, LANGUAGE_CODE_TERM, { terms: { collectionSlugs: ['plants', 'tree'] } }], + }, + }); + }); + it('paging', () => { const result = buildElasticBody({ skip: 20, take: 10 }, searchConfig, CHANNEL_ID, LanguageCode.en); expect(result).toEqual({ diff --git a/packages/elasticsearch-plugin/src/build-elastic-body.ts b/packages/elasticsearch-plugin/src/build-elastic-body.ts index 3e267634c1..c3d78980a0 100644 --- a/packages/elasticsearch-plugin/src/build-elastic-body.ts +++ b/packages/elasticsearch-plugin/src/build-elastic-body.ts @@ -19,7 +19,9 @@ export function buildElasticBody( facetValueIds, facetValueOperator, collectionId, + collectionIds, collectionSlug, + collectionSlugs, groupByProduct, skip, take, @@ -83,10 +85,18 @@ export function buildElasticBody( ensureBoolFilterExists(query); query.bool.filter.push({ term: { collectionIds: collectionId } }); } + if (collectionIds) { + ensureBoolFilterExists(query) + query.bool.filter.push({ terms: { collectionIds: Array.from(new Set(collectionIds)) } }) + } if (collectionSlug) { ensureBoolFilterExists(query); query.bool.filter.push({ term: { collectionSlugs: collectionSlug } }); } + if (collectionSlugs) { + ensureBoolFilterExists(query) + query.bool.filter.push({ terms: { collectionSlugs: Array.from(new Set(collectionSlugs)) } }) + } if (enabledOnly) { ensureBoolFilterExists(query); query.bool.filter.push({ term: { enabled: true } });