List of usage examples for org.apache.lucene.document Field setFloatValue
public void setFloatValue(float value)
From source file:com.bewsia.script.LuceneHandler.java
License:Open Source License
protected void write(SEntity entity, Document doc) { String schema = entity.getSchema(); if (schema == null) schema = ""; String[] fields = schema.split("\\|"); for (int i = 0; i < fields.length && i + 1 < fields.length; i += 2) { String kind = fields[i];/*from www.j av a 2 s. c om*/ String fname = fields[i + 1]; if (SEntity.STRING.equalsIgnoreCase(kind)) { Field field = new Field(fname, entity.getString(fname), Store.YES, Index.NOT_ANALYZED_NO_NORMS); doc.add(field); } else if (SEntity.DOUBLE.equalsIgnoreCase(kind)) { NumericField field = new NumericField(fname, Store.YES, true); field.setDoubleValue(entity.getDouble(fname)); doc.add(field); } else if (SEntity.FLOAT.equalsIgnoreCase(kind)) { NumericField field = new NumericField(fname, Store.YES, true); field.setFloatValue(entity.getFloat(fname)); doc.add(field); } else if (SEntity.INTEGER.equalsIgnoreCase(kind)) { NumericField field = new NumericField(fname, Store.YES, true); field.setIntValue(entity.getInteger(fname)); doc.add(field); } else if (SEntity.LONG.equalsIgnoreCase(kind)) { NumericField field = new NumericField(fname, Store.YES, true); field.setLongValue(entity.getLong(fname)); doc.add(field); } else if (SEntity.ANALYZED.equalsIgnoreCase(kind)) { Field field = new Field(fname, entity.getString(fname), Store.YES, Index.ANALYZED); doc.add(field); } } }
From source file:org.apache.solr.legacy.TestLegacyField.java
License:Apache License
public void testLegacyFloatField() throws Exception { Field fields[] = new Field[] { new LegacyFloatField("foo", 5f, Field.Store.NO), new LegacyFloatField("foo", 5f, Field.Store.YES) }; for (Field field : fields) { trySetByteValue(field);/*www . jav a2 s . co m*/ trySetBytesValue(field); trySetBytesRefValue(field); trySetDoubleValue(field); trySetIntValue(field); field.setFloatValue(6f); // ok trySetLongValue(field); trySetReaderValue(field); trySetShortValue(field); trySetStringValue(field); trySetTokenStreamValue(field); assertEquals(6f, field.numericValue().floatValue(), 0.0f); } }
From source file:org.apache.solr.legacy.TestLegacyField.java
License:Apache License
private void trySetFloatValue(Field f) { expectThrows(IllegalArgumentException.class, () -> { f.setFloatValue(Float.MAX_VALUE); });//w w w . j av a2 s. c o m }
From source file:suonos.lucene.fields.IndexedField.java
License:Apache License
public void setValue(Field field, Object value) { if (javaType == String.class) { field.setStringValue((String) value); } else if (javaType == Double.class) { field.setDoubleValue((Double) value); } else if (javaType == Float.class) { field.setFloatValue((Float) value); } else if (javaType == Integer.class) { field.setIntValue((Integer) value); } else if (javaType == Long.class) { field.setLongValue((Long) value); } else if (javaType == Boolean.class) { field.setStringValue(getBoolValue(value)); } else if (javaType == Date.class) { field.setLongValue(((Date) value).getTime()); } else if (javaType == Byte[].class) { field.setBytesValue((byte[]) value); }/* w w w.j av a 2 s .co m*/ throw Validate.notAllowed(""); }