Relevance sorting for shop products in RavenDB

Viewed 36

Assume we have an online shop.

  1. The products table contains a ReleaseDate and IsPublished value.
  2. The orders table contains a CreatedDate and OrderItems (containing ProductId and Count)
  3. The discounts table contains a ProductId and eventually a more complex product query as well as the discount itself.

My goal is to create a product listing with facets for product properties and relevance sorting. Facets in RavenDB are awesome, no problem here. My problem is the sorting.

The idea is the following: Products are sorted by multiple criteria (release date, sold units and is on sale). The product gets 0 to 100 points for each criteria. 0 points for the minimum value and 100 points for the maximum value. Each criteria has a weight. Eventually for release date that's 50% weight, for sold units 20%, and on sale 30%.

That results in the following formula (pseudo code):

product.relevance = 
(50 * (product.releaseDate - minReleaseDate) / (maxReleaseDate - minReleaseDate)) +
(20 * (product.soldUnits - minSoldUnits) / (maxSoldUnits - minSoldUnits)) +
(30 * (product.isOnSale ? 1 : 0))

I do already have an index which contains the products with their release dates and soldUnits. Discounts are still a problem but not part of this question. I do also have access to the min/max values for my criteria via facets (minOn/maxOn).


My question:

What is the best option to solve this problem? I have thought about creating a JavaScript index, which contains a function ("The Script") for the relevance calculation. But how do I get the min/max values within the index? I will probably need one index for the values (release date, sold units) and another one for the relevance, right? I guess that would make it harder to query the data. I have also found custom collectors for Lucene, which is probably the functionality I need? Yet I couldn't find anything related in RavenDB (currently using v5.1).

Is the way I am trying to solve this problem too complex?

0 Answers
Related