Skip to content

Commit 47a89ac

Browse files
committed
SOLR-15078: Fix ExpandComponent behavior when expanding on numeric fields to differentiate '0' group from null group
1 parent 166d39a commit 47a89ac

File tree

5 files changed

+303
-265
lines changed

5 files changed

+303
-265
lines changed

solr/CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Optimizations
212212

213213
Bug Fixes
214214
---------------------
215-
(No changes)
215+
* SOLR-15078: Fix ExpandComponent behavior when expanding on numeric fields to differentiate '0' group from null group (hossman)
216216

217217
Other Changes
218218
---------------------

solr/core/src/java/org/apache/solr/handler/component/ExpandComponent.java

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@
7171
import org.apache.solr.core.SolrCore;
7272
import org.apache.solr.request.SolrQueryRequest;
7373
import org.apache.solr.schema.FieldType;
74-
import org.apache.solr.schema.NumberType;
7574
import org.apache.solr.schema.SchemaField;
7675
import org.apache.solr.schema.StrField;
7776
import org.apache.solr.search.CollapsingQParserPlugin;
@@ -214,7 +213,6 @@ public void process(ResponseBuilder rb) throws IOException {
214213
FieldType fieldType = schemaField.getType();
215214

216215
SortedDocValues values = null;
217-
long nullValue = 0L;
218216

219217
if(fieldType instanceof StrField) {
220218
//Get The Top Level SortedDocValues
@@ -225,28 +223,7 @@ public void process(ResponseBuilder rb) throws IOException {
225223
} else {
226224
values = DocValues.getSorted(reader, field);
227225
}
228-
} else if (fieldType.getNumberType() != null) {
229-
//Get the nullValue for the numeric collapse field
230-
String defaultValue = searcher.getSchema().getField(field).getDefaultValue();
231-
232-
final NumberType numType = fieldType.getNumberType();
233-
234-
// Since the expand component depends on the operation of the collapse component,
235-
// which validates that numeric field types are 32-bit,
236-
// we don't need to handle invalid 64-bit field types here.
237-
// FIXME: what happens when expand.field specified?
238-
// how would this work for date field?
239-
// SOLR-10400: before this, long and double were explicitly handled
240-
if (defaultValue != null) {
241-
if (numType == NumberType.INTEGER) {
242-
nullValue = Long.parseLong(defaultValue);
243-
} else if (numType == NumberType.FLOAT) {
244-
nullValue = Float.floatToIntBits(Float.parseFloat(defaultValue));
245-
}
246-
} else if (NumberType.FLOAT.equals(numType)) { // Integer case already handled by nullValue defaulting to 0
247-
nullValue = Float.floatToIntBits(0.0f);
248-
}
249-
} else {
226+
} else if (fieldType.getNumberType() == null) {
250227
// possible if directly expand.field is specified
251228
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
252229
"Expand not supported for fieldType:'" + fieldType.getTypeName() +"'");
@@ -358,13 +335,8 @@ public void process(ResponseBuilder rb) throws IOException {
358335
if (valueDocID < contextDoc) {
359336
valueDocID = collapseValues.advance(contextDoc);
360337
}
361-
long value;
362338
if (valueDocID == contextDoc) {
363-
value = collapseValues.longValue();
364-
} else {
365-
value = 0;
366-
}
367-
if(value != nullValue) {
339+
final long value = collapseValues.longValue();
368340
groupSet.add(value);
369341
collapsedSet.add(globalDoc);
370342
}
@@ -399,7 +371,7 @@ public void process(ResponseBuilder rb) throws IOException {
399371

400372
groupExpandCollector = new GroupExpandCollector(values, groupBits, collapsedSet, limit, sort);
401373
} else {
402-
groupExpandCollector = new NumericGroupExpandCollector(field, nullValue, groupSet, collapsedSet, limit, sort);
374+
groupExpandCollector = new NumericGroupExpandCollector(field, groupSet, collapsedSet, limit, sort);
403375
}
404376

405377
if(groupQuery != null) {
@@ -628,11 +600,9 @@ private static class NumericGroupExpandCollector implements Collector, GroupColl
628600
private LongObjectHashMap<Collector> groups;
629601

630602
private IntHashSet collapsedSet;
631-
private long nullValue;
632603

633-
public NumericGroupExpandCollector(String field, long nullValue, LongHashSet groupSet, IntHashSet collapsedSet, int limit, Sort sort) throws IOException {
604+
public NumericGroupExpandCollector(String field, LongHashSet groupSet, IntHashSet collapsedSet, int limit, Sort sort) throws IOException {
634605
int numGroups = collapsedSet.size();
635-
this.nullValue = nullValue;
636606
groups = new LongObjectHashMap<>(numGroups);
637607
for (LongCursor cursor : groupSet) {
638608
groups.put(cursor.value, getCollector(limit, sort));
@@ -663,17 +633,12 @@ public void setScorer(Scorable scorer) throws IOException {
663633

664634
@Override
665635
public void collect(int docId) throws IOException {
666-
long value;
667636
if (docValues.advanceExact(docId)) {
668-
value = docValues.longValue();
669-
} else {
670-
value = 0;
671-
}
672-
final int index;
673-
if (value != nullValue &&
674-
(index = leafCollectors.indexOf(value)) >= 0 &&
675-
!collapsedSet.contains(docId + docBase)) {
676-
leafCollectors.indexGet(index).collect(docId);
637+
final long value = docValues.longValue();
638+
final int index = leafCollectors.indexOf(value);
639+
if (index >= 0 && !collapsedSet.contains(docId + docBase)) {
640+
leafCollectors.indexGet(index).collect(docId);
641+
}
677642
}
678643
}
679644
};

0 commit comments

Comments
 (0)