[英]Lucene 3.6 IndexWriter
Currently I'm working with Lucene 3.6 and am having difficulty getting IndexWriters to work. 目前,我正在使用Lucene 3.6,并且很难使IndexWriters正常工作。
The API documents suggest that: API文档建议:
IndexWriter writer = new IndexWriter(Directory, Analyzer);
(and a few other similar constructors)is depreciated and that I should use something like: (以及其他一些类似的构造函数)已贬值,我应该使用类似以下内容:
IndexWriter writer = new IndexWriter(Directory, Configuration);
However eclipse won't recognize this newer constructor (lucene-core3.6.jar is added to the build path of my project) and if I use an older constructor I have to suppress a warning (which I don't especially want to do - an exception gets thrown when I index in memory with these older methods). 但是eclipse无法识别这个较新的构造函数(将lucene-core3.6.jar添加到我的项目的构建路径中),如果我使用较旧的构造函数,则必须禁止显示警告(我特别不想这样做) -当我使用这些较旧的方法在内存中建立索引时,将引发异常。
I've cleaned the project, but the problem still persists. 我已经清理了项目,但是问题仍然存在。
EDIT: The code I am using: 编辑:我正在使用的代码:
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);
A good beginning is always reading at the javadoc: 一个好的开始总是在阅读javadoc:
http://lucene.apache.org/core/3_6_0/api/all/index.html http://lucene.apache.org/core/3_6_0/api/all/index.html
Constructors 建设者
Constructor and Description 构造函数和描述
IndexWriter(Directory d, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy, IndexWriter.MaxFieldLength mfl) Deprecated. 不推荐使用IndexWriter(目录d,分析器a,布尔创建,IndexDeletionPolicy deletePolicy,IndexWriter.MaxFieldLength mfl)。 use IndexWriter(Directory, IndexWriterConfig) instead 使用IndexWriter(Directory,IndexWriterConfig)代替
IndexWriter(Directory d, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl) Deprecated. IndexWriter(Directory d,Analyzer a,boolean create,IndexWriter.MaxFieldLength mfl)已弃用。 use IndexWriter(Directory, IndexWriterConfig) instead 使用IndexWriter(Directory,IndexWriterConfig)代替
IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, IndexWriter.MaxFieldLength mfl) Deprecated. 不推荐使用IndexWriter(目录d,分析器a,IndexDeletionPolicy deletePolicy,IndexWriter.MaxFieldLength mfl)。 use IndexWriter(Directory, IndexWriterConfig) instead 使用IndexWriter(Directory,IndexWriterConfig)代替
IndexWriter(Directory d, Analyzer a, IndexDeletionPolicy deletionPolicy, IndexWriter.MaxFieldLength mfl, IndexCommit commit) Deprecated. 不推荐使用IndexWriter(目录d,分析器a,IndexDeletionPolicy deletePolicy,IndexWriter.MaxFieldLength mfl,IndexCommit提交)。 use IndexWriter(Directory, IndexWriterConfig) instead 使用IndexWriter(Directory,IndexWriterConfig)代替
IndexWriter(Directory d, Analyzer a, IndexWriter.MaxFieldLength mfl) Deprecated. 不推荐使用IndexWriter(目录d,分析器a,IndexWriter.MaxFieldLength mfl)。 use IndexWriter(Directory, IndexWriterConfig) instead 使用IndexWriter(Directory,IndexWriterConfig)代替
IndexWriter(Directory d, IndexWriterConfig conf) Constructs a new IndexWriter per the settings given in conf. IndexWriter(Directory d,IndexWriterConfig conf)根据conf中提供的设置构造一个新的IndexWriter。
Not suprisingly, you are using a deprecated constructor and Eclipse correctly emit a warning. 不出所料,您正在使用不推荐使用的构造函数,并且Eclipse会正确发出警告。 If you use the last constructor, I am sure Eclipse won't emit a warning. 如果使用最后一个构造函数,那么我确信Eclipse不会发出警告。
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. StandardAnalyzer的构造函数采用Version对象。 Perhaps Eclipse does not recognize the IndexWriter constructor because there is a compile-time error at an earlier line (ie when you try to create a new StandardAnalyzer). 也许Eclipse无法识别IndexWriter构造函数,因为在较早的一行(即,当您尝试创建新的StandardAnalyzer时)存在编译时错误。
I solved the problem: 我解决了这个问题:
There was a .jar file interfering with lucene (thirdparty-all.jar) which I found through looking at the stack trace. 我通过查看堆栈跟踪发现了一个.luc文件干扰lucene(thirdparty-all.jar)。 Removing the .jar removed problem. 删除.jar已删除的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.