Skip to content

Commit

Permalink
feat: add rankingScoreThreshold to searchGet (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdubus authored Jun 18, 2024
1 parent 5f4d297 commit f3bb65b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export type SearchParams = Query &
vector?: number[] | null;
showRankingScore?: boolean;
showRankingScoreDetails?: boolean;
rankingScoreThreshold?: number;
attributesToSearchOn?: string[] | null;
hybrid?: HybridSearch;
rankingScoreThreshold?: number;
};

// Search parameters for searches made with the GET method
Expand All @@ -147,6 +147,7 @@ export type SearchRequestGET = Pagination &
attributesToSearchOn?: string | null;
hybridEmbedder?: string;
hybridSemanticRatio?: number;
rankingScoreThreshold?: number;
};

export type MultiSearchQuery = SearchParams & { indexUid: string };
Expand Down
25 changes: 24 additions & 1 deletion tests/get_search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,34 @@ describe.each([

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

expect(response).not.toHaveProperty('semanticHitCount');
});

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

const response = await client.index(index.uid).searchGet('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: Try to search on deleted index and fail`, async () => {
const client = await getClient(permission);
const masterClient = await getClient('Master');
Expand Down

0 comments on commit f3bb65b

Please sign in to comment.