diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 19830ac5ada..4b9872ba519 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -388,6 +388,9 @@ Bug Fixes if the last published state is something else if it has already registered with ZK. (Ishan Chattopadhyaya, Mark Miller via noble) +* SOLR-8287: TrieDoubleField and TrieLongField now override toNativeType + (Ishan Chattopadhyaya via Christine Poerschke) + Optimizations ---------------------- diff --git a/solr/core/src/java/org/apache/solr/schema/TrieDoubleField.java b/solr/core/src/java/org/apache/solr/schema/TrieDoubleField.java index 16c448490c7..4403b1bfeba 100644 --- a/solr/core/src/java/org/apache/solr/schema/TrieDoubleField.java +++ b/solr/core/src/java/org/apache/solr/schema/TrieDoubleField.java @@ -55,6 +55,14 @@ public class TrieDoubleField extends TrieField implements DoubleValueFieldType { type=TrieTypes.DOUBLE; } + @Override + public Object toNativeType(Object val) { + if(val==null) return null; + if (val instanceof Number) return ((Number) val).doubleValue(); + if (val instanceof String) return Double.parseDouble((String) val); + return super.toNativeType(val); + } + @Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { diff --git a/solr/core/src/java/org/apache/solr/schema/TrieLongField.java b/solr/core/src/java/org/apache/solr/schema/TrieLongField.java index 2d4ca938c97..3eb5de5df24 100644 --- a/solr/core/src/java/org/apache/solr/schema/TrieLongField.java +++ b/solr/core/src/java/org/apache/solr/schema/TrieLongField.java @@ -49,6 +49,19 @@ public class TrieLongField extends TrieField implements LongValueFieldType { type=TrieTypes.LONG; } + @Override + public Object toNativeType(Object val) { + if(val==null) return null; + if (val instanceof Number) return ((Number) val).longValue(); + try { + if (val instanceof String) return Long.parseLong((String) val); + } catch (NumberFormatException e) { + Double v = Double.parseDouble((String) val); + return v.longValue(); + } + return super.toNativeType(val); + } + @Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) {