Skip to content

Commit f3bb65b

Browse files
authored
feat: add rankingScoreThreshold to searchGet (#1673)
1 parent 5f4d297 commit f3bb65b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/types/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ export type SearchParams = Query &
125125
vector?: number[] | null;
126126
showRankingScore?: boolean;
127127
showRankingScoreDetails?: boolean;
128+
rankingScoreThreshold?: number;
128129
attributesToSearchOn?: string[] | null;
129130
hybrid?: HybridSearch;
130-
rankingScoreThreshold?: number;
131131
};
132132

133133
// Search parameters for searches made with the GET method
@@ -147,6 +147,7 @@ export type SearchRequestGET = Pagination &
147147
attributesToSearchOn?: string | null;
148148
hybridEmbedder?: string;
149149
hybridSemanticRatio?: number;
150+
rankingScoreThreshold?: number;
150151
};
151152

152153
export type MultiSearchQuery = SearchParams & { indexUid: string };

tests/get_search.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,34 @@ describe.each([
483483

484484
test(`${permission} key: search without vectors`, async () => {
485485
const client = await getClient(permission);
486-
const response = await client.index(index.uid).search('prince', {});
486+
const response = await client.index(index.uid).searchGet('prince', {});
487487

488488
expect(response).not.toHaveProperty('semanticHitCount');
489489
});
490490

491+
test(`${permission} key: search with rankingScoreThreshold filter`, async () => {
492+
const client = await getClient(permission);
493+
494+
const response = await client.index(index.uid).searchGet('prince', {
495+
showRankingScore: true,
496+
rankingScoreThreshold: 0.8,
497+
});
498+
499+
const hit = response.hits[0];
500+
501+
expect(response).toHaveProperty('hits', expect.any(Array));
502+
expect(response).toHaveProperty('query', 'prince');
503+
expect(hit).toHaveProperty('_rankingScore');
504+
expect(hit['_rankingScore']).toBeGreaterThanOrEqual(0.8);
505+
506+
const response2 = await client.index(index.uid).search('prince', {
507+
showRankingScore: true,
508+
rankingScoreThreshold: 0.9,
509+
});
510+
511+
expect(response2.hits.length).toBeLessThanOrEqual(0);
512+
});
513+
491514
test(`${permission} key: Try to search on deleted index and fail`, async () => {
492515
const client = await getClient(permission);
493516
const masterClient = await getClient('Master');

0 commit comments

Comments
 (0)