Skip to content

Commit

Permalink
Merge #1318
Browse files Browse the repository at this point in the history
1318: feat(instant-meilisearch): add ranking score threshold r=brunoocasali a=Strift

## Related issue
Fixes #1315 

## What does this PR do?

features:
- add `rankingScoreThreshold` to the search parameters
- update `README.md` to list the new search parameter
- sort search parameters alphabetically (in the readme & the code)

maintenance:
- add `.nvmrc` to pin node version
- pin package manager in `package.json`

## 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: Strift <[email protected]>
  • Loading branch information
meili-bors[bot] and Strift authored Aug 14, 2024
2 parents d9b427a + f6649aa commit 72a0346
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-hounds-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@meilisearch/instant-meilisearch": patch
---

Add support for [ranking score threshold](https://www.meilisearch.com/docs/reference/api/search#ranking-score-threshold?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch)
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.20.2
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"dependencies": {
"@changesets/cli": "^2.26.1",
"instantsearch.css": "^8.0.0"
}
},
"packageManager": "[email protected]"
}
25 changes: 13 additions & 12 deletions packages/instant-meilisearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,19 @@ You can use your own HTTP client, for example, with [`axios`](https://github.com

`meiliSearchParams` lets you override a set of search parameters that are sent off to Meilisearch.
The following options can be overridden:
[`attributesToRetrieve`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-retrieve),
[`attributesToCrop`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-crop),
[`cropLength`](https://www.meilisearch.com/docs/reference/api/search#crop-length),
[`cropMarker`](https://www.meilisearch.com/docs/reference/api/search#crop-marker),
[`attributesToHighlight`](https://www.meilisearch.com/docs/reference/api/search#attributes-to-highlight),
[`highlightPreTag`, `highlightPostTag`](https://www.meilisearch.com/docs/reference/api/search#highlight-tags),
[`showMatchesPosition`](https://www.meilisearch.com/docs/reference/api/search#show-matches-position),
[`matchingStrategy`](https://www.meilisearch.com/docs/reference/api/search#matching-strategy),
[`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)
- [`attributesToCrop`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#attributes-to-crop)
- [`attributesToHighlight`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#attributes-to-highlight)
- [`attributesToRetrieve`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#attributes-to-retrieve)
- [`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#customize-attributes-to-search-on-at-search-time)
- [`cropLength`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#crop-length)
- [`cropMarker`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#crop-marker)
- [`distinct`](https://www.meilisearch.com/docs/learn/relevancy/distinct_attribute)
- [`highlightPreTag`, `highlightPostTag`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#highlight-tags)
- [`hybrid`](https://www.meilisearch.com/docs/learn/experimental/vector_search)
- [`matchingStrategy`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#matching-strategy)
- [`showMatchesPosition`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#show-matches-position)
- [`showRankingScore`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#ranking-score)
- [`rankingScoreThreshold`](https://www.meilisearch.com/docs/reference/api/search?utm_campaign=oss&utm_source=github&utm_medium=instant-meilisearch#ranking-score-threshold)

```js
instantMeiliSearch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ describe('Parameters adapter', () => {
expect(searchParams.hybrid).toBe(hybridSearchConfig)
})

test('ranking score threshold can be set via search parameters', () => {
const rankingScoreThreshold = 0.974

const searchParams = adaptSearchParams({
...DEFAULT_CONTEXT,
meiliSearchParams: {
rankingScoreThreshold,
},
})

expect(searchParams.rankingScoreThreshold).toBe(rankingScoreThreshold)
})

test('distinct search configuration can be set via search parameters', () => {
const distinctSearchConfig = 'title'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
meiliSearchParams.distinct = value
}
},
addRankingScoreThreshold() {
const value = overrideParams?.rankingScoreThreshold
if (value !== undefined) {
meiliSearchParams.rankingScoreThreshold = value
}
},
}
}

Expand Down Expand Up @@ -277,6 +283,7 @@ export function adaptSearchParams(
meilisearchParams.addAttributesToSearchOn()
meilisearchParams.addHybridSearch()
meilisearchParams.addDistinct()
meilisearchParams.addRankingScoreThreshold()

return meilisearchParams.getParams()
}
11 changes: 6 additions & 5 deletions packages/instant-meilisearch/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,20 @@ export type InstantSearchParams = NonNullable<

export type OverridableMeiliSearchSearchParameters = Pick<
MeiliSearchMultiSearchParams,
| 'attributesToRetrieve'
| 'attributesToCrop'
| 'attributesToRetrieve'
| 'attributesToSearchOn'
| 'cropLength'
| 'cropMarker'
| 'attributesToHighlight'
| 'distinct'
| 'highlightPreTag'
| 'highlightPostTag'
| 'showMatchesPosition'
| 'hybrid'
| 'matchingStrategy'
| 'rankingScoreThreshold'
| 'showMatchesPosition'
| 'showRankingScore'
| 'attributesToSearchOn'
| 'hybrid'
| 'distinct'
>

type BaseInstantMeiliSearchOptions = {
Expand Down

0 comments on commit 72a0346

Please sign in to comment.