solrsolrjsolrcloudsolr4solr-query-syntax

Sort Based on the top 100 records Solr


This is not same as the below:

How to sort the top 100 results of solr query based on a specific filed?

Suppose my search criteria title:Building the Nation returns 100k results. I guess Solr already returns data based on the best match i.e best match data will in the top. I am sorting based on some thing. In this case the record at the last position may come at the top.

https://host/solr/booksCore/select?q=(title:"Building the Nation" OR title:Building the Nation OR author:"Building the Nation" OR author:Building the Nation) AND subjects:*&rows=100&sort=sales_a desc&wt=json

So I want to do search at first, then take the 1st 100 records and then sort. How can I do that using Solr select API?


Solution

  • First - the queries you're writing does not do what you probably intend them to do. author:Building the Nation searches for Building in the author field, and the and Nation in the default search field. You probably want author:the author:Nation in that case, or use qf with the edismax query parser (and use ps and pf to boost phrases).

    Second, if subjects:* are meant to match any document that has a subject, that syntax would be subjects:[* TO *].

    Then third, to re-rank the top N results in a query, you can use rq - a re-rank query. The result of this query will be a new set of scores, which you can boost using the reRankWeight parameter:

    In the example below, the top 1000 documents matching the query "greetings" will be re-ranked using the query "(hi hello hey hiya)". The resulting scores for each of those 1000 documents will be 3 times their score from the "(hi hello hey hiya)", plus the score from the original "greetings" query:

    q=greetings&rq={!rerank reRankQuery=$rqq reRankDocs=1000 reRankWeight=3}&rqq=(hi+hello+hey+hiya)
    

    You can use _val_ to directly assign a numerical value as the score of the document, effectively reverse sorting by that value.