@@ -133,20 +133,23 @@ public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, fl
133
133
throws IOException {
134
134
135
135
if (this .equalValues ) { // lowerPoint==upperPoint
136
- return new SinglePointConstantScoreWeight (this , scoreMode , boost );
136
+ return new SinglePointRangeQueryWeight (this , scoreMode , boost );
137
137
}
138
138
// We don't use RandomAccessWeight here: it's no good to approximate with "match all docs".
139
139
// This is an inverted structure and should be used in the first pass:
140
- return new MultiPointsConstantScoreWeight (this , scoreMode , boost );
140
+ return new MultiPointRangeQueryWeight (this , scoreMode , boost );
141
141
}
142
142
143
143
/**
144
- * Essentially, it is to reduce the number of comparisons. This is an optimization, used for the
145
- * case of lowerPoint==upperPoint.
144
+ * Single-point range query weight implementation class, used to handle the special case where the
145
+ * lower and upper bounds are equal (i.e. single-point query).
146
+ *
147
+ * <p>Optimize query performance by reducing the number of comparisons between dimensions. This
148
+ * implementation is used when the upper and lower bounds of all dimensions are exactly the same.
146
149
*/
147
- protected class SinglePointConstantScoreWeight extends MultiPointsConstantScoreWeight {
150
+ protected class SinglePointRangeQueryWeight extends PointRangeQueryWeight {
148
151
149
- public SinglePointConstantScoreWeight (Query query , ScoreMode scoreMode , float boost ) {
152
+ protected SinglePointRangeQueryWeight (Query query , ScoreMode scoreMode , float boost ) {
150
153
super (query , scoreMode , boost );
151
154
}
152
155
@@ -192,21 +195,20 @@ public Relation relate(byte[] minPackedValue, byte[] maxPackedValue) {
192
195
}
193
196
194
197
/**
195
- * A weight that used for lowerPoint != upperPoint case, the query range may include multiple
196
- * points.
198
+ * Multiple-point range query weight implementation class, used to handle the situation where the
199
+ * query range contains multiple points.
200
+ *
201
+ * <p>When the lower bound (lowerPoint) of the query is not equal to the upper bound (upperPoint),
202
+ * this implementation is used to check whether each dimension is within the query range.
197
203
*/
198
- protected class MultiPointsConstantScoreWeight extends ConstantScoreWeight {
204
+ protected class MultiPointRangeQueryWeight extends PointRangeQueryWeight {
199
205
200
- protected ScoreMode scoreMode ;
201
- protected ByteArrayComparator comparator ;
202
-
203
- public MultiPointsConstantScoreWeight (Query query , ScoreMode scoreMode , float boost ) {
204
- super (query , boost );
205
- this .scoreMode = scoreMode ;
206
- this .comparator = ArrayUtil .getUnsignedComparator (bytesPerDim );
206
+ protected MultiPointRangeQueryWeight (Query query , ScoreMode scoreMode , float boost ) {
207
+ super (query , scoreMode , boost );
207
208
}
208
209
209
- public boolean matches (byte [] packedValue ) {
210
+ @ Override
211
+ protected boolean matches (byte [] packedValue ) {
210
212
int offset = 0 ;
211
213
for (int dim = 0 ; dim < numDims ; dim ++, offset += bytesPerDim ) {
212
214
if (comparator .compare (packedValue , offset , lowerPoint , offset ) < 0 ) {
@@ -221,7 +223,8 @@ public boolean matches(byte[] packedValue) {
221
223
return true ;
222
224
}
223
225
224
- public Relation relate (byte [] minPackedValue , byte [] maxPackedValue ) {
226
+ @ Override
227
+ protected Relation relate (byte [] minPackedValue , byte [] maxPackedValue ) {
225
228
226
229
boolean crosses = false ;
227
230
int offset = 0 ;
@@ -244,6 +247,31 @@ public Relation relate(byte[] minPackedValue, byte[] maxPackedValue) {
244
247
return Relation .CELL_INSIDE_QUERY ;
245
248
}
246
249
}
250
+ }
251
+
252
+ /**
253
+ * Basic weight class, inherited from {@link ConstantScoreWeight}, subclasses need to implement
254
+ * specific point value matching logic and range relationship judgment.
255
+ *
256
+ * @see SinglePointRangeQueryWeight for the specific implementation of single-point range query.
257
+ * @see MultiPointRangeQueryWeight for the specific implementation of multi-point range query.
258
+ */
259
+ protected abstract class PointRangeQueryWeight extends ConstantScoreWeight {
260
+
261
+ protected ScoreMode scoreMode ;
262
+ protected ByteArrayComparator comparator ;
263
+
264
+ protected PointRangeQueryWeight (Query query , ScoreMode scoreMode , float boost ) {
265
+ super (query , boost );
266
+ this .scoreMode = scoreMode ;
267
+ this .comparator = ArrayUtil .getUnsignedComparator (bytesPerDim );
268
+ }
269
+
270
+ /** whether the point value matches the query range. */
271
+ protected abstract boolean matches (byte [] packedValue );
272
+
273
+ /** relation between the point value range and the query range. */
274
+ protected abstract Relation relate (byte [] minPackedValue , byte [] maxPackedValue );
247
275
248
276
private IntersectVisitor getIntersectVisitor (DocIdSetBuilder result ) {
249
277
return new IntersectVisitor () {
0 commit comments