Skip to content

Commit

Permalink
Add rankingScoreThreshold in search
Browse files Browse the repository at this point in the history
  • Loading branch information
the-sinner committed Jun 8, 2024
1 parent dd8272c commit 9990377
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 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,8 @@ 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',
};

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

0 comments on commit 9990377

Please sign in to comment.