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

爷,独闯天下 提交于 2019-12-25 01:25:44

问题


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?


回答1:


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 :)




回答2:


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



来源:https://stackoverflow.com/questions/47130637/how-to-sort-the-top-100-results-of-solr-query-based-on-a-specific-filed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!