-
Notifications
You must be signed in to change notification settings - Fork 90
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 rankingScore and rankingScoreDetails types #1537
Changes from all commits
e1d336c
e1bc4db
f7ee249
a2ca298
34e65cc
52e0e1f
a8b4966
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,51 @@ describe.each([ | |
expect(hit.id).toEqual(1) | ||
}) | ||
|
||
test(`${permission} key: search with _showRankingScore enabled`, async () => { | ||
const client = await getClient(permission) | ||
|
||
const response = await client.index(index.uid).search('prince', { | ||
showRankingScore: true, | ||
}) | ||
|
||
const hit = response.hits[0] | ||
|
||
expect(response).toHaveProperty('hits', expect.any(Array)) | ||
expect(response).toHaveProperty('query', 'prince') | ||
expect(hit).toHaveProperty('_rankingScore') | ||
}) | ||
|
||
test(`${permission} key: search with showRankingScoreDetails enabled`, async () => { | ||
const client = await getClient(permission) | ||
const key = await getKey(permission) | ||
|
||
await fetch(`${HOST}/experimental-features`, { | ||
body: JSON.stringify({ scoreDetails: true }), | ||
headers: { | ||
Authorization: `Bearer ${key}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
method: 'PATCH', | ||
}) | ||
|
||
const response = await client.index(index.uid).search('prince', { | ||
showRankingScoreDetails: true, | ||
}) | ||
|
||
const hit = response.hits[0] | ||
|
||
expect(response).toHaveProperty('hits', expect.any(Array)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion is not valid since you'll have a broken code anyway. In the line before you ensure you're taking the first item from an array :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not asserting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hits will always be an array, that's my point. Otherwise you'll have an exception! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your assertion, you're telling that you expect the hits key to be an array. And that will never fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, it's a test that tests Meilisearch not my SDK haha. It's a copy paste from other tests I can remove it |
||
expect(response).toHaveProperty('query', 'prince') | ||
expect(hit).toHaveProperty('_rankingScoreDetails') | ||
expect(Object.keys(hit._rankingScoreDetails || {})).toEqual([ | ||
'words', | ||
'typo', | ||
'proximity', | ||
'attribute', | ||
'exactness', | ||
]) | ||
}) | ||
|
||
test(`${permission} key: search with array options`, async () => { | ||
const client = await getClient(permission) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to add comments to these types, to make them highlight the IDEs of people using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I realised I forgot to use
RankingScoreDetails
hehe. But to answer your question this is how IDe works w/ typescript types.By clicking on
go to type definition
you'll be redirection to theRankingScoreDetails
type.Now, I can add a comment like this:
Which would appear like that if I hover over the type (see last line of second screen):