我用TestRegexpQuery在Lucene的这个单元测试工作,一切都运行得很好,但是当我增加了一些额外的打印语句,我不明白为什么它不返回文档本身。Lucene的空车返回正则表达式搜索结果
private int regexQueryNrHits(String regex) throws IOException {
// RegexpQuery query = new RegexpQuery(newTerm(regex));
// return searcher.search(query, 5).totalHits;
RegexpQuery query = new RegexpQuery(newTerm(regex));
TopDocs result = searcher.search(query, 5);
// my code to print the result instead of just the counts
//START
ScoreDoc[] docs = result.scoreDocs;
for (ScoreDoc scoreDoc : docs) {
System.out.println(scoreDoc);
System.out.println(scoreDoc.doc);
System.out.println(scoreDoc.score);
System.out.println(scoreDoc.shardIndex);
System.out.println(searcher.getIndexReader().document(scoreDoc.doc));
}
System.out.println("---------");
// end
return result.totalHits;
}
这个测试只插入一个文档,这是胜负的样子,我希望它返回无论是句子或匹配的正则表达式,但一切看起来空文件的标记..
---------
doc=0 score=1.0 shardIndex=0
0
1.0
0
Document<>
---------
doc=0 score=1.0 shardIndex=0
0
1.0
0
Document<>
任何人都可以帮助我理解结果中究竟发生了什么?