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; }
doc.add(new LongField(FieldNames.STORAGE_FILE_OFFSET, record.getStorageByteOffset(), Store.YES)); } else { doc.add(new IntField(FieldNames.BLOCK_INDEX, blockIndex, Store.YES)); doc.add(new LongField(SearchableFields.Identifier.getSearchableFieldName(), record.getEventId(), Store.YES));
protected void addDocumentLength(Document document, String docLengthFieldName, FieldType docLengthFieldType, int documentLength) { document.add(new IntField(docLengthFieldName, documentLength, docLengthFieldType)); }
/** {@inheritDoc} */ @Override public Optional<Field> indexedField(String name, Integer value) { IntField intField = new IntField(name, value, STORE); intField.setBoost(boost); return Optional.of(intField); }
public Field field(String name, AbstractType type, ByteBuffer byteBufferValue, FieldType fieldType) { Object value = type.compose(byteBufferValue); return new IntField(name, (Integer) value, fieldType); } }
public static Field newDepthField(String path){ return new IntField(FieldNames.PATH_DEPTH, PathUtils.getDepth(path), NO); }
public static Field newDepthField(String path){ return new IntField(FieldNames.PATH_DEPTH, PathUtils.getDepth(path), NO); }
public void addIntFieldToDocument(String fieldName, int intValue, Document document) { checkNotCompressed( fieldName ); IntField field = new IntField( fieldName, intValue, storeType != Store.NO ? Field.Store.YES : Field.Store.NO ); setBoost( field ); document.add( field ); }
public void addIntFieldToDocument(String fieldName, int intValue, Document document) { checkNotCompressed( fieldName ); IntField field = new IntField( fieldName, intValue, storeType != Store.NO ? Field.Store.YES : Field.Store.NO ); setBoost( field ); document.add( field ); }
public void addToLuceneDoc(Document doc) { for (ComplexFieldProperty p : properties.values()) { p.addToLuceneDoc(doc, fieldName, start, end); } // Add number of tokens in complex field as a stored field, // because we need to be able to find this property quickly // for SpanQueryNot. // (Also note that this is the actual number of words + 1, // because we always store a dummy "closing token" at the end // that doesn't contain a word but may contain trailing punctuation) doc.add(new IntField(ComplexFieldUtil.lengthTokensField(fieldName), numberOfTokens(), Field.Store.YES)); }
@Override public void addIntNumericField(int value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { final IntField numField = new IntField( name, value, getStore( store ) ); numField.setBoost( boost ); getLuceneDocument().add( numField ); }
@Override public void addIntNumericField(int value, String name, int precisionStep, SerializableStore store, boolean indexed, float boost, boolean omitNorms, boolean omitTermFreqAndPositions) { final IntField numField = new IntField( name, value, getStore( store ) ); numField.setBoost( boost ); getLuceneDocument().add( numField ); }
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; }
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { int pmid = BlueCasUtil.getHeaderIntDocId(jCas); if (!BlueCasUtil.isEmptyText(jCas)) { // System.out.println("indexing:: " + pmid); Document doc = new Document(); doc.add(new IntField(PMID_FIELD, pmid, Store.YES)); doc.add(new TextField(CONTENT_FIELD, jCas.getDocumentText(), Store.YES)); doc.add(new TextField(TITLE_FIELD, getTitle(jCas), Store.YES)); try { indexWriter.addDocument(doc); } catch (IOException e) { throw new AnalysisEngineProcessException(e); } } }
private org.apache.lucene.index.IndexableField buildIntField( StoreField field) { return new IntField(field.getName(), (Integer) field.getValue(), field.isStored() ? Store.YES : Store.NO); }
private void indexTestDocuments(Directory directory) throws IOException { IndexWriterConfig indexWriterConfig = new IndexWriterConfig( new StandardAnalyzer() ); indexWriterConfig.setOpenMode( IndexWriterConfig.OpenMode.CREATE ); IndexWriter indexWriter = new IndexWriter( directory, indexWriterConfig ); Document document = new Document(); document.add( new StringField( "stringField", "test", Field.Store.NO ) ); document.add( new IntField( "intField", 0, Field.Store.NO ) ); indexWriter.addDocument( document ); indexWriter.commit(); indexWriter.close(); }
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); } }
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; } }
private Document buildDocumentWithNumericFields() { Document doc = new Document(); Field numField = new DoubleField( "double", 23d, Store.NO ); doc.add( numField ); numField = new IntField( "int", 23, Store.NO ); doc.add( numField ); numField = new FloatField( "float", 2.3f, Store.NO ); doc.add( numField ); numField = new LongField( "long", 23L, Store.NO ); doc.add( numField ); return doc; }