抱歉标题含糊。这是我的问题。我正在使用以下代码从 lucene 搜索中检索结果
scoreDoc[] hits = results.scoreDocs;
int numTotalHits = results.totalHits;
for (int i = 0; i < numTotalHits; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println(i+":File name is: "+d.get("filename"));
System.out.println(i+":File content is: "+d.get("contents"));
}
现在这段代码有时会弹出一个异常,指出索引超出数组边界。所以我使用了下面的代码,它不会导致任何异常
scoreDoc[] hits = results.scoreDocs;
int numTotalHits = results.totalHits;
for (int i = 0; i < numTotalHits-1; i++) {
int docId = hits[i].doc;
Document d = searcher.doc(docId);
System.out.println(i+":File name is: "+d.get("filename"));
System.out.println(i+":File content is: "+d.get("contents"));
}
这是否意味着results.totalHits
返回results.totalHits-2
搜索结果的数量?
谢谢你..