Gravatar for ncipollina@captechconsulting.com

Question by ncipollina, Jul 26, 2016 11:28 AM

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:

@field=("Value1","Value2","Value3").

Thanks in advance, Nick

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Jul 26, 2016 12:12 PM

Hi Nick,

That is a very good question and I would solve it using Query Ranking Override and Query Ranking Expressions (QRE).

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.

Jeff

Gravatar for ncipollina@captechconsulting.com

Comment by ncipollina, Jul 26, 2016 12:20 PM

jflheureux, that was exactly what I wanted/needed for this! Thank you!

Ask a question