I have a problem with figuring out how to formulate a solr query to dynamically elevate certain documents and applying a different sorting mechanism to the rest of the documents. To make it more clear consider following documents.
<doc>
<field name="docId">1</field>
<field name="sales">33</field>
<field name="price">10</field>
</doc>
<doc>
<field name="docId">2</field>
<field name="sales">44</field>
<field name="price">20</field>
</doc>
<doc>
<field name="docId">3</field>
<field name="sales">55</field>
<field name="price">30</field>
</doc>
<doc>
<field name="docId">4</field>
<field name="sales">22</field>
<field name="price">50</field>
</doc>
<doc>
<field name="docId">5</field>
<field name="sales">11</field>
<field name="price">5</field>
</doc>
<doc>
<field name="docId">6</field>
<field name="sales">1</field>
<field name="price">4</field>
</doc>
My goal is to select one product with the best sales and display it as the first product. Then select a product with the lowest price and display it as second and finally sort the rest of the documents by price ascending, so my final result would look like that:
<doc>
<field name="docId">3</field><!-- Product with the highest amount of sales -->
</doc>
<doc>
<field name="docId">6</field><!-- Product with the lowest price -->
</doc>
<!-- The rest sorted by price asc -->
<doc>
<field name="docId">5</field>
</doc>
<doc>
<field name="docId">4</field>
</doc>
<doc>
<field name="docId">1</field>
</doc>
<doc>
<field name="docId">2</field>
</doc>
At the beggining I was considering using QueryElevation component, but it only supports static data and I need to be able to for example change the price range and apply the same sorting logic.
I started looking at the solr function query and particularly "max(sales,0) desc" would solve my problem, but I cannot find a way to limit results in sorting and merge them together.
Maybe I am trying to achieve something that is not possible with just one query at all, but before I decide to give up, I wanted to ask, if you guys have an idea, how to solve this one?
I have also found this answer but it does not go into details about the solution.
Thanks in advance!