Skip to content

Commit 5f4d297

Browse files
Add rankingScoreThreshold in search (#1669)
* Add rankingScoreThreshold in search * Update src/types/types.ts * Update src/types/types.ts * Apply suggestions from code review * Update src/types/types.ts --------- Co-authored-by: Clémentine <[email protected]>
1 parent 1d6507e commit 5f4d297

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/types/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export type SearchParams = Query &
127127
showRankingScoreDetails?: boolean;
128128
attributesToSearchOn?: string[] | null;
129129
hybrid?: HybridSearch;
130+
rankingScoreThreshold?: number;
130131
};
131132

132133
// Search parameters for searches made with the GET method
@@ -1011,6 +1012,14 @@ export const ErrorStatusCode = {
10111012

10121013
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_query */
10131014
INVALID_FACET_SEARCH_FACET_QUERY: 'invalid_facet_search_facet_query',
1015+
1016+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_search_ranking_score_threshold */
1017+
INVALID_SEARCH_RANKING_SCORE_THRESHOLD:
1018+
'invalid_search_ranking_score_threshold',
1019+
1020+
/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_similar_ranking_score_threshold */
1021+
INVALID_SIMILAR_RANKING_SCORE_THRESHOLD:
1022+
'invalid_similar_ranking_score_threshold',
10141023
};
10151024

10161025
export type ErrorStatusCode =

tests/search.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,29 @@ describe.each([
306306
]);
307307
});
308308

309+
test(`${permission} key: search with rankingScoreThreshold filter`, async () => {
310+
const client = await getClient(permission);
311+
312+
const response = await client.index(index.uid).search('prince', {
313+
showRankingScore: true,
314+
rankingScoreThreshold: 0.8,
315+
});
316+
317+
const hit = response.hits[0];
318+
319+
expect(response).toHaveProperty('hits', expect.any(Array));
320+
expect(response).toHaveProperty('query', 'prince');
321+
expect(hit).toHaveProperty('_rankingScore');
322+
expect(hit['_rankingScore']).toBeGreaterThanOrEqual(0.8);
323+
324+
const response2 = await client.index(index.uid).search('prince', {
325+
showRankingScore: true,
326+
rankingScoreThreshold: 0.9,
327+
});
328+
329+
expect(response2.hits.length).toBeLessThanOrEqual(0);
330+
});
331+
309332
test(`${permission} key: search with array options`, async () => {
310333
const client = await getClient(permission);
311334

0 commit comments

Comments
 (0)