Hi there!
What you’re describing is indeed the normal behavior. The engine doesn’t check which record matches a filter on the most points, but just if it matches or not. After that, your custom ranking kicks in to determine the order of the records. This is most likely what causes record 2 to show up before record 1.
That being said, it is possible to achieve the behavior you want. You can do this by leveraging optionalFilters
. optionalFilters
boost records that match the filters in it, without removing records that don’t match it. This, combined with the facetFilters
you already have, allows you to boost results that match both filters. This would look something like this:
const results = await index.search(query, {
facetFilters: ['type:lunch', 'type:dinner'],
optionalFilters: [
['type:lunch', 'type:dinner']
],
});
The code above will filter all your results (as you currently have), and the optionalFilters
will promote all the items that have type:lunch
and type:dinner
in their attributes. Doing this will cause result 1 to show up before result 2.
I hope this helps, let me know if you have any other questions!