Skip to content

Commit

Permalink
Fix sorting of single valued numeric fields (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme authored Jan 9, 2025
1 parent e8772e1 commit 2108ef0
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 74 deletions.
17 changes: 6 additions & 11 deletions src/main/java/com/yelp/nrtsearch/server/field/NumberFieldDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,12 @@ public DoubleValuesSource getExpressionBinding(String property) {
@Override
public SortField getSortField(SortType type) {
verifyDocValues("Sort field");
SortField sortField;
if (isMultiValue()) {
sortField =
new SortedNumericSortField(
getName(),
getSortFieldType(),
type.getReverse(),
NUMERIC_TYPE_PARSER.apply(type.getSelector()));
} else {
sortField = new SortField(getName(), getSortFieldType(), type.getReverse());
}
SortField sortField =
new SortedNumericSortField(
getName(),
getSortFieldType(),
type.getReverse(),
NUMERIC_TYPE_PARSER.apply(type.getSelector()));

boolean missingLast = type.getMissingLast();
sortField.setMissingValue(getSortMissingValue(missingLast));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import com.yelp.nrtsearch.server.state.GlobalState;
import java.io.IOException;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -63,7 +62,6 @@
import org.apache.lucene.index.TieredMergePolicy;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortField.Type;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.PrintStreamInfoStream;
import org.slf4j.Logger;
Expand All @@ -72,13 +70,6 @@
/** Implementation of index state which is immutable. */
public class ImmutableIndexState extends IndexState {
private static final Logger logger = LoggerFactory.getLogger(ImmutableIndexState.class);
private static final EnumSet<Type> ALLOWED_INDEX_SORT_TYPES =
EnumSet.of(
SortField.Type.STRING,
SortField.Type.LONG,
SortField.Type.INT,
SortField.Type.DOUBLE,
SortField.Type.FLOAT);

public static final double DEFAULT_NRT_CACHING_MAX_MERGE_SIZE_MB = 5.0;
public static final double DEFAULT_NRT_CACHING_MAX_SIZE_MB = 60.0;
Expand Down Expand Up @@ -831,14 +822,9 @@ static void validateLiveSettings(IndexLiveSettings liveSettings) {

private static void validateIndexSort(Sort sort) {
for (SortField sortField : sort.getSort()) {
if (!ALLOWED_INDEX_SORT_TYPES.contains(sortField.getType())) {
if (sortField.getIndexSorter() == null) {
throw new IllegalArgumentException(
"Sort field: "
+ sortField.getField()
+ ", type: "
+ sortField.getType()
+ " is not in allowed types: "
+ ALLOWED_INDEX_SORT_TYPES);
"Sort field: \"" + sortField.getField() + "\" does not support index sorting");
}
}
}
Expand Down
Loading

0 comments on commit 2108ef0

Please sign in to comment.