Search in sources :

Example 1 with LuceneCollectorExpression

use of io.crate.operation.reference.doc.lucene.LuceneCollectorExpression in project crate by crate.

the class OrderedLuceneBatchIteratorFactoryTest method createOrderedCollector.

private LuceneOrderedDocCollector createOrderedCollector(IndexSearcher searcher, int shardId) {
    CollectorContext collectorContext = new CollectorContext(mock(IndexFieldDataService.class), new CollectorFieldsVisitor(0));
    List<LuceneCollectorExpression<?>> expressions = Collections.singletonList(new OrderByCollectorExpression(reference, orderBy));
    return new LuceneOrderedDocCollector(new ShardId("dummy", shardId), searcher, new MatchAllDocsQuery(), null, false, // batchSize < 10 to have at least one searchMore call.
    5, fieldTypeLookup, collectorContext, orderBy, new Sort(new SortedNumericSortField(columnName, SortField.Type.LONG, reverseFlags[0])), expressions, expressions);
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) IndexFieldDataService(org.elasticsearch.index.fielddata.IndexFieldDataService) OrderByCollectorExpression(io.crate.operation.reference.doc.lucene.OrderByCollectorExpression) CollectorContext(io.crate.operation.reference.doc.lucene.CollectorContext) LuceneCollectorExpression(io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)

Example 2 with LuceneCollectorExpression

use of io.crate.operation.reference.doc.lucene.LuceneCollectorExpression in project crate by crate.

the class SortSymbolVisitor method customSortField.

private SortField customSortField(String name, final Symbol symbol, final SortSymbolContext context, final SortField.Type reducedType, final boolean missingNullValue) {
    InputFactory.Context<? extends LuceneCollectorExpression<?>> inputContext = docInputFactory.getCtx();
    final Input input = inputContext.add(symbol);
    final Collection<? extends LuceneCollectorExpression<?>> expressions = inputContext.expressions();
    return new SortField(name, new IndexFieldData.XFieldComparatorSource() {

        @Override
        public FieldComparator<?> newComparator(String fieldName, int numHits, int sortPos, boolean reversed) throws IOException {
            for (LuceneCollectorExpression collectorExpression : expressions) {
                collectorExpression.startCollect(context.context);
            }
            DataType dataType = symbol.valueType();
            Object missingValue = missingNullValue ? null : SortSymbolVisitor.missingObject(dataType, SortOrder.missing(context.reverseFlag, context.nullFirst), reversed);
            if (context.context.visitor().required()) {
                return new FieldsVisitorInputFieldComparator(numHits, context.context.visitor(), expressions, input, dataType, missingValue);
            } else {
                return new InputFieldComparator(numHits, expressions, input, dataType, missingValue);
            }
        }

        @Override
        public SortField.Type reducedType() {
            return reducedType;
        }
    }, context.reverseFlag);
}
Also used : DocInputFactory(io.crate.operation.collect.DocInputFactory) InputFactory(io.crate.operation.InputFactory) SortField(org.apache.lucene.search.SortField) IOException(java.io.IOException) Input(io.crate.data.Input) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) IndexFieldData(org.elasticsearch.index.fielddata.IndexFieldData) FieldComparator(org.apache.lucene.search.FieldComparator) LuceneCollectorExpression(io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)

Example 3 with LuceneCollectorExpression

use of io.crate.operation.reference.doc.lucene.LuceneCollectorExpression in project crate by crate.

the class LuceneBatchIterator method tryAdvanceDocIdSetIterator.

private boolean tryAdvanceDocIdSetIterator() throws IOException {
    if (currentDocIdSetIt != null) {
        return true;
    }
    while (leavesIt.hasNext()) {
        LeafReaderContext leaf = leavesIt.next();
        Scorer scorer = weight.scorer(leaf);
        if (scorer == null) {
            continue;
        }
        currentScorer = scorer;
        currentLeaf = leaf;
        currentDocIdSetIt = scorer.iterator();
        for (LuceneCollectorExpression expression : expressions) {
            expression.setScorer(currentScorer);
            expression.setNextReader(currentLeaf);
        }
        return true;
    }
    return false;
}
Also used : LeafReaderContext(org.apache.lucene.index.LeafReaderContext) LuceneCollectorExpression(io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)

Example 4 with LuceneCollectorExpression

use of io.crate.operation.reference.doc.lucene.LuceneCollectorExpression in project crate by crate.

the class LuceneBatchIterator method onDoc.

private void onDoc(int doc, LeafReader reader) throws IOException {
    checkCircuitBreaker();
    if (visitor.required()) {
        visitor.reset();
        reader.document(doc, visitor);
    }
    for (LuceneCollectorExpression expression : expressions) {
        expression.setNextDocId(doc);
    }
}
Also used : LuceneCollectorExpression(io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)

Example 5 with LuceneCollectorExpression

use of io.crate.operation.reference.doc.lucene.LuceneCollectorExpression in project crate by crate.

the class FetchCollector method setNextDocId.

private void setNextDocId(LeafReaderContext readerContext, int doc) throws IOException {
    if (visitorEnabled) {
        fieldsVisitor.reset();
        readerContext.reader().document(doc, fieldsVisitor);
    }
    for (LuceneCollectorExpression e : collectorExpressions) {
        e.setNextReader(readerContext);
        e.setNextDocId(doc);
    }
}
Also used : LuceneCollectorExpression(io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)

Aggregations

LuceneCollectorExpression (io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)5 Input (io.crate.data.Input)1 InputFactory (io.crate.operation.InputFactory)1 DocInputFactory (io.crate.operation.collect.DocInputFactory)1 CollectorContext (io.crate.operation.reference.doc.lucene.CollectorContext)1 OrderByCollectorExpression (io.crate.operation.reference.doc.lucene.OrderByCollectorExpression)1 IOException (java.io.IOException)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 FieldComparator (org.apache.lucene.search.FieldComparator)1 SortField (org.apache.lucene.search.SortField)1 IndexFieldData (org.elasticsearch.index.fielddata.IndexFieldData)1 IndexFieldDataService (org.elasticsearch.index.fielddata.IndexFieldDataService)1 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)1 ShardId (org.elasticsearch.index.shard.ShardId)1