Assume we have an online shop.
- The products table contains a
ReleaseDateandIsPublishedvalue. - The orders table contains a
CreatedDateandOrderItems(containingProductIdandCount) - The discounts table contains a
ProductIdand 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?