Search in sources :

Example 1 with OrderByCollectorExpression

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

the class ScoreDocRowFunction method apply.

@Nullable
@Override
public Row apply(@Nullable ScoreDoc input) {
    if (input == null) {
        return null;
    }
    FieldDoc fieldDoc = (FieldDoc) input;
    scorer.score(fieldDoc.score);
    for (OrderByCollectorExpression orderByCollectorExpression : orderByCollectorExpressions) {
        orderByCollectorExpression.setNextFieldDoc(fieldDoc);
    }
    List<LeafReaderContext> leaves = indexReader.leaves();
    int readerIndex = ReaderUtil.subIndex(fieldDoc.doc, leaves);
    LeafReaderContext subReaderContext = leaves.get(readerIndex);
    int subDoc = fieldDoc.doc - subReaderContext.docBase;
    for (LuceneCollectorExpression<?> expression : expressions) {
        try {
            expression.setNextReader(subReaderContext);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }
        expression.setNextDocId(subDoc);
    }
    return inputRow;
}
Also used : FieldDoc(org.apache.lucene.search.FieldDoc) OrderByCollectorExpression(io.crate.operation.reference.doc.lucene.OrderByCollectorExpression) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 2 with OrderByCollectorExpression

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

the class DocInputFactory method extractImplementations.

public InputFactory.Context<? extends LuceneCollectorExpression<?>> extractImplementations(RoutedCollectPhase phase) {
    OrderBy orderBy = phase.orderBy();
    ReferenceResolver<? extends LuceneCollectorExpression<?>> refResolver;
    if (orderBy == null) {
        refResolver = referenceResolver;
    } else {
        refResolver = ref -> {
            if (orderBy.orderBySymbols().contains(ref)) {
                return new OrderByCollectorExpression(ref, orderBy);
            }
            return referenceResolver.getImplementation(ref);
        };
    }
    InputFactory.Context<? extends LuceneCollectorExpression<?>> ctx = inputFactory.ctxForRefs(refResolver);
    ctx.add(phase.toCollect());
    return ctx;
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) OrderByCollectorExpression(io.crate.operation.reference.doc.lucene.OrderByCollectorExpression)

Example 3 with OrderByCollectorExpression

use of io.crate.operation.reference.doc.lucene.OrderByCollectorExpression 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)

Aggregations

OrderByCollectorExpression (io.crate.operation.reference.doc.lucene.OrderByCollectorExpression)3 OrderBy (io.crate.analyze.OrderBy)1 InputFactory (io.crate.operation.InputFactory)1 CollectorContext (io.crate.operation.reference.doc.lucene.CollectorContext)1 LuceneCollectorExpression (io.crate.operation.reference.doc.lucene.LuceneCollectorExpression)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 FieldDoc (org.apache.lucene.search.FieldDoc)1 IndexFieldDataService (org.elasticsearch.index.fielddata.IndexFieldDataService)1 ShardId (org.elasticsearch.index.shard.ShardId)1