Skip to content

Commit 503debf

Browse files
committed
[bugfix] Make sure the content of a typed Lucene Full Text field can actually be parsed as that XDM type
1 parent 3b0d35b commit 503debf

1 file changed

Lines changed: 28 additions & 18 deletions

File tree

extensions/indexes/lucene/src/main/java/org/exist/indexing/lucene/LuceneFieldConfig.java

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -211,39 +211,49 @@ protected void processText(CharSequence text, Document luceneDoc) {
211211
}
212212
}
213213

214-
private Field convertToField(String content) {
214+
private Field convertToField(final String content) {
215215
try {
216216
switch (type) {
217217
case Type.INTEGER:
218218
case Type.LONG:
219219
case Type.UNSIGNED_LONG:
220-
long lvalue = Long.parseLong(content);
221-
return new LongField(fieldName, lvalue, LongField.TYPE_STORED);
220+
final long longValue = new IntegerValue(content, type).getLong();
221+
return new LongField(fieldName, longValue, LongField.TYPE_STORED);
222+
222223
case Type.INT:
223224
case Type.UNSIGNED_INT:
224225
case Type.SHORT:
225226
case Type.UNSIGNED_SHORT:
226-
int ivalue = Integer.parseInt(content);
227-
return new IntField(fieldName, ivalue, IntField.TYPE_STORED);
227+
final int intValue = new IntegerValue(content, type).getInt();
228+
return new IntField(fieldName, intValue, IntField.TYPE_STORED);
229+
228230
case Type.DECIMAL:
231+
final double decimalValue = new DecimalValue(content).getDouble();
232+
return new DoubleField(fieldName, decimalValue, DoubleField.TYPE_STORED);
233+
229234
case Type.DOUBLE:
230-
double dvalue = Double.parseDouble(content);
231-
return new DoubleField(fieldName, dvalue, DoubleField.TYPE_STORED);
235+
final double doubleValue = new DoubleValue(content).getDouble();
236+
return new DoubleField(fieldName, doubleValue, DoubleField.TYPE_STORED);
237+
232238
case Type.FLOAT:
233-
float fvalue = Float.parseFloat(content);
234-
return new FloatField(fieldName, fvalue, FloatField.TYPE_STORED);
239+
final float floatValue = new FloatValue(content).getFloat();
240+
return new FloatField(fieldName, floatValue, FloatField.TYPE_STORED);
241+
235242
case Type.DATE:
236-
DateValue dv = new DateValue(content);
237-
long dl = dateToLong(dv);
238-
return new LongField(fieldName, dl, LongField.TYPE_STORED);
243+
final DateValue dateValue = new DateValue(content);
244+
final long longDateValue = dateToLong(dateValue);
245+
return new LongField(fieldName, longDateValue, LongField.TYPE_STORED);
246+
239247
case Type.TIME:
240-
TimeValue tv = new TimeValue(content);
241-
long tl = timeToLong(tv);
242-
return new LongField(fieldName, tl, LongField.TYPE_STORED);
248+
final TimeValue timeValue = new TimeValue(content);
249+
final long longTimeValue = timeToLong(timeValue);
250+
return new LongField(fieldName, longTimeValue, LongField.TYPE_STORED);
251+
243252
case Type.DATE_TIME:
244-
DateTimeValue dtv = new DateTimeValue(content);
245-
String dateStr = dateTimeToString(dtv);
246-
return new TextField(fieldName, dateStr, Field.Store.YES);
253+
final DateTimeValue dateTimeValue = new DateTimeValue(content);
254+
final String strDateTimeValue = dateTimeToString(dateTimeValue);
255+
return new TextField(fieldName, strDateTimeValue, Field.Store.YES);
256+
247257
default:
248258
return new TextField(fieldName, content, store ? Field.Store.YES : Field.Store.NO);
249259
}

0 commit comments

Comments
 (0)