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

Add rankingScoreThreshold in search #1669

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export type SearchParams = Query &
showRankingScoreDetails?: boolean;
attributesToSearchOn?: string[] | null;
hybrid?: HybridSearch;
rankingScoreThreshold?: number;
};

// Search parameters for searches made with the GET method
Expand Down Expand Up @@ -1010,6 +1011,10 @@ export const ErrorStatusCode = {

/** @see https://www.meilisearch.com/docs/reference/errors/error_codes#invalid_facet_search_facet_query */
INVALID_FACET_SEARCH_FACET_QUERY: 'invalid_facet_search_facet_query',

INVALID_SEARCH_RANKING_SCORE_THRESHOLD:'invalid_search_ranking_score_threshold',
Copy link
Member

@curquiza curquiza Jun 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the error code invalid_search_ranking_score_threshold in types.ts. Is it fine ?

It's fine!

Shouldn't we also add invalid_similar_ranking_score_threshold based on the usage page (last section): https://meilisearch.notion.site/Filter-by-score-usage-224a183ce7b24ca99b6a9a8da755668a

curquiza marked this conversation as resolved.
Show resolved Hide resolved

INVALID_SIMILAR_RANKING_SCORE_THRESHOLD:'invalid_similar_ranking_score_threshold'
curquiza marked this conversation as resolved.
Show resolved Hide resolved
};

export type ErrorStatusCode =
Expand Down
23 changes: 23 additions & 0 deletions tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,29 @@ describe.each([
]);
});

test(`${permission} key: search with rankingScoreThreshold filter`, async () => {
const client = await getClient(permission);

const response = await client.index(index.uid).search('prince', {
showRankingScore: true,
rankingScoreThreshold: 0.8,
});

const hit = response.hits[0];

expect(response).toHaveProperty('hits', expect.any(Array));
expect(response).toHaveProperty('query', 'prince');
expect(hit).toHaveProperty('_rankingScore');
expect(hit['_rankingScore']).toBeGreaterThanOrEqual(0.8);

const response2 = await client.index(index.uid).search('prince', {
showRankingScore: true,
rankingScoreThreshold: 0.9,
});

expect(response2.hits.length).toBeLessThanOrEqual(0);
});

test(`${permission} key: search with array options`, async () => {
const client = await getClient(permission);

Expand Down
Loading