Order results by number of facets matched

I have products with tags array. How do I rank the results of products with most number of facets matching first then the rest after that?

I have added tags.tagName as my facet.

Example of Product:

objectID : "5398"
name : "Blue Dinosaur Banana *Bread* Paleo Bar"
lowestPrice: 5.99
tags : [
{ tagTypeName: "Special Diets", tagName: "Vegetarian", description: "Vegetarian", tagId: "96", systemTag: true },
{ tagTypeName: "Special Diets", tagName: "Vegan", description: "Vegan", tagId: "87", systemTag: true },
{ tagTypeName: "Allergies", tagName: "Dairy-Free", description: "Dairy-Free", tagId: "262", systemTag: true },
{ tagTypeName: "Nutrition/Marketing Claims", tagName: "Refined Sugar-Free", description: "Refined Sugar-Free", tagId: "260", systemTag: false },
{ tagTypeName: "Intolerances", tagName: "Gluten Free", description: "Gluten Free", tagId: "86", systemTag: true }
]
typeName : "Product"
4 Likes

+1 on this. Have an array of meta-tags for every entry.

{
  objectID: 1
  classifications: ['metaTag1', "metaTag2', 'metaTag3']
},
{
  objectID: 2
  classifications: ['metaTag1', "metaTag4', 'metaTag5']
},

During api-search we pass in an array of these meta-tags and use algolia to return the items matching at least one of these.

indexSearch('', {
  facetFilters: [
     classifications: ['metaTag1', 'metaTag2', 'metaTag3'] 
  ]
})

This search should (and currently does) return both the objects 1 and 2, but Iā€™m looking for a way to rank the Object 1 higher since the query matches all the classifications.

Looking for a way to rank the response, so that the first item is the one with the highest number of matches on the classification-tag.

3 Likes