[lucene] 关于lucene 创建索引IndexWriter

lyj552041 2010-09-01
package com.puppet.util;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.util.Version;
import org.apache.lucene.analysis.standard.StandardAnalyzer;

public class IndexProcess {
private String INDEX_STORE_PATH="";

public void createIndex(String inputDir){
try {
IndexWriter writer= new IndexWriter(INDEX_STORE_PATH,new StandardAnalyzer(Version.LUCENE_CURRENT),true,IndexWriter.MAX_TERM_LENGTH);
} catch (Exception e) {
e.printStackTrace();
}

}
}



上面红色行一直报错,说没有这个构造函数。
error:The constructor IndexWriter(String,StandardAnalyzer,boolea,int) id undefined

换成这样也不行。

IndexWriter writer= new IndexWriter(INDEX_STORE_PATH,new StandardAnalyzer(),true);

我用的包是3.0的

我刚学,麻烦各位大大帮忙解决下。
viruscamp 2010-09-01
IndexWriter(Directory d, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl)
          Constructs an IndexWriter for the index in d.

http://lucene.apache.org/java/3_0_2/api/all/org/apache/lucene/index/IndexWriter.html#IndexWriter(org.apache.lucene.store.Directory, org.apache.lucene.analysis.Analyzer, boolean, org.apache.lucene.index.IndexWriter.MaxFieldLength)

3的构造函数和2不同,目录参数不能是String,必须是Directory类型的
最后一个参数MaxFieldLength不是int的,是自定义的类型
viruscamp 2010-09-01
Directory 参数一般这样取得
Directory dir = FSDirectory.open("d:\index\");
lyj552041 2010-09-01
大哥,你牛。我参照你的回复重新写过了,果然不再报错了。现在网上的一些学习资料都是2.0的,误导人。谢谢!
fengjia10 2010-09-03
我的回复给和谐掉了,je上有bug哈
lyj552041 2010-09-03
呃,不会吧哥,一定是你发了不和谐的内容啦啦队。
Global site tag (gtag.js) - Google Analytics