如题,我用Lucene2.3 和3.4 分别生成了一个索引,索引方式及内容都完全相同,可是索引时间lucene3.4竟然慢了一倍左右,应该是索引速度更快才对啊,(搜索的时候速度快了是原来的50%左右),那位大侠帮我看看问题到底出哪儿了?
还有生成的索引也变大了,难道Lucene高版本的就是这样的吗?
大家在用lucene的时候,高版本和低版本对比的话,索引和搜索性能提升了多少啊?
Lucene2.3 的代码:
public static void main(String args[]) throws Exception {
long a = System.currentTimeMillis();
IndexWriter writer = new IndexWriter("index", new KeywordAnalyzer(),
true);
writer.setMergeFactor(1024);
Document doc = null;
for (int i = 0; i < 50000; i++) {
doc = new Document();
doc.add(new Field("id", "wo" + i, Field.Store.YES,
Field.Index.TOKENIZED));
writer.addDocument(doc);
}
writer.optimize();
writer.close();
long b = System.currentTimeMillis();
System.out.println("time:" + (b - a) + "ms");
}
Lucene 3.4 代码:
public static void main(String args[]) throws Exception {
long a = System.currentTimeMillis();
Directory dir = FSDirectory.open(new File("index"));
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_34,
new KeywordAnalyzer());
conf.setOpenMode(OpenMode.CREATE);
LogByteSizeMergePolicy mp = new LogByteSizeMergePolicy();
mp.setMergeFactor(1024);
conf.setMergePolicy(mp);
IndexWriter writer = new IndexWriter(dir, conf);
Document doc = null;
for (int i = 0; i < 50000; i++) {
doc = new Document();
doc.add(new Field("id", "wo" + i, Field.Store.YES,
Field.Index.ANALYZED));
writer.addDocument(doc);
}
writer.optimize();
writer.close();
long b = System.currentTimeMillis();
System.out.println("time:" + (b - a) + "ms");
}
谢谢~~
用Lucene本来就是用空间换时间的做法,只要搜索时快,建索引慢点也没什么关系
3.4版修改了一些bug并做了优化和改进,建索引慢的原因可能是对索引文件进行了进一步优化存储
谢谢您的回答.
我用3.4去搜索2.3生成的索引,速度和3.4去搜3.4生成的索引差不多,这个能否说明3.4的搜索模块确实比2.3优化了许多,但是索引方面的优化就没有体现出来.
所以,还是觉得那些地方不对劲儿,但我也不知道,呵呵,对上面说的这种现象您有何高见呢?
@printlner: 这个没具体测过
@artwl: 谢谢~