【发布时间】:2010-07-01 22:46:37
【问题描述】:
我正在处理在另一个索引中构建流行术语索引的遗留代码。没有单元测试,索引过程很痛苦,因为第一个索引需要很长时间才能构建。
我想以不同的方式构建第二个(流行词)索引。是否有测试 Lucene 索引是否正确创建的最佳实践?
编辑>> 根据@Pascal 的建议,我使用的是 RAMDirectory,然后为了测试我刚刚编写的索引,我设置了一个 indexReader 并遍历术语结果,打印出每个术语确保数据看起来没问题。
代码:
IndexReader reader = IndexReader.open(dir2);
TermEnum terms = reader.terms();
System.out.println("Here come the terms!");
while (terms.next()){
if (terms.term().field().equals("FULLTEXT")){
System.out.println(terms.term());
}
}
int numDocs = reader.maxDoc();
System.out.println("Number of Docs: " + numDocs);
如果索引真的很大,我让它运行一段时间,然后中途停止。
另外,Luke 是检查索引的好工具,如果您想更彻底...我只是在寻找快速的东西。
欢迎任何其他想法!
【问题讨论】:
标签: unit-testing junit lucene legacy-code