@@ -177,35 +177,33 @@ LeafBucketCollector getLeafCollector(LeafReaderContext context, LeafBucketCollec
177
177
// unwrapSingleton() returns non-null only if the field is single-valued
178
178
final SortedDocValues singleton = DocValues .unwrapSingleton (dvs );
179
179
180
- // Optimization path: Field is confirmed to be single-valued
180
+ // Direct ordinal access for single-valued fields
181
181
if (singleton != null ) {
182
182
return new LeafBucketCollector () {
183
183
@ Override
184
184
public void collect (int doc , long bucket ) throws IOException {
185
- if (singleton .advanceExact (doc )) { // If document has a value
186
- currentValue = singleton .ordValue (); // Get ordinal directly
187
- next .collect (doc , bucket ); // Collect into bucket
188
- } else if (missingBucket ) { // Handle missing value case
189
- currentValue = -1 ; // Use -1 for missing
185
+ if (singleton .advanceExact (doc )) {
186
+ currentValue = singleton .ordValue ();
187
+ next .collect (doc , bucket );
188
+ } else if (missingBucket ) {
189
+ currentValue = -1 ;
190
190
next .collect (doc , bucket );
191
191
}
192
192
}
193
193
};
194
194
}
195
195
196
- // Non-optimized collector for multi-valued fields
197
196
return new LeafBucketCollector () {
198
197
@ Override
199
198
public void collect (int doc , long bucket ) throws IOException {
200
- if (dvs .advanceExact (doc )) { // If document has values
199
+ if (dvs .advanceExact (doc )) {
201
200
long ord ;
202
- int count = dvs .docValueCount (); // Get number of values
203
- // Loop through all values in the document
201
+ int count = dvs .docValueCount ();
204
202
while ((count -- > 0 ) && (ord = dvs .nextOrd ()) != NO_MORE_DOCS ) {
205
- currentValue = ord ; // Store current ordinal
206
- next .collect (doc , bucket ); // Collect each value
203
+ currentValue = ord ;
204
+ next .collect (doc , bucket );
207
205
}
208
- } else if (missingBucket ) { // Handle missing values
206
+ } else if (missingBucket ) {
209
207
currentValue = -1 ;
210
208
next .collect (doc , bucket );
211
209
}
0 commit comments