Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public Factory(
taskConcurrency,
limit,
false,
ScoreMode.COMPLETE_NO_SCORES
shardContext -> ScoreMode.COMPLETE_NO_SCORES
);
this.shardRefCounters = contexts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public LuceneMaxFactory(
taskConcurrency,
limit,
false,
ScoreMode.COMPLETE_NO_SCORES
shardContext -> ScoreMode.COMPLETE_NO_SCORES
);
this.contexts = contexts;
this.fieldName = fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public LuceneMinFactory(
taskConcurrency,
limit,
false,
ScoreMode.COMPLETE_NO_SCORES
shardContext -> ScoreMode.COMPLETE_NO_SCORES
);
this.shardRefCounters = contexts;
this.fieldName = fieldName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ protected Factory(
int taskConcurrency,
int limit,
boolean needsScore,
ScoreMode scoreMode
Function<ShardContext, ScoreMode> scoreModeFunction
) {
this.limit = limit;
this.dataPartitioning = dataPartitioning;
this.sliceQueue = LuceneSliceQueue.create(contexts, queryFunction, dataPartitioning, autoStrategy, taskConcurrency, scoreMode);
this.sliceQueue = LuceneSliceQueue.create(
contexts,
queryFunction,
dataPartitioning,
autoStrategy,
taskConcurrency,
scoreModeFunction
);
this.taskConcurrency = Math.min(sliceQueue.totalSlices(), taskConcurrency);
this.needsScore = needsScore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ public static LuceneSliceQueue create(
DataPartitioning dataPartitioning,
Function<Query, PartitioningStrategy> autoStrategy,
int taskConcurrency,
ScoreMode scoreMode
Function<ShardContext, ScoreMode> scoreModeFunction
) {
List<LuceneSlice> slices = new ArrayList<>();
Map<String, PartitioningStrategy> partitioningStrategies = new HashMap<>(contexts.size());

for (ShardContext ctx : contexts) {
for (QueryAndTags queryAndExtra : queryFunction.apply(ctx)) {
var scoreMode = scoreModeFunction.apply(ctx);
Query query = queryAndExtra.query;
query = scoreMode.needsScores() ? query : new ConstantScoreQuery(query);
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Factory(
taskConcurrency,
limit,
needsScore,
needsScore ? COMPLETE : COMPLETE_NO_SCORES
shardContext -> needsScore ? COMPLETE : COMPLETE_NO_SCORES
);
this.contexts = contexts;
this.maxPageSize = maxPageSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.LeafCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocsCollector;
import org.apache.lucene.search.TopFieldCollectorManager;
import org.apache.lucene.search.TopScoreDocCollectorManager;
import org.apache.lucene.search.Weight;
import org.elasticsearch.common.Strings;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.DocBlock;
Expand All @@ -44,9 +43,6 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.apache.lucene.search.ScoreMode.TOP_DOCS;
import static org.apache.lucene.search.ScoreMode.TOP_DOCS_WITH_SCORES;

/**
* Source operator that builds Pages out of the output of a TopFieldCollector (aka TopN)
*/
Expand Down Expand Up @@ -75,7 +71,7 @@ public Factory(
taskConcurrency,
limit,
needsScore,
needsScore ? TOP_DOCS_WITH_SCORES : TOP_DOCS
scoreModeFunction(sorts, needsScore)
);
this.contexts = contexts;
this.maxPageSize = maxPageSize;
Expand Down Expand Up @@ -331,18 +327,11 @@ static final class ScoringPerShardCollector extends PerShardCollector {
}
}

private static Function<ShardContext, Weight> weightFunction(
Function<ShardContext, Query> queryFunction,
List<SortBuilder<?>> sorts,
boolean needsScore
) {
private static Function<ShardContext, ScoreMode> scoreModeFunction(List<SortBuilder<?>> sorts, boolean needsScore) {
return ctx -> {
final var query = queryFunction.apply(ctx);
final var searcher = ctx.searcher();
try {
// we create a collector with a limit of 1 to determine the appropriate score mode to use.
var scoreMode = newPerShardCollector(ctx, sorts, needsScore, 1).collector.scoreMode();
return searcher.createWeight(searcher.rewrite(query), scoreMode, 1);
return newPerShardCollector(ctx, sorts, needsScore, 1).collector.scoreMode();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private TimeSeriesSourceOperatorFactory(
taskConcurrency,
limit,
false,
ScoreMode.COMPLETE_NO_SCORES
shardContext -> ScoreMode.COMPLETE_NO_SCORES
);
this.contexts = contexts;
this.maxPageSize = maxPageSize;
Expand Down