diff --git a/.changeset/smart-llamas-draw.md b/.changeset/smart-llamas-draw.md new file mode 100644 index 00000000..74c9a7f7 --- /dev/null +++ b/.changeset/smart-llamas-draw.md @@ -0,0 +1,5 @@ +--- +"@meilisearch/instant-meilisearch": patch +--- + +Add support for distinct attribute diff --git a/.gitignore b/.gitignore index 7bc85a9a..258a46e4 100644 --- a/.gitignore +++ b/.gitignore @@ -124,3 +124,5 @@ data.ms .turbo .angular + +.idea diff --git a/packages/instant-meilisearch/README.md b/packages/instant-meilisearch/README.md index d5ef5f52..54f4ca97 100644 --- a/packages/instant-meilisearch/README.md +++ b/packages/instant-meilisearch/README.md @@ -224,6 +224,7 @@ The following options can be overridden: [`showRankingScore`](https://www.meilisearch.com/docs/reference/api/search#ranking-score), [`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time), [`hybrid`](https://www.meilisearch.com/docs/learn/experimental/vector_search) +[`distinct`](https://www.meilisearch.com/docs/learn/relevancy/distinct_attribute) ```js instantMeiliSearch( diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts index 473a9fd4..1361ab58 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/__tests__/search-params.test.ts @@ -94,6 +94,19 @@ describe('Parameters adapter', () => { expect(searchParams.hybrid).toBe(hybridSearchConfig) }) + + test('distinct search configuration can be set via search parameters', () => { + const distinctSearchConfig = 'title' + + const searchParams = adaptSearchParams({ + ...DEFAULT_CONTEXT, + meiliSearchParams: { + distinct: distinctSearchConfig, + }, + }) + + expect(searchParams.distinct).toBe(distinctSearchConfig) + }) }) describe('Geo filter adapter', () => { diff --git a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts index efdec9b5..2d70f4c6 100644 --- a/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts +++ b/packages/instant-meilisearch/src/adapter/search-request-adapter/search-params-adapter.ts @@ -238,6 +238,12 @@ export function MeiliParamsCreator(searchContext: SearchContext) { meiliSearchParams.hybrid = value } }, + addDistinct() { + const value = overrideParams?.distinct + if (value !== undefined) { + meiliSearchParams.distinct = value + } + }, } } @@ -270,6 +276,7 @@ export function adaptSearchParams( meilisearchParams.addShowRankingScore() meilisearchParams.addAttributesToSearchOn() meilisearchParams.addHybridSearch() + meilisearchParams.addDistinct() return meilisearchParams.getParams() } diff --git a/packages/instant-meilisearch/src/types/types.ts b/packages/instant-meilisearch/src/types/types.ts index 114638a1..530b63e7 100644 --- a/packages/instant-meilisearch/src/types/types.ts +++ b/packages/instant-meilisearch/src/types/types.ts @@ -55,6 +55,7 @@ export type OverridableMeiliSearchSearchParameters = Pick< | 'showRankingScore' | 'attributesToSearchOn' | 'hybrid' + | 'distinct' > type BaseInstantMeiliSearchOptions = {