sortingsolrlucenesolr-query-syntax

How to nested sort in solr query?


Assume I have field and value like

Field : value
sku : xxx
Seller : true
Name : "Elux"

query will be like

sku:"xxx"

within this result I need to sort the products with Name (Elux) in the top with seller (true) top and within that I need the products name should be sorted in alphabetical order same goes for seller (false) and Name other than Elux in the bottom. Is this possible with solr?


Solution

  • You can use the same strategy as shown in this answer by Alexandre, but you'll have to adapt it to your need. Something like:

    &sort=query(Name:Elux, 0) desc, query(seller:true, 0) desc, Name asc
    

    .. should work. Not sure about the performance from those two query calls, though.

    Update:

    You'll have to use placeholders as Alexandre describes in his answer:

    sort=query($manu_sort,0) desc, query($seller_sort,0) desc, ManufacturerName asc
    &manu_sort=ManufacturerName:Champ
    &seller_sort=BestSeller:true