If you want to explore how a result was ranked, you can get this information by setting the getRankingInfo property to true for each query. Here's an example:
index.search('query', {
getRankingInfo: true
}).then(({ hits }) => {
console.log(hits.map(hit => hit._rankingInfo));
});
Then from the response, the firstMatchedWord
(integer) will contain the searchable attribute that best matched the query for each record.
To determine which attribute within the list of searchableAttributes
was the best match, you need to divide the number by 1000:(int) (firstMatchedWord / 1000)
. For example, if firstMatchedWord=2001,(int) (2001/1000)=2
, the best matching attribute is the 3rd one in the list ofsearchableAttributes
(2 = position 3).