Search code examples
sortingsolrsolr-query-syntax

Understanding Sort on query in solr


I am new to solr and trying to understand a solr sort criteria that goes like this -

bQ01=2859969
bQ02={!term f=prdId v=$bQ01}
bQ03={!lucene} {!v=$bQ02}^=6

buryClearanceQuery={!parent which=$pq score=min v=$matchAllQueryRef2}
matchAllQueryRef2= ({!query v=$cq})  ({!simpleFilter v=$priceTypeClearance})
priceTypeClearance={!term f=priceType_refine v=$matchAllQueryRef3} 
matchAllQueryRef3=Clearance
cq= {!simpleFilter v=docType:pdf}   {!docValues v='shelf_873:1'}
sort=query($bQ03,0) desc, query($buryClearanceQuery) asc

I am facing issues understanding how the sort criteria is made above and how will query(some_expression, 0) desc will work.

Any help is greatly appreciated.


Solution

  • The parameters to the sort clause get there via parameter passing. So, basically in the Solr query you could reference it via $ sign.

    Simpler example from the Solr documentation

    q={!type=dismax qf=myfield v=$qq}&qq=solr rocks
    

    Similar stuff is happening in your query and in sort clause particularly. Sorting by query is working as following:

    Solr can sort query responses according to document scores or the value of any field with a single value

    than in the sort clause you could specify the field by which you're sorting, or the query (it could be either normal query or function query) - which produce single "pseudo" field (score)