Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(elasticsearch-plugin): adds search options by collection slugs or collection IDs #3182

Open
wants to merge 1 commit into
base: minor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/api/schema/common/common-types.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions packages/elasticsearch-plugin/src/build-elastic-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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({
Expand Down
10 changes: 10 additions & 0 deletions packages/elasticsearch-plugin/src/build-elastic-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function buildElasticBody(
facetValueIds,
facetValueOperator,
collectionId,
collectionIds,
collectionSlug,
collectionSlugs,
groupByProduct,
skip,
take,
Expand Down Expand Up @@ -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 } });
Expand Down
Loading