i want to sort the top 100documents of a solr using a specific field but it sort the whole result set and then display result the following is my code.
query1.setQuery(" Natural Language ");
query1.setStart(0);
query1.setRows(100);
int i=0;
query1.set("df","Text");
query1.setFields("PaperID","TotalPageRank");
query1.setSort("customrank", SolrQuery.ORDER.desc);
Is it possible using solr query to sort the top 100 documents using customrank field?
It is very simple..
SolrQuery query1 = new SolrQuery();
CommonsHttpSolrServer server = new CommonsHttpSolrServer("Your server url");
server.getHttpClient().getParams();
query1.setQuery("Natural Language");
query1.setFields("PaperID", "TotalPageRank");
query1.setStart(0);
query1.setRows(100);
query1.setSort("customrank", SolrQuery.ORDER.desc);
QueryResponse solrresponse = server.query(query1);
SolrDocumentList results = solrresponse.getResults();
for (int i = 0; i < results.size(); ++i) {
String resultsolr = results.get(i).toString();
}
Note: The customrank field shoud be integer, better to have customrank_i
Hope this will help!! Happy coding :)
You can try to use the Query Re-Ranking feature. This allows you to issue one query, retrieve the top N entries and then re-rank these entries according to a second query. This is usually used to have one simple query limit the total number of documents before applying an expensive query to those entries for re-ranking, but the use case seems similar enough.
An adapted version of the example on the documentation page would probably be something like (I haven't been able to test this, so add a comment with adjustments for your use case):
rq={!rerank reRankQuery=$rqq reRankDocs=100 reRankWeight=3}&rqq=_val_=customrank
You might have to tune the rerankweight to get your customrank to contribute more to the final score, as I don't think you can sort explicitly