Example usage for org.apache.lucene.search FieldValueHitQueue create

List of usage examples for org.apache.lucene.search FieldValueHitQueue create

Introduction

In this page you can find the example usage for org.apache.lucene.search FieldValueHitQueue create.

Prototype

public static <T extends FieldValueHitQueue.Entry> FieldValueHitQueue<T> create(SortField[] fields, int size) 

Source Link

Document

Creates a hit queue sorted by the given list of fields.

Usage

From source file:com.tuplejump.stargate.cassandra.IndexEntryCollector.java

License:Apache License

public IndexEntryCollector(org.apache.lucene.search.SortField[] sortFields, int maxResults) throws IOException {
    if (sortFields == null) {
        hitQueue = FieldValueHitQueue.create(
                new org.apache.lucene.search.SortField[] { org.apache.lucene.search.SortField.FIELD_SCORE },
                maxResults);/*from   w w  w. jav a 2s.  c  o  m*/
    } else {
        hitQueue = FieldValueHitQueue.create(sortFields, maxResults);
    }
    comparators = hitQueue.getComparators();
    numHits = maxResults;
    reverseMul = hitQueue.getReverseMul();

}

From source file:com.tuplejump.stargate.lucene.IndexEntryCollector.java

License:Apache License

public IndexEntryCollector(Function function, Search search, Options options, int maxResults)
        throws IOException {
    this.options = options;
    org.apache.lucene.search.SortField[] sortFields = search.usesSorting() ? search.sort(options) : null;
    if (sortFields == null) {
        hitQueue = FieldValueHitQueue.create(
                new org.apache.lucene.search.SortField[] { org.apache.lucene.search.SortField.FIELD_SCORE },
                maxResults);//from w w  w.j  a v a  2 s.  co  m
    } else {
        hitQueue = FieldValueHitQueue.create(sortFields, maxResults);
    }
    comparators = hitQueue.getComparators();
    numHits = maxResults;
    reverseMul = hitQueue.getReverseMul();
    numericDocValueNamesToFetch = new ArrayList<>();
    binaryDocValueNamesToFetch = new ArrayList<>();
    if (function instanceof AggregateFunction) {
        AggregateFunction aggregateFunction = (AggregateFunction) function;
        List<String> groupByFields = aggregateFunction.getGroupByFields();
        List<String> aggregateFields = aggregateFunction.getAggregateFields();
        boolean abort = false;
        FieldType[] groupDocValueTypes = null;
        if (groupByFields != null) {
            groupDocValueTypes = new FieldType[groupByFields.size()];
            for (int i = 0; i < groupByFields.size(); i++) {
                String field = groupByFields.get(i).toLowerCase();
                FieldType docValType = getDocValueType(options, field);
                if (docValType == null) {
                    abort = true;
                    break;
                }
                groupDocValueTypes[i] = docValType;
            }
        }
        FieldType[] aggDocValueTypes = new FieldType[aggregateFields.size()];
        if (!abort) {
            for (int i = 0; i < aggregateFields.size(); i++) {
                String field = aggregateFields.get(i);
                FieldType docValType = getDocValueType(options, field);
                if (docValType == null) {
                    abort = true;
                    break;
                }
                aggDocValueTypes[i] = docValType;
            }
        }
        canByPassRowFetch = !abort;
        if (canByPassRowFetch) {
            if (groupByFields != null)
                addToFetch(groupByFields.iterator(), groupDocValueTypes);
            addToFetch(aggregateFields.iterator(), aggDocValueTypes);
        }
    }
}