Skip to content

Commit 62231ea

Browse files
prudhvigodithidweiss
authored andcommitted
Add count() to FilterWeight (#15510)
1 parent 4019ff1 commit 62231ea

File tree

7 files changed

+27
-29
lines changed

7 files changed

+27
-29
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ API Changes
5151
* GITHUB#15581: Minor javadoc clarification that HasIndexSlice::getSlice can return null
5252
(Chris Hegarty)
5353

54+
* GITHUB#15502: Add `count()` method to `FilterWeight` (Prudhvi Godithi)
55+
5456
New Features
5557
---------------------
5658
* GITHUB#15328: VectorSimilarityFunction.getValues() now implements doubleVal allowing its

lucene/core/src/java/org/apache/lucene/search/FilterWeight.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
* A {@code FilterWeight} contains another {@code Weight} and implements all abstract methods by
2424
* calling the contained weight's method.
2525
*
26-
* <p>Note that {@code FilterWeight} does not override the non-abstract {@link
27-
* Weight#bulkScorer(LeafReaderContext)} method and subclasses of {@code FilterWeight} must provide
28-
* their bulkScorer implementation if required.
29-
*
3026
* @lucene.internal
3127
*/
3228
public abstract class FilterWeight extends Weight {
@@ -67,4 +63,9 @@ public Matches matches(LeafReaderContext context, int doc) throws IOException {
6763
public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOException {
6864
return in.scorerSupplier(context);
6965
}
66+
67+
@Override
68+
public int count(LeafReaderContext context) throws IOException {
69+
return in.count(context);
70+
}
7071
}

lucene/core/src/test/org/apache/lucene/search/TestFilterWeight.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.lang.reflect.Method;
2020
import java.lang.reflect.Modifier;
21-
import java.util.Arrays;
2221
import org.apache.lucene.tests.util.LuceneTestCase;
2322
import org.junit.Test;
2423

@@ -36,30 +35,6 @@ private void implTestDeclaredMethodsOverridden(Class<?> superClass, Class<?> sub
3635
final int modifiers = superClassMethod.getModifiers();
3736
if (Modifier.isFinal(modifiers)) continue;
3837
if (Modifier.isStatic(modifiers)) continue;
39-
if (Arrays.asList("bulkScorer", "count").contains(superClassMethod.getName())) {
40-
try {
41-
final Method subClassMethod =
42-
subClass.getDeclaredMethod(
43-
superClassMethod.getName(), superClassMethod.getParameterTypes());
44-
fail(
45-
subClass
46-
+ " must not override\n'"
47-
+ superClassMethod
48-
+ "'"
49-
+ " but it does override\n'"
50-
+ subClassMethod
51-
+ "'");
52-
} catch (
53-
@SuppressWarnings("unused")
54-
NoSuchMethodException e) {
55-
/* FilterWeight must not override the bulkScorer method
56-
* since as of July 2016 not all deriving classes use the
57-
* {code}return in.bulkScorer(content);{code}
58-
* implementation that FilterWeight.bulkScorer would use.
59-
*/
60-
continue;
61-
}
62-
}
6338
try {
6439
final Method subClassMethod =
6540
subClass.getDeclaredMethod(

lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public boolean isCacheable(LeafReaderContext ctx) {
240240
// the memory used by the cache
241241
return false;
242242
}
243+
244+
@Override
245+
public int count(LeafReaderContext context) {
246+
return -1;
247+
}
243248
}
244249

245250
static final class OrdinalMapScorer extends BaseGlobalOrdinalScorer {

lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public Explanation explain(LeafReaderContext context, int doc) throws IOExceptio
135135
}
136136
return Explanation.noMatch("Not a match");
137137
}
138+
139+
@Override
140+
public int count(LeafReaderContext context) {
141+
return -1;
142+
}
138143
}
139144

140145
static class ToChildBlockJoinScorer extends Scorer {

lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ public Matches matches(LeafReaderContext context, int doc) throws IOException {
217217
}
218218
return MatchesUtils.MATCH_WITH_NO_TERMS;
219219
}
220+
221+
@Override
222+
public int count(LeafReaderContext context) {
223+
return -1;
224+
}
220225
}
221226

222227
private static class ParentApproximation extends DocIdSetIterator {

lucene/test-framework/src/java/org/apache/lucene/tests/search/RandomApproximationQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public ScorerSupplier scorerSupplier(LeafReaderContext context) throws IOExcepti
100100
}
101101
return new DefaultScorerSupplier(scorer);
102102
}
103+
104+
@Override
105+
public int count(LeafReaderContext context) {
106+
return -1;
107+
}
103108
}
104109

105110
private static class RandomApproximationScorer extends Scorer {

0 commit comments

Comments
 (0)