diff options
author | Robert Newson <rnewson@apache.org> | 2023-04-11 16:53:51 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2023-04-22 11:20:02 +0100 |
commit | b1cb89992da5699115a8ee78731367b3e9d0fc9d (patch) | |
tree | b55f5be08acc3e03bd2a501b284eef4808d3c67c | |
parent | 3e63df81b94b04c252eb45aa2ceaeae04702b549 (diff) | |
download | couchdb-b1cb89992da5699115a8ee78731367b3e9d0fc9d.tar.gz |
fix StoredField
-rw-r--r-- | nouveau/src/main/java/org/apache/couchdb/nouveau/api/StoredField.java | 28 | ||||
-rw-r--r-- | nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java | 10 |
2 files changed, 10 insertions, 28 deletions
diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/api/StoredField.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/api/StoredField.java index 060eb5a06..755f5a907 100644 --- a/nouveau/src/main/java/org/apache/couchdb/nouveau/api/StoredField.java +++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/api/StoredField.java @@ -22,39 +22,21 @@ public final class StoredField extends Field { @NotNull private final Object value; - private final boolean encoded; - - public StoredField(@JsonProperty("name") final String name, @JsonProperty("value") final String value) { - super(name); - this.value = value; - this.encoded = false; - } - - public StoredField(@JsonProperty("name") final String name, @JsonProperty("value") final double value) { + public StoredField(@JsonProperty("name") final String name, @JsonProperty("value") final Object value) { super(name); + if (!(value instanceof String || value instanceof Number || value instanceof byte[])) { + throw new IllegalArgumentException(value + " must be a string, number or byte array"); + } this.value = value; - this.encoded = false; } - public StoredField(@JsonProperty("name") final String name, @JsonProperty("value") final byte[] value) { - super(name); - this.value = value; - this.encoded = true; - } - - @JsonProperty public Object getValue() { return value; } - @JsonProperty - public boolean isEncoded() { - return encoded; - } - @Override public String toString() { - return "StoredField [value=" + value + ", encoded=" + encoded + "]"; + return "StoredField [name=" + name + ", value=" + value + "]"; } } diff --git a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java index 47094b7b2..8e4a88259 100644 --- a/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java +++ b/nouveau/src/main/java/org/apache/couchdb/nouveau/lucene9/Lucene9Index.java @@ -237,7 +237,7 @@ public class Lucene9Index extends Index { continue; } if (field.numericValue() != null) { - fields.add(new StoredField(field.name(), (double) field.numericValue())); + fields.add(new StoredField(field.name(), field.numericValue().doubleValue())); } else if (field.binaryValue() != null) { fields.add(new StoredField(field.name(), toBytes(field.binaryValue()))); } else if (field.stringValue() != null) { @@ -392,11 +392,11 @@ public class Lucene9Index extends Index { var f = (StoredField) field; var val = f.getValue(); if (val instanceof String) { - result.add(new org.apache.lucene.document.StoredField(f.getName(), (String) f.getValue())); - } else if (val instanceof Double) { - result.add(new org.apache.lucene.document.StoredField(f.getName(), (Double) f.getValue())); + result.add(new org.apache.lucene.document.StoredField(f.getName(), (String) val)); + } else if (val instanceof Number) { + result.add(new org.apache.lucene.document.StoredField(f.getName(), ((Number)val).doubleValue())); } else if (val instanceof byte[]) { - result.add(new org.apache.lucene.document.StoredField(f.getName(), (byte[]) f.getValue())); + result.add(new org.apache.lucene.document.StoredField(f.getName(), (byte[]) val)); } else { throw new WebApplicationException(field + " is not valid", Status.BAD_REQUEST); } |