Example usage for org.apache.solr.handler.component ResponseBuilder getSortSpec

List of usage examples for org.apache.solr.handler.component ResponseBuilder getSortSpec

Introduction

In this page you can find the example usage for org.apache.solr.handler.component ResponseBuilder getSortSpec.

Prototype

public SortSpec getSortSpec() 

Source Link

Usage

From source file:com.sn.solr.plugin.rank.RankEngine.java

License:Apache License

/**
 * Provides implementation for Dense ranking ["1223"] as identified by the
 * {@link RankStrategy#LEGACY_DENSE} the difference is that this
 * implementation is computed without using facet results so this will 
 * noticeably slower than computing rank based on facets
 * use {@link RankStrategy#DENSE}. Besides this implementation might cause 
 * lot of cache evictions putting stress on memory. 
 *
 * @see #computeDenseRank(List)/*w  w w.  j a  v  a2  s  . c  o m*/
 * 
 * @param pairList List of {@link Pair} objects that holds the value of rank 
 * field & respective count.
 */
@Deprecated
public static Map<String, Number> computeLegacyDenseRank(ResponseBuilder rb, String idField, String rankField)
        throws IOException {
    SolrIndexSearcher searcher = rb.req.getSearcher();
    SolrParams params = rb.req.getParams();// .getParams(FacetParams.FACET_FIELD);

    String _start = params.get(CommonParams.START);
    String _rows = params.get(CommonParams.ROWS);
    int start = 0;
    int rows = 10;

    if (_start != null & AppHelper.isInteger(_start))
        start = new Integer(_start);
    if (_rows != null & AppHelper.isInteger(_rows))
        rows = new Integer(_rows);

    LOG.info("Computing rank using strategy: {}", RankStrategy.ORDINAL.getDescription());
    FieldSelector fs = new MapFieldSelector(new String[] { idField, rankField });
    Map<String, Number> rankMap = new HashMap<String, Number>();
    DocList docs = searcher.getDocList(rb.getQuery(), rb.getFilters(), rb.getSortSpec().getSort(), 0,
            start + rows, 0);
    int denseRank = 1;
    int _CurrScore = 0;
    int _PrevScore = 0;
    int i = 0;
    for (DocIterator it = docs.iterator(); it.hasNext();) {
        Document doc = searcher.doc(it.nextDoc(), fs);
        _CurrScore = new Integer(doc.get(rankField));
        if (i == 0) {
            _PrevScore = _CurrScore;
        }
        if (_PrevScore != _CurrScore) {
            _PrevScore = _CurrScore;
            denseRank++;
        }
        if (i >= start) {
            rankMap.put(doc.get(idField), denseRank);
        }
        i++;
    }

    return rankMap;
}