@Override Field encodeField( String name, Value value ) { return new DoubleField( name, Values.coerceToDouble(value), NO ); }
/** {@inheritDoc} */ @Override public Optional<Field> indexedField(String name, Double value) { DoubleField doubleField = new DoubleField(name, value, STORE); doubleField.setBoost(boost); return Optional.of(doubleField); }
@Override public void addDoubleNumericField(double value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { final DoubleField numField = new DoubleField( name, value, getStore( store ) ); numField.setBoost( boost ); getLuceneDocument().add( numField ); }
private void addCluster(IndexWriter iwriter, StopCluster stopCluster) throws IOException { Document doc = new Document(); doc.add(new TextField("name", stopCluster.name, Field.Store.YES)); doc.add(new DoubleField("lat", stopCluster.lat, Field.Store.YES)); doc.add(new DoubleField("lon", stopCluster.lon, Field.Store.YES)); doc.add(new StringField("id", stopCluster.id, Field.Store.YES)); doc.add(new StringField("category", Category.CLUSTER.name(), Field.Store.YES)); iwriter.addDocument(doc); }
@Override public void addDoubleNumericField(double value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { final DoubleField numField = new DoubleField( name, value, getStore( store ) ); numField.setBoost( boost ); getLuceneDocument().add( numField ); }
public static IndexableField instantiateField( String key, Object value, FieldType fieldType ) { IndexableField field; if ( value instanceof Number ) { Number number = (Number) value; if ( value instanceof Long ) { field = new LongField( key, number.longValue(), Store.YES ); } else if ( value instanceof Float ) { field = new FloatField( key, number.floatValue(), Store.YES ); } else if ( value instanceof Double ) { field = new DoubleField( key, number.doubleValue(), Store.YES ); } else { field = new IntField( key, number.intValue(), Store.YES ); } } else { field = new Field( key, value.toString(), fieldType ); } return field; }
private void addCorner(IndexWriter iwriter, StreetVertex sv) throws IOException { String mainStreet = null; String crossStreet = null; // TODO score based on OSM street type, using intersection nodes instead of vertices. for (StreetEdge pse : Iterables.filter(sv.getOutgoing(), StreetEdge.class)) { if (mainStreet == null) mainStreet = pse.getName(); else crossStreet = pse.getName(); } if (mainStreet == null || crossStreet == null) return; if (mainStreet.equals(crossStreet)) return; Document doc = new Document(); doc.add(new TextField("name", mainStreet + " & " + crossStreet, Field.Store.YES)); doc.add(new DoubleField("lat", sv.getLat(), Field.Store.YES)); doc.add(new DoubleField("lon", sv.getLon(), Field.Store.YES)); doc.add(new StringField("category", Category.CORNER.name(), Field.Store.YES)); iwriter.addDocument(doc); }
private void addStop(IndexWriter iwriter, Stop stop) throws IOException { Document doc = new Document(); doc.add(new TextField("name", stop.getName(), Field.Store.YES)); if (stop.getCode() != null) { doc.add(new StringField("code", stop.getCode(), Field.Store.YES)); } doc.add(new DoubleField("lat", stop.getLat(), Field.Store.YES)); doc.add(new DoubleField("lon", stop.getLon(), Field.Store.YES)); doc.add(new StringField("id", stop.getId().toString(), Field.Store.YES)); doc.add(new StringField("category", Category.STOP.name(), Field.Store.YES)); iwriter.addDocument(doc); }
public static Field doubleField(String name, String value) { return new DoubleField(name, Double.parseDouble(value), Field.Store.NO); }
public Field field(String name, AbstractType type, ByteBuffer byteBufferValue, FieldType fieldType) { Object value = type.compose(byteBufferValue); return new DoubleField(name, ((Number) value).doubleValue(), fieldType); } }
public void addDoubleFieldToDocument(String fieldName, double doubleValue, Document document) { checkNotCompressed( fieldName ); DoubleField field = new DoubleField( fieldName, doubleValue, storeType != Store.NO ? Field.Store.YES : Field.Store.NO ); setBoost( field ); document.add( field ); }
public void addDoubleFieldToDocument(String fieldName, double doubleValue, Document document) { checkNotCompressed( fieldName ); DoubleField field = new DoubleField( fieldName, doubleValue, storeType != Store.NO ? Field.Store.YES : Field.Store.NO ); setBoost( field ); document.add( field ); }
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */ public Field[] createIndexableFields(Point point) { FieldType doubleFieldType = new FieldType(DoubleField.TYPE_NOT_STORED); doubleFieldType.setNumericPrecisionStep(precisionStep); Field[] f = new Field[2]; f[0] = new DoubleField(fieldNameX, point.getX(), doubleFieldType); f[1] = new DoubleField(fieldNameY, point.getY(), doubleFieldType); return f; }
public static Field createField(String fieldName, Object value, Field.Store store, Field.Index analyzed) { Field field = null; if (value instanceof Number) { Number number = (Number) value; if (value instanceof Long) { field = new LongField(fieldName, number.longValue(), store); } else if (value instanceof Float) { field = new FloatField(fieldName, number.floatValue(), store); } else if (value instanceof Double) { field = new DoubleField(fieldName, number.doubleValue(), store); } else { field = new IntField(fieldName, number.intValue(), store); } } else if (value instanceof Date) { field = new LongField(fieldName, ((Date) value).getTime(), store); } else { field = new Field(fieldName, value.toString(), store, analyzed); } return field; }
doc.add(new DoubleField(colName[i], new Double(row[i].toString()),Field.Store.YES));
@Override public Void visit(Node node) { Document document = new Document(); document.add(new Field("class", "node", classField)); document.add(new BinaryDocValuesField("class_value", class_nodeByteRef)); document.add(new Field("node.identity", String.valueOf(node.getId()), classField)); document.add(new NumericDocValuesField("node.identity_value", node.getId())); if (node.isLoaded()) { document.add(new DoubleField("node.latitude", node.getLatitude(), coordinateDoubleField)); document.add(new DoubleField("node.longitude", node.getLongitude(), coordinateDoubleField)); } else if (log.isInfoEnabled()) { log.info("Indexing node " + node.getId() + " which has not been loaded. Coordinates will not be searchable."); } addObjectFields(node, document); try { indexWriter.updateDocument(new Term("node.identity", String.valueOf(node.getId())), document); } catch (IOException e) { throw new RuntimeException(e); } return null; }
private org.apache.lucene.index.IndexableField buildDoubleField( StoreField field) { return new DoubleField(field.getName(), (Double) field.getValue(), field.isStored() ? Store.YES : Store.NO); }
public void addDocumentField(Document tmp, JsonElement jsonValue) { if ( jsonValue == null || jsonValue.isJsonNull() ) { return; } switch ( fieldType ) { case INTEGER: tmp.add( new IntField( absoluteName, jsonValue.getAsInt(), Store.NO ) ); break; case LONG: tmp.add( new LongField( absoluteName, jsonValue.getAsLong(), Store.NO ) ); break; case FLOAT: tmp.add( new FloatField( absoluteName, jsonValue.getAsFloat(), Store.NO ) ); break; case DOUBLE: tmp.add( new DoubleField( absoluteName, jsonValue.getAsDouble(), Store.NO ) ); break; case UNKNOWN_NUMERIC: throw LOG.unexpectedNumericEncodingType( rootTypeMetadata.getType(), absoluteName ); case BOOLEAN: tmp.add( new StringField( absoluteName, String.valueOf( jsonValue.getAsBoolean() ), Store.NO ) ); break; default: tmp.add( new StringField( absoluteName, jsonValue.getAsString(), Store.NO ) ); break; } }
public void addDocumentField(Document tmp, JsonElement jsonValue) { if ( jsonValue == null || jsonValue.isJsonNull() ) { return; } switch ( fieldType ) { case INTEGER: tmp.add( new IntField( absoluteName, jsonValue.getAsInt(), Store.NO ) ); break; case LONG: tmp.add( new LongField( absoluteName, jsonValue.getAsLong(), Store.NO ) ); break; case FLOAT: tmp.add( new FloatField( absoluteName, jsonValue.getAsFloat(), Store.NO ) ); break; case DOUBLE: tmp.add( new DoubleField( absoluteName, jsonValue.getAsDouble(), Store.NO ) ); break; case UNKNOWN_NUMERIC: throw LOG.unexpectedNumericEncodingType( rootTypeMetadata.getType(), absoluteName ); case BOOLEAN: tmp.add( new StringField( absoluteName, String.valueOf( jsonValue.getAsBoolean() ), Store.NO ) ); break; default: tmp.add( new StringField( absoluteName, jsonValue.getAsString(), Store.NO ) ); break; } }
public static Field field(String name, Properties properties, String value, FieldType fieldType) { Type type = properties.getType(); if (type == Type.integer) { return new IntField(name, Integer.parseInt(value), fieldType); } else if (type == Type.bigint) { return new LongField(name, Long.parseLong(value), fieldType); } else if (type == Type.bigdecimal) { return new DoubleField(name, Double.parseDouble(value), fieldType); } else if (type == Type.decimal) { return new FloatField(name, Float.parseFloat(value), fieldType); } else if (type == Type.date) { //TODO - set correct locale FormatDateTimeFormatter formatter = Dates.forPattern(value, Locale.US); return new LongField(name, formatter.parser().parseMillis(value), fieldType); } else if (type == Type.bool) { Boolean val = Boolean.parseBoolean(value); return new Field(name, val.toString(), fieldType); } else { return new Field(name, value, fieldType); } }