以下是代码:
protected Document getDocument(File f) throws Exception {
Document doc = new Document();
doc.add(new Field("contents", new FileReader(f),Field.TermVector.WITH_POSITIONS_OFFSETS));
FileReader fr = new FileReader(f);
doc.add(new Field("filename", f.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED));
doc.add(new Field("fullpath", f.getCanonicalPath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
return doc;
}
我将版本从3.6更改为4.0。所以有一些方法已被弃用。 例如: doc.add(new Field)不推荐使用Field。 Field.TermVector不推荐使用TremVector。而且Field.Index索引也已弃用。
答案 0 :(得分:0)
在Field
documentation中,他们列出了一组要了解的字段子类:
大多数用户应该使用糖的一个子类:IntField,LongField,FloatField,DoubleField,ByteDocValuesField,ShortDocValuesField,IntDocValuesField,LongDocValuesField,PackedLongDocValuesField,FloatDocValuesField,DoubleDocValuesField,SortedBytesDocValuesField,DerefBytesDocValuesField,StraightBytesDocValuesField,StringField,文本字段,StoredField
特别是,对于您列出的字段,您会发现TextField
和StringField
很有用。
The Migration Guide提供了有关4.0更改的更多信息。