Query Relevant Items For Multiple Values
I am currently working on creating a related-items component in Sitecore and I'm trying to figure out how I query a field that supports multiple values so that the items that have the most similar values are the most relevant. My sitecore Item contains a field called MetaData that is a Checklist and I've indexed MetaData as isMultiValue="true". What I'd like is if I'm showing a page that has the following MetaData items ("Value1", "Value2", "Value3") as it's metadata items, I'd like to return other items that have as many of those values selected first. So if I have Item2 with ("Value1", "Value2") and Item3 with ("Value3"), I'd like Item2 to be more relevant in my results. The problem is what I'm seeing is that if Item3 has been updated more recently, then my query returns that one first, even though it only matches on 1 of the MetaData values where as Item2 matches on 2 of them. Is there a way to make Item2 more relevant because it has more MetaData items in common? My query looks like this:
Thanks in advance, Nick
By default, when sorting by relevance, the Coveo index uses a lot of algorithms to give points to documents and rank them intelligently based on their properties and the terms used in the query. Such properties include the last modified date of the documents, their language etc… Query Ranking Override with
$weight() in your query allows you to change the weight of the algorithms used to rank the results. For this exact use case, I recommend you to set all the weights to 0 to disable them. You will end up with all the results having a score of 0 points.
Then, you should add QREs for each of the current item metadata. For your example, I would add the following:
$qre(expression:@metadata=="Value1", modifier:10) $qre(expression:@metadata=="Value2", modifier:10) $qre(expression:@metadata=="Value3", modifier:10)
This will give 10 points per matched metadata to the results. So the results matching all 3 metadatas will have 30 points and will be the first results in the result list.
You might also have to add your @metadata field in the ranking ignored fields list to tell the Coveo index not to use the "Value1", "Value2" and "Value3" terms for ranking and highlighting the search results.
I hope this helps.