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);
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations