[英]Print words in the index - Lucene
我对Lucene非常陌生,正在使用Lucene 4.10.4。 为了澄清起见,我尝试打印在搜索过程中从索引读取的所有lucene单词。 我试图根据搜索字符串来理解Lucene跳过索引中所有单词的内容。 我尝试在某些Lucene类中使用print语句来打印单词。 但这没有用。 在哪里可以使用打印声明?
这样的事情应该为您工作。 此代码将打开Lucene索引并遍历所有字段并列出所有术语。 您可以在此处轻松跳过不需要的字段
IndexReader reader = DirectoryReader.open(dir);
final Fields fields = MultiFields.getFields(reader);
final Iterator<String> iterator = fields.iterator();
while(iterator.hasNext()) {
final String field = iterator.next();
final Terms terms = MultiFields.getTerms(reader, field);
final TermsEnum it = terms.iterator(null);
BytesRef term = it.next();
while (term != null) {
System.out.println(term.utf8ToString());
term = it.next();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.