You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sa...@apache.org on 2016/07/21 13:37:37 UTC
[15/51] [abbrv] lucene-solr:apiv2: LUCENE-7372: Factor out an
org.apache.lucene.search.FilterWeight class.
LUCENE-7372: Factor out an org.apache.lucene.search.FilterWeight class.
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/15e8719b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/15e8719b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/15e8719b
Branch: refs/heads/apiv2
Commit: 15e8719b8aa80b1e7e8deeba6bf8bec99f663ac8
Parents: 415d321
Author: Christine Poerschke <cp...@apache.org>
Authored: Wed Jul 13 16:04:24 2016 +0100
Committer: Christine Poerschke <cp...@apache.org>
Committed: Wed Jul 13 16:04:24 2016 +0100
----------------------------------------------------------------------
lucene/CHANGES.txt | 3 +
.../org/apache/lucene/search/FilterWeight.java | 73 ++++++++++++++++++++
.../apache/lucene/search/TestFilterWeight.java | 67 ++++++++++++++++++
.../apache/lucene/search/TestLRUQueryCache.java | 17 +----
.../join/GlobalOrdinalsWithScoreQuery.java | 10 ++-
.../search/join/ToChildBlockJoinQuery.java | 19 ++---
.../search/join/ToParentBlockJoinQuery.java | 19 ++---
.../apache/lucene/search/AssertingWeight.java | 19 +----
.../lucene/search/RandomApproximationQuery.java | 21 +-----
.../search/TestBaseExplanationTestCase.java | 14 +---
.../apache/solr/search/ReRankQParserPlugin.java | 24 ++-----
11 files changed, 170 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 16d9d41..ec8ecf0 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -132,6 +132,9 @@ Other
* LUCENE-7360: Explanation.toHtml() is deprecated. (Alan Woodward)
+* LUCENE-7372: Factor out an org.apache.lucene.search.FilterWeight class.
+ (Christine Poerschke, Adrien Grand, David Smiley)
+
======================= Lucene 6.1.0 =======================
New Features
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java b/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
new file mode 100644
index 0000000..2053067
--- /dev/null
+++ b/lucene/core/src/java/org/apache/lucene/search/FilterWeight.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.Term;
+
+/**
+ * A {@code FilterWeight} contains another {@code Weight} and implements
+ * all abstract methods by calling the contained weight's method.
+ *
+ * Note that {@code FilterWeight} does not override the non-abstract
+ * {@link Weight#bulkScorer(LeafReaderContext)} method and subclasses of
+ * {@code FilterWeight} must provide their bulkScorer implementation
+ * if required.
+ *
+ * @lucene.internal
+ */
+public abstract class FilterWeight extends Weight {
+
+ final protected Weight in;
+
+ /**
+ * Default constructor.
+ */
+ protected FilterWeight(Weight weight) {
+ this(weight.getQuery(), weight);
+ }
+
+ /**
+ * Alternative constructor.
+ * Use this variant only if the <code>weight</code> was not obtained
+ * via the {@link Query#createWeight(IndexSearcher, boolean, float)}
+ * method of the <code>query</code> object.
+ */
+ protected FilterWeight(Query query, Weight weight) {
+ super(query);
+ this.in = weight;
+ }
+
+ @Override
+ public void extractTerms(Set<Term> terms) {
+ in.extractTerms(terms);
+ }
+
+ @Override
+ public Explanation explain(LeafReaderContext context, int doc) throws IOException {
+ return in.explain(context, doc);
+ }
+
+ @Override
+ public Scorer scorer(LeafReaderContext context) throws IOException {
+ return in.scorer(context);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java b/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
new file mode 100644
index 0000000..cfa01bf
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.search;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.lucene.util.LuceneTestCase;
+import org.junit.Test;
+
+public class TestFilterWeight extends LuceneTestCase {
+
+ @Test
+ public void testDeclaredMethodsOverridden() throws Exception {
+ final Class<?> subClass = FilterWeight.class;
+ implTestDeclaredMethodsOverridden(subClass.getSuperclass(), subClass);
+ }
+
+ private void implTestDeclaredMethodsOverridden(Class<?> superClass, Class<?> subClass) throws Exception {
+ for (final Method superClassMethod : superClass.getDeclaredMethods()) {
+ final int modifiers = superClassMethod.getModifiers();
+ if (Modifier.isFinal(modifiers)) continue;
+ if (Modifier.isStatic(modifiers)) continue;
+ if (superClassMethod.getName().equals("bulkScorer")) {
+ try {
+ final Method subClassMethod = subClass.getDeclaredMethod(
+ superClassMethod.getName(),
+ superClassMethod.getParameterTypes());
+ fail(subClass + " must not override\n'" + superClassMethod + "'"
+ + " but it does override\n'" + subClassMethod + "'");
+ } catch (NoSuchMethodException e) {
+ /* FilterWeight must not override the bulkScorer method
+ * since as of July 2016 not all deriving classes use the
+ * {code}return in.bulkScorer(content);{code}
+ * implementation that FilterWeight.bulkScorer would use.
+ */
+ continue;
+ }
+ }
+ try {
+ final Method subClassMethod = subClass.getDeclaredMethod(
+ superClassMethod.getName(),
+ superClassMethod.getParameterTypes());
+ assertEquals("getReturnType() difference",
+ superClassMethod.getReturnType(),
+ subClassMethod.getReturnType());
+ } catch (NoSuchMethodException e) {
+ fail(subClass + " needs to override '" + superClassMethod + "'");
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
index a2e4e1d..460f4a7 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestLRUQueryCache.java
@@ -29,7 +29,6 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -1088,30 +1087,18 @@ public class TestLRUQueryCache extends LuceneTestCase {
}
}
- private static class WeightWrapper extends Weight {
+ private static class WeightWrapper extends FilterWeight {
- private final Weight in;
private final AtomicBoolean scorerCalled;
private final AtomicBoolean bulkScorerCalled;
protected WeightWrapper(Weight in, AtomicBoolean scorerCalled, AtomicBoolean bulkScorerCalled) {
- super(in.getQuery());
- this.in = in;
+ super(in);
this.scorerCalled = scorerCalled;
this.bulkScorerCalled = bulkScorerCalled;
}
@Override
- public void extractTerms(Set<Term> terms) {
- in.extractTerms(terms);
- }
-
- @Override
- public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- return in.explain(context, doc);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
scorerCalled.set(true);
return in.scorer(context);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
index 8781d1e..a192996 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
@@ -22,6 +22,7 @@ import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.MultiDocValues;
import org.apache.lucene.index.SortedDocValues;
import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilterWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
@@ -102,13 +103,10 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
'}';
}
- final class W extends Weight {
-
- private final Weight approximationWeight;
+ final class W extends FilterWeight {
W(Query query, Weight approximationWeight) {
- super(query);
- this.approximationWeight = approximationWeight;
+ super(query, approximationWeight);
}
@Override
@@ -148,7 +146,7 @@ final class GlobalOrdinalsWithScoreQuery extends Query {
return null;
}
- Scorer approximationScorer = approximationWeight.scorer(context);
+ Scorer approximationScorer = in.scorer(context);
if (approximationScorer == null) {
return null;
} else if (globalOrds != null) {
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
index b925b31..53f13b6 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
@@ -20,11 +20,9 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
-import java.util.Set;
-
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilterWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
@@ -90,29 +88,22 @@ public class ToChildBlockJoinQuery extends Query {
return parentQuery;
}
- private static class ToChildBlockJoinWeight extends Weight {
- private final Weight parentWeight;
+ private static class ToChildBlockJoinWeight extends FilterWeight {
private final BitSetProducer parentsFilter;
private final boolean doScores;
public ToChildBlockJoinWeight(Query joinQuery, Weight parentWeight, BitSetProducer parentsFilter, boolean doScores) {
- super(joinQuery);
- this.parentWeight = parentWeight;
+ super(joinQuery, parentWeight);
this.parentsFilter = parentsFilter;
this.doScores = doScores;
}
- @Override
- public void extractTerms(Set<Term> terms) {
- parentWeight.extractTerms(terms);
- }
-
// NOTE: acceptDocs applies (and is checked) only in the
// child document space
@Override
public Scorer scorer(LeafReaderContext readerContext) throws IOException {
- final Scorer parentScorer = parentWeight.scorer(readerContext);
+ final Scorer parentScorer = in.scorer(readerContext);
if (parentScorer == null) {
// No matches
@@ -138,7 +129,7 @@ public class ToChildBlockJoinQuery extends Query {
return Explanation.match(
scorer.score(),
String.format(Locale.ROOT, "Score based on parent document %d", parentDoc + context.docBase),
- parentWeight.explain(context, parentDoc)
+ in.explain(context, parentDoc)
);
}
return Explanation.noMatch("Not a match");
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
index d5745d9..18a5d20 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
@@ -20,12 +20,10 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
-import java.util.Set;
-
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilterWeight;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
@@ -124,29 +122,22 @@ public class ToParentBlockJoinQuery extends Query {
return childQuery;
}
- private static class BlockJoinWeight extends Weight {
- private final Weight childWeight;
+ private static class BlockJoinWeight extends FilterWeight {
private final BitSetProducer parentsFilter;
private final ScoreMode scoreMode;
public BlockJoinWeight(Query joinQuery, Weight childWeight, BitSetProducer parentsFilter, ScoreMode scoreMode) {
- super(joinQuery);
- this.childWeight = childWeight;
+ super(joinQuery, childWeight);
this.parentsFilter = parentsFilter;
this.scoreMode = scoreMode;
}
- @Override
- public void extractTerms(Set<Term> terms) {
- childWeight.extractTerms(terms);
- }
-
// NOTE: acceptDocs applies (and is checked) only in the
// parent document space
@Override
public Scorer scorer(LeafReaderContext readerContext) throws IOException {
- final Scorer childScorer = childWeight.scorer(readerContext);
+ final Scorer childScorer = in.scorer(readerContext);
if (childScorer == null) {
// No matches
return null;
@@ -174,7 +165,7 @@ public class ToParentBlockJoinQuery extends Query {
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
BlockJoinScorer scorer = (BlockJoinScorer) scorer(context);
if (scorer != null && scorer.iterator().advance(doc) == doc) {
- return scorer.explain(context, childWeight);
+ return scorer.explain(context, in);
}
return Explanation.noMatch("Not a match");
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
index 9f24f22..75529df 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
@@ -18,35 +18,20 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Random;
-import java.util.Set;
-
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.Term;
-class AssertingWeight extends Weight {
+class AssertingWeight extends FilterWeight {
final Random random;
- final Weight in;
final boolean needsScores;
AssertingWeight(Random random, Weight in, boolean needsScores) {
- super(in.getQuery());
+ super(in);
this.random = random;
- this.in = in;
this.needsScores = needsScores;
}
@Override
- public void extractTerms(Set<Term> terms) {
- in.extractTerms(terms);
- }
-
- @Override
- public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- return in.explain(context, doc);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
final Scorer inScorer = in.scorer(context);
assert inScorer == null || inScorer.docID() == -1;
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java b/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
index 2db46ff..0bf81e5 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
@@ -18,13 +18,10 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.Random;
-import java.util.Set;
-
import com.carrotsearch.randomizedtesting.generators.RandomInts;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.Term;
/**
* A {@link Query} that adds random approximations to its scorers.
@@ -70,30 +67,18 @@ public class RandomApproximationQuery extends Query {
return new RandomApproximationWeight(weight, new Random(random.nextLong()));
}
- private static class RandomApproximationWeight extends Weight {
+ private static class RandomApproximationWeight extends FilterWeight {
- private final Weight weight;
private final Random random;
RandomApproximationWeight(Weight weight, Random random) {
- super(weight.getQuery());
- this.weight = weight;
+ super(weight);
this.random = random;
}
@Override
- public void extractTerms(Set<Term> terms) {
- weight.extractTerms(terms);
- }
-
- @Override
- public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- return weight.explain(context, doc);
- }
-
- @Override
public Scorer scorer(LeafReaderContext context) throws IOException {
- final Scorer scorer = weight.scorer(context);
+ final Scorer scorer = in.scorer(context);
if (scorer == null) {
return null;
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java
----------------------------------------------------------------------
diff --git a/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java b/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java
index 0c342d9..c421647 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/search/TestBaseExplanationTestCase.java
@@ -17,8 +17,6 @@
package org.apache.lucene.search;
import java.io.IOException;
-import java.util.Set;
-
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.Term;
@@ -78,11 +76,9 @@ public class TestBaseExplanationTestCase extends BaseExplanationTestCase {
}
}
- public static final class BrokenExplainWeight extends Weight {
- final Weight in;
+ public static final class BrokenExplainWeight extends FilterWeight {
public BrokenExplainWeight(BrokenExplainTermQuery q, Weight in) {
- super(q);
- this.in = in;
+ super(q, in);
}
public BulkScorer bulkScorer(LeafReaderContext context) throws IOException {
return in.bulkScorer(context);
@@ -104,11 +100,5 @@ public class TestBaseExplanationTestCase extends BaseExplanationTestCase {
}
return result;
}
- public void extractTerms(Set<Term> terms) {
- in.extractTerms(terms);
- }
- public Scorer scorer(LeafReaderContext context) throws IOException {
- return in.scorer(context);
- }
}
}
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/15e8719b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
index 03a1d33..37919f4 100644
--- a/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
@@ -20,14 +20,12 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Map;
-import java.util.Set;
-
import com.carrotsearch.hppc.IntFloatHashMap;
import com.carrotsearch.hppc.IntIntHashMap;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.Term;
+import org.apache.lucene.search.FilterWeight;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.LeafCollector;
@@ -35,7 +33,6 @@ import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.QueryRescorer;
import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopDocsCollector;
@@ -179,33 +176,20 @@ public class ReRankQParserPlugin extends QParserPlugin {
}
}
- private class ReRankWeight extends Weight{
+ private class ReRankWeight extends FilterWeight {
private Query reRankQuery;
private IndexSearcher searcher;
- private Weight mainWeight;
private double reRankWeight;
public ReRankWeight(Query mainQuery, Query reRankQuery, double reRankWeight, IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
- super(mainQuery);
+ super(mainQuery, mainQuery.createWeight(searcher, needsScores, boost));
this.reRankQuery = reRankQuery;
this.searcher = searcher;
this.reRankWeight = reRankWeight;
- this.mainWeight = mainQuery.createWeight(searcher, needsScores, boost);
- }
-
- @Override
- public void extractTerms(Set<Term> terms) {
- this.mainWeight.extractTerms(terms);
-
- }
-
- @Override
- public Scorer scorer(LeafReaderContext context) throws IOException {
- return mainWeight.scorer(context);
}
public Explanation explain(LeafReaderContext context, int doc) throws IOException {
- Explanation mainExplain = mainWeight.explain(context, doc);
+ Explanation mainExplain = in.explain(context, doc);
return new QueryRescorer(reRankQuery) {
@Override
protected float combine(float firstPassScore, boolean secondPassMatches, float secondPassScore) {