Gravatar for rallan@getfishtank.ca

Question by Ryan, Oct 13, 2016 1:01 AM

How to add a random number to ranking weights

I need to add a random number to the ranking weights for each item in a search.

Something like $qre: expression: 'rand(0-600)'

The ExprTk doesn't seem to have a random function, it looks like it depends on the code it is used with.

Did I miss something, or is there another method to do this?

Thanks

1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Oct 13, 2016 3:44 AM

I must admit, it's the first time I see someone requesting for the result ordering to have a random factor. Out of sheer curiosity, what is the use case?

As for a solution, you can inject those $qre expressions in JS when building the query; I'd generate one with a random number there and send it over to the server. Indeed we don't provide any server-side way to introduce randomness, but it wouldn't be hard to do. It's just that we haven't any use case for it… unless you can provide us with a perfect one :)

Gravatar for partow@gmail.com

Comment by arash, Oct 13, 2016 5:06 AM

How about adding something like this to Coveo:

https://github.com/ArashPartow/exprtk/blob/master/exprtksimpleexample_17.cpp#L27

At that point users can make use of random number generator facilities within their expressions.

For example the above expression can now be: "rnd_01 * 600"

Furthermore, perhaps the ExprTk RTL packages could be enabled to provide even more functionality:

https://github.com/ArashPartow/exprtk/blob/master/readme.txt#L2671

Gravatar for dan@getfishtank.ca

Comment by Dan Cruickshank, Oct 13, 2016 12:31 PM

Hey Martin! So this is the use-case. It's ultimately my idea, so it's best not to punish Ryan by forcing him to explain it.

Say we have a collection of 200 assets (in Sitecore in this case) that were all authored at a similar time. They're tagged with locations, personas and other information that make them relevant to specific users. There is too much data with too many rules to target the content manually for authors. So we offload this relevance to Coveo. This actually builds on top of the Coveo presentation I did at the Sitecore Symposium. :)

So say we have 5 pieces of content tagged as is in "Calgary", has a "Business" persona and is tied to the campaign. User always see the most relevant asset by location, persona & campaign. Because the content isn't changing so the most relevant item they're seeing isn't changing. So they'll only ever see the 1st of the 5. Which isn't what we want, we'd like them to get a distribution of the 5 as the top result because they're all relevant - probably nearly with identical document scores.

If we could introduce some random weighting across the document score, that would allow different results to appears as the first where they're statistically tied. I've some ideas for broader implications of this functionality as well. :D

Shoot me an email if need be!

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Oct 14, 2016 4:19 AM

I wasn't intending this as a punition :p I just wanted to understand the use case.

Funny thing is that we discussed this on Slack and one of our younger devs said "Hey! I could have used that in our last hackathon!". So Dan (who works on the index) will have a look at this.

Ask a question