Skip to content

Commit 3842bbe

Browse files
Refactor DocValuesSkipper stat methods to accept IndexReader instead of IndexSearcher (#15514)
1 parent 02c40ba commit 3842bbe

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ API Changes
180180

181181
* GITHUB#15501: Introduce optional access to backing vector values from the scorer (Chris Hegarty)
182182

183+
* GITHUB#15514: Refactor DocValuesSkipper stat methods to accept IndexReader instead of IndexSearcher (Pan Guixin)
184+
183185
New Features
184186
---------------------
185187
* GITHUB#15328: VectorSimilarityFunction.getValues() now implements doubleVal allowing its

lucene/core/src/java/org/apache/lucene/document/SortedNumericDocValuesRangeQuery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
9393
if (lowerValue > upperValue) {
9494
return MatchNoDocsQuery.INSTANCE;
9595
}
96-
long globalMin = DocValuesSkipper.globalMinValue(indexSearcher, field);
97-
long globalMax = DocValuesSkipper.globalMaxValue(indexSearcher, field);
96+
long globalMin = DocValuesSkipper.globalMinValue(indexSearcher.getIndexReader(), field);
97+
long globalMax = DocValuesSkipper.globalMaxValue(indexSearcher.getIndexReader(), field);
9898
if (lowerValue > globalMax || upperValue < globalMin) {
9999
return MatchNoDocsQuery.INSTANCE;
100100
}
101101
if (lowerValue <= globalMin
102102
&& upperValue >= globalMax
103-
&& DocValuesSkipper.globalDocCount(indexSearcher, field)
103+
&& DocValuesSkipper.globalDocCount(indexSearcher.getIndexReader(), field)
104104
== indexSearcher.getIndexReader().maxDoc()) {
105105
return MatchAllDocsQuery.INSTANCE;
106106
}

lucene/core/src/java/org/apache/lucene/index/DocValuesSkipper.java

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

1919
import java.io.IOException;
2020
import org.apache.lucene.search.DocIdSetIterator;
21-
import org.apache.lucene.search.IndexSearcher;
2221

2322
/**
2423
* Skipper for {@link DocValues}.
@@ -128,12 +127,12 @@ public final void advance(long minValue, long maxValue) throws IOException {
128127
* Returns the minimum value for a field across all segments, or {@link Long#MIN_VALUE} if not
129128
* available
130129
*
131-
* @param searcher a searcher over the index
130+
* @param reader the index reader to be queried
132131
* @param field the field to retrieve values for
133132
*/
134-
public static long globalMinValue(IndexSearcher searcher, String field) throws IOException {
133+
public static long globalMinValue(IndexReader reader, String field) throws IOException {
135134
long minValue = Long.MAX_VALUE;
136-
for (LeafReaderContext ctx : searcher.getLeafContexts()) {
135+
for (LeafReaderContext ctx : reader.leaves()) {
137136
if (ctx.reader().getFieldInfos().fieldInfo(field) == null) {
138137
continue; // no field values in this segment, so we can ignore it
139138
}
@@ -152,12 +151,12 @@ public static long globalMinValue(IndexSearcher searcher, String field) throws I
152151
* Returns the maximum value for a field across all segments, or {@link Long#MIN_VALUE} if not
153152
* available
154153
*
155-
* @param searcher a searcher over the index
154+
* @param reader the index reader to be queried
156155
* @param field the field to retrieve values for
157156
*/
158-
public static long globalMaxValue(IndexSearcher searcher, String field) throws IOException {
157+
public static long globalMaxValue(IndexReader reader, String field) throws IOException {
159158
long maxValue = Long.MIN_VALUE;
160-
for (LeafReaderContext ctx : searcher.getLeafContexts()) {
159+
for (LeafReaderContext ctx : reader.leaves()) {
161160
if (ctx.reader().getFieldInfos().fieldInfo(field) == null) {
162161
continue; // no field values in this segment, so we can ignore it
163162
}
@@ -175,12 +174,12 @@ public static long globalMaxValue(IndexSearcher searcher, String field) throws I
175174
/**
176175
* Returns the total skipper document count for a field across all segments
177176
*
178-
* @param searcher a searcher over the index
177+
* @param reader the index reader to be queried
179178
* @param field the field to retrieve values for
180179
*/
181-
public static int globalDocCount(IndexSearcher searcher, String field) throws IOException {
180+
public static int globalDocCount(IndexReader reader, String field) throws IOException {
182181
int docCount = 0;
183-
for (LeafReaderContext ctx : searcher.getLeafContexts()) {
182+
for (LeafReaderContext ctx : reader.leaves()) {
184183
DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(field);
185184
if (skipper != null) {
186185
docCount += skipper.docCount();

0 commit comments

Comments
 (0)