Search in sources :

Example 1 with LuceneBatchIterator

use of io.crate.execution.engine.collect.collectors.LuceneBatchIterator in project crate by crate.

the class QueryTester method runQuery.

public List<Object> runQuery(String resultColumn, String expression, Object... params) throws Exception {
    Query query = toQuery(expression, params);
    LuceneBatchIterator batchIterator = getIterator.apply(ColumnIdent.fromPath(resultColumn), query);
    return BatchIterators.collect(batchIterator, Collectors.mapping(row -> row.get(0), Collectors.toList())).get(5, TimeUnit.SECONDS);
}
Also used : Query(org.apache.lucene.search.Query) LuceneBatchIterator(io.crate.execution.engine.collect.collectors.LuceneBatchIterator)

Example 2 with LuceneBatchIterator

use of io.crate.execution.engine.collect.collectors.LuceneBatchIterator in project crate by crate.

the class LuceneShardCollectorProvider method getUnorderedIterator.

@Override
protected BatchIterator<Row> getUnorderedIterator(RoutedCollectPhase collectPhase, boolean requiresScroll, CollectTask collectTask) {
    ShardId shardId = indexShard.shardId();
    SharedShardContext sharedShardContext = collectTask.sharedShardContexts().getOrCreateContext(shardId);
    var searcher = sharedShardContext.acquireSearcher("unordered-iterator: " + formatSource(collectPhase));
    collectTask.addSearcher(sharedShardContext.readerId(), searcher);
    IndexShard sharedShardContextShard = sharedShardContext.indexShard();
    // A closed shard has no mapper service and cannot be queried with lucene,
    // therefore skip it
    boolean isClosed = sharedShardContextShard.mapperService() == null;
    if (isClosed) {
        return InMemoryBatchIterator.empty(SentinelRow.SENTINEL);
    }
    QueryShardContext queryShardContext = sharedShardContext.indexService().newQueryShardContext();
    LuceneQueryBuilder.Context queryContext = luceneQueryBuilder.convert(collectPhase.where(), collectTask.txnCtx(), sharedShardContextShard.mapperService(), sharedShardContextShard.shardId().getIndexName(), queryShardContext, table, sharedShardContext.indexService().cache());
    InputFactory.Context<? extends LuceneCollectorExpression<?>> docCtx = docInputFactory.extractImplementations(collectTask.txnCtx(), collectPhase);
    return new LuceneBatchIterator(searcher.item(), queryContext.query(), queryContext.minScore(), Symbols.containsColumn(collectPhase.toCollect(), DocSysColumns.SCORE), new CollectorContext(sharedShardContext.readerId()), docCtx.topLevelInputs(), docCtx.expressions());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) InputFactory(io.crate.expression.InputFactory) IndexShard(org.elasticsearch.index.shard.IndexShard) LuceneQueryBuilder(io.crate.lucene.LuceneQueryBuilder) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) CollectorContext(io.crate.expression.reference.doc.lucene.CollectorContext) SharedShardContext(io.crate.execution.jobs.SharedShardContext) LuceneBatchIterator(io.crate.execution.engine.collect.collectors.LuceneBatchIterator)

Aggregations

LuceneBatchIterator (io.crate.execution.engine.collect.collectors.LuceneBatchIterator)2 SharedShardContext (io.crate.execution.jobs.SharedShardContext)1 InputFactory (io.crate.expression.InputFactory)1 CollectorContext (io.crate.expression.reference.doc.lucene.CollectorContext)1 LuceneQueryBuilder (io.crate.lucene.LuceneQueryBuilder)1 Query (org.apache.lucene.search.Query)1 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)1 IndexShard (org.elasticsearch.index.shard.IndexShard)1 ShardId (org.elasticsearch.index.shard.ShardId)1