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

feat(instant-meilisearch): add ranking score threshold #1318

Merged
merged 4 commits into from
Aug 14, 2024
Merged
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
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": "yarn@1.22.22"
}
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
Loading