我正在使用Lucene 5.3來索引一組文檔,並使用BooleanQuery
,其中查詢中的每個術語都被某個分數提升。爲什麼lucene不會返回索引中的所有文檔?
我的問題是,當我搜索索引時,我得到的文檔數量少於點擊數,而我的索引數量很少。
System.out.println("docs in the index = " + reader.numDocs());
//e.g., docs in the index = 92
TopDocs topDocs = indexSearcher.search(q, reader.numDocs()); //this ensures no result is omitted from the search.
ScoreDoc[] hits = topDocs.scoreDocs;
System.out.println("results found: " + topDocs.totalHits)
//e.g., results found: 44
這種行爲的原因是什麼? lucene是否忽略零分的文檔?
如何獲得索引中的所有文檔,無論他們擁有什麼分數?
你是否期待這個查詢匹配索引中的所有文檔?或者是否希望它返回所有文檔,而不管它們是否與查詢匹配? – femtoRgon
我想返回所有文檔。然後,我會根據分數對它們進行排名,因此不匹配的文檔將成爲底部。 – KillBill
@KillBill查看IndexSearcher :: search中的代碼(Weight weight,ScoreDoc after,int nDocs)可能有可能無法根據maxScore返回文檔:return new TopDocs(totalHits,scoreDocs,maxScore);所以我會使用TopDocs searchAfter(ScoreDoc after,Query query,int n)。 –