Skip to content

Commit

Permalink
Merge #1313
Browse files Browse the repository at this point in the history
1313: Add support for distinct attribute r=curquiza a=thomas-lcdp

# Pull Request

## Related issue
Fixes #1312

## What does this PR do?
- Add support for distinct attribute

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: Thomas <thomas@lecomptoirdespharmacies.fr>
  • Loading branch information
meili-bors[bot] and thomas-lcdp authored Aug 7, 2024
2 parents 04b4e08 + f2bb298 commit c36580e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-llamas-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@meilisearch/instant-meilisearch": patch
---

Add support for distinct attribute
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,5 @@ data.ms
.turbo

.angular

.idea
1 change: 1 addition & 0 deletions packages/instant-meilisearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
meiliSearchParams.hybrid = value
}
},
addDistinct() {
const value = overrideParams?.distinct
if (value !== undefined) {
meiliSearchParams.distinct = value
}
},
}
}

Expand Down Expand Up @@ -270,6 +276,7 @@ export function adaptSearchParams(
meilisearchParams.addShowRankingScore()
meilisearchParams.addAttributesToSearchOn()
meilisearchParams.addHybridSearch()
meilisearchParams.addDistinct()

return meilisearchParams.getParams()
}
1 change: 1 addition & 0 deletions packages/instant-meilisearch/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type OverridableMeiliSearchSearchParameters = Pick<
| 'showRankingScore'
| 'attributesToSearchOn'
| 'hybrid'
| 'distinct'
>

type BaseInstantMeiliSearchOptions = {
Expand Down

0 comments on commit c36580e

Please sign in to comment.