Skip to content

Commit

Permalink
SOLR-13539: Fix mv update of UUID, enum, bool and binary fields
Browse files Browse the repository at this point in the history
Co-Authored-By: Thomas Wockinger
  • Loading branch information
gerlowskija committed Jul 1, 2019
1 parent 6799ca6 commit 8242e6c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ Bug Fixes

* SOLR-13566: REINDEXCOLLECTION does not work with (basic) authentication. (Colvin Cowie, ab)

* SOLR-13159: Fix atomic update encoding issue for UUID, enum, bool, and binary fields (Thomas Wockinger via Jason Gerlowski)

================== 8.1.1 ==================

Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
Expand Down
14 changes: 11 additions & 3 deletions solr/core/src/java/org/apache/solr/schema/AbstractEnumField.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.lang3.math.NumberUtils;
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.queries.function.ValueSource;
import org.apache.lucene.queries.function.valuesource.EnumFieldSource;
Expand Down Expand Up @@ -315,11 +316,18 @@ public String toExternal(IndexableField f) {
public Object toNativeType(Object val) {
if (val instanceof CharSequence || val instanceof String) {
final String str = val.toString();
return new EnumFieldValue(enumMapping.enumStringToIntMap.get(str), str);
} else if(val instanceof Number) {
final int num = ((Number)val).intValue();
final Integer entry = enumMapping.enumStringToIntMap.get(str);
if (entry != null) {
return new EnumFieldValue(entry, str);
} else if (NumberUtils.isCreatable(str)) {
final int num = Integer.parseInt(str);
return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
}
} else if (val instanceof Number) {
final int num = ((Number) val).intValue();
return new EnumFieldValue(num, enumMapping.enumIntToStringMap.get(num));
}

return super.toNativeType(val);
}
}
8 changes: 8 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/BinaryField.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,12 @@ public IndexableField createField(SchemaField field, Object val) {

return new org.apache.lucene.document.StoredField(field.getName(), buf, offset, len);
}

@Override
public Object toNativeType(Object val) {
if (val instanceof byte[]) {
return ByteBuffer.wrap((byte[]) val);
}
return super.toNativeType(val);
}
}
7 changes: 7 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/BoolField.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ public List<IndexableField> createFields(SchemaField field, Object value) {
return Collections.singletonList(fval);
}

@Override
public Object toNativeType(Object val) {
if (val instanceof CharSequence) {
return Boolean.valueOf(val.toString());
}
return super.toNativeType(val);
}
}

// TODO - this can be much more efficient - use FixedBitSet or Bits
Expand Down
8 changes: 8 additions & 0 deletions solr/core/src/java/org/apache/solr/schema/UUIDField.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public String toInternal(UUID uuid) {
public UUID toObject(IndexableField f) {
return UUID.fromString(f.stringValue());
}

@Override
public Object toNativeType(Object val) {
if (val instanceof CharSequence) {
return UUID.fromString(val.toString());
}
return val;
}
}

0 comments on commit 8242e6c

Please sign in to comment.