1

目前我正在使用 Lucene 3.6,并且很难让 IndexWriters 工作。

API 文档建议:

IndexWriter writer = new IndexWriter(Directory, Analyzer);

(以及其他一些类似的构造函数)已被贬值,我应该使用类似的东西:

IndexWriter writer = new IndexWriter(Directory, Configuration);

但是 Eclipse 不会识别这个较新的构造函数(lucene-core3.6.jar 已添加到我的项目的构建路径中),如果我使用较旧的构造函数,我必须抑制警告(我不是特别想这样做- 当我使用这些旧方法在内存中建立索引时会引发异常)。

我已经清理了项目,但问题仍然存在。

编辑:我正在使用的代码:

        Directory index = new RAMDirectory();
    StandardAnalyzer analyzer = new StandardAnalyzer();
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_36, analyzer);
    IndexDeletionPolicy IndexDeletionPolicy = new KeepOnlyLastCommitDeletionPolicy();
    MaxFieldLength fieldLength = new MaxFieldLength(256);
    IndexWriter writer = new IndexWriter(index, analyzer, false, IndexDeletionPolicy, fieldLength);
    //IndexWriter writer = new IndexWriter(index, config); 
    writer.setUseCompoundFile(false);
4

3 回答 3

1

一个好的开始总是阅读 javadoc:

http://lucene.apache.org/core/3_6_0/api/all/index.html

构造函数

构造函数和描述

  • IndexWriter(Directory d, Analyzer a, boolean create, IndexDeletionPolicy deletePolicy, IndexWriter.MaxFieldLength mfl) 已弃用。改用 IndexWriter(Directory, IndexWriterConfig)

  • IndexWriter(Directory d, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) 已弃用。改用 IndexWriter(Directory, IndexWriterConfig)

  • IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletePolicy, IndexWriter.MaxFieldLength mfl) 已弃用。改用 IndexWriter(Directory, IndexWriterConfig)

  • IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletePolicy, IndexWriter.MaxFieldLength mfl, IndexCommit commit) 已弃用。改用 IndexWriter(Directory, IndexWriterConfig)

  • IndexWriter(Directory d, Analyzer a, IndexWriter.MaxFieldLength mfl) 已弃用。改用 IndexWriter(Directory, IndexWriterConfig)

  • IndexWriter(Directory d, IndexWriterConfig conf) Constructs a new IndexWriter per the settings given in conf.

Not suprisingly, you are using a deprecated constructor and Eclipse correctly emit a warning. If you use the last constructor, I am sure Eclipse won't emit a warning.

于 2012-07-11T15:35:03.723 回答
0

You might want to change:

StandardAnalyzer analyzer = new StandardAnalyzer();

to:

StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);

The constructor of StandardAnalyzer takes a Version object. Perhaps Eclipse does not recognize the IndexWriter constructor because there is a compile-time error at an earlier line (i.e. when you try to create a new StandardAnalyzer).

于 2012-07-11T17:28:26.367 回答
0

I solved the problem:

There was a .jar file interfering with lucene (thirdparty-all.jar) which I found through looking at the stack trace. Removing the .jar removed problem.

于 2012-07-13T10:08:14.133 回答