Search code examples
sortingsolrsolr4

(Fair) random Solr results sorting (grouped by category)


We've got a client who has requested that the results in their search page be returned in an equitable and fair way. Essentially, their products which are returned are "holiday packages". Each product is listed by a different vendor, and because the marketplace's shareholders are the vendors, they absolutely cannot show any preference to any particular vendor. (ie. Everyone needs to have the same exposure regardless of the merit of their actual inventory/products)

What we have been doing is just randomising, but the problem with true random is that a vendor with 100 packages, on a search results page with 12 other vendors who have 1 package each, just do not show. In the worst case, we have a vendor who has about 7000 packages, whereas other vendors in this category only have 1 or 2 products. So a true random means that the other vendors are totally swamped. The way we overcame this was to boost all other vendors, but then this vendor with 7000 packages doesn't show until all other products have been marketed.

So in summary, what we're trying to achieve is a fair, equitable sorting so that at least ONE product from each vendor is returned first before other products from other vendors are returned. Once other products have been returned, then it's all fair game...


Solution

  • there is something in Lucene to deal with something very similar: "show at most X docs from each key in this field", the DiversifiedTopDocsCollector. It seems you want "show at least X docs from each key in this field".

    I guess if the existing collector is not good enough you could modify it to achieve what you need. The problem is, the code needed to surface this collector in Solr has not been put in place yet...so you would need to do that as well.

    The other alternative, as already mentioned, is trying to get this done with Collapse/Grouping.