【问题标题】:How to change the code in Lucene 4.0 [duplicate]如何更改 Lucene 4.0 中的代码 [重复]
【发布时间】:2014-03-26 00:14:31
【问题描述】:

代码如下:

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.TermVector TremVector 已弃用。而 Field.Index Index 也已弃用。

【问题讨论】:

  • 发行说明记录了您需要做的事情。

标签: java lucene


【解决方案1】:

Field documentation 中,他们列出了一组值得了解的 Field 子类:

大多数用户应该使用其中一种糖子类:IntField、LongField、FloatField、DoubleField、ByteDocValuesField、ShortDocValuesField、IntDocValuesField、LongDocValuesField、PackedLongDocValuesField、FloatDocValuesField、DoubleDocValuesField、SortedBytesDocValuesField、DerefBytesDocValuesField、StraightBytesDocValuesField、StringField、TextField、StoredField。

特别是,您会发现TextFieldStringField 对于您列出的字段很有用。

The Migration Guide 有更多关于 4.0 变化的信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 2023-04-07
    • 2021-09-21
    • 2018-03-07
    • 2019-11-12
    • 2023-03-21
    • 2018-02-11
    相关资源
    最近更新 更多