Skip to content

Apache Lucene open-source search software

LUCENE-6746: DisjunctionMaxQuery, BoostingQuery and BoostedQuery now create sub weights through IndexSearcher.

Adrien Grandc196056b3373
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 245429afb40..00ed921d8f2 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -80,6 +80,9 @@ Optimizations
* LUCENE-6756: MatchAllDocsQuery now has a dedicated BulkScorer for better
performance when used as a top-level query. (Adrien Grand)
+* LUCENE-6746: DisjunctionMaxQuery, BoostingQuery and BoostedQuery now create
+ sub weights through IndexSearcher so that they can be cached. (Adrien Grand)
+
Bug Fixes
* LUCENE-6730: Hyper-parameter c is ignored in term frequency NormalizationH1.
diff --git a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
index c9ec2bc0247..de096cabf50 100644
--- a/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
@@ -123,7 +123,7 @@ public class DisjunctionMaxQuery extends Query implements Iterable<Query> {
public DisjunctionMaxWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
super(DisjunctionMaxQuery.this);
for (Query disjunctQuery : disjuncts) {
- weights.add(disjunctQuery.createWeight(searcher, needsScores));
+ weights.add(searcher.createWeight(disjunctQuery, needsScores));
}
this.needsScores = needsScores;
}
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
index b482d60c488..9280dd9841a 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
@@ -59,8 +59,8 @@ public class BoostingQuery extends Query {
if (needsScores == false) {
return match.createWeight(searcher, needsScores);
}
- final Weight matchWeight = match.createWeight(searcher, needsScores);
- final Weight contextWeight = context.createWeight(searcher, false);
+ final Weight matchWeight = searcher.createWeight(match, needsScores);
+ final Weight contextWeight = searcher.createWeight(context, false);
return new Weight(this) {
@Override
diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
index e7469cd1a15..cf4fbf05017 100644
--- a/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/BoostedQuery.java
@@ -32,7 +32,6 @@ import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Weight;
-import org.apache.lucene.util.Bits;
import org.apache.lucene.util.ToStringUtils;
/**
@@ -74,7 +73,7 @@ public class BoostedQuery extends Query {
public BoostedWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
super(BoostedQuery.this);
this.searcher = searcher;
- this.qWeight = q.createWeight(searcher, needsScores);
+ this.qWeight = searcher.createWeight(q, needsScores);
this.fcontext = ValueSource.newContext(searcher);
boostVal.createWeight(fcontext,searcher);
}