Example usage for org.apache.lucene.search SortField rewrite

List of usage examples for org.apache.lucene.search SortField rewrite

Introduction

In this page you can find the example usage for org.apache.lucene.search SortField rewrite.

Prototype

public SortField rewrite(IndexSearcher searcher) throws IOException 

Source Link

Document

Rewrites this SortField, returning a new SortField if a change is made.

Usage

From source file:org.apache.solr.handler.component.ShardFieldSortedHitQueue.java

License:Apache License

Comparator<ShardDoc> getCachedComparator(SortField sortField, IndexSearcher searcher) {
    SortField.Type type = sortField.getType();
    if (type == SortField.Type.SCORE) {
        return (o1, o2) -> {
            final float f1 = o1.score;
            final float f2 = o2.score;
            if (f1 < f2)
                return -1;
            if (f1 > f2)
                return 1;
            return 0;
        };//www  . ja v  a 2s.c o  m
    } else if (type == SortField.Type.REWRITEABLE) {
        try {
            sortField = sortField.rewrite(searcher);
        } catch (IOException e) {
            throw new SolrException(SERVER_ERROR, "Exception rewriting sort field " + sortField, e);
        }
    }
    return comparatorFieldComparator(sortField);
}

From source file:org.apache.solr.search.federated.ShardFieldSortedHitQueue.java

License:Apache License

Comparator<ShardDoc> getCachedComparator(SortField sortField, IndexSearcher searcher) {
    SortField.Type type = sortField.getType();
    if (type == SortField.Type.SCORE) {
        return comparatorScore();
    } else if (type == SortField.Type.REWRITEABLE) {
        try {/*from ww  w  .ja v  a  2s.com*/
            sortField = sortField.rewrite(searcher);
        } catch (IOException e) {
            throw new SolrException(SERVER_ERROR, "Exception rewriting sort field " + sortField, e);
        }
    }
    return comparatorFieldComparator(sortField);
}