繁体   English   中英

lucene为什么不返回索引中的所有文档?

[英]why lucene doesn't return all the documents in the index?

我正在使用Lucene 5.3对一组文档建立索引,并使用BooleanQuery ,其中查询中的每个术语都会提高一些分数。

我的问题是,当我搜索索引时,命中的文档数量少于索引中的文档数量。

    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是否会忽略零分的文档?

无论分数如何,如何获取索引中的所有文档?

Lucene将仅返回与查询实际匹配的结果。 如果要获取所有文档作为结果,则需要确保它们都匹配。 您可以使用MatchAllDocsQuery做到这一点:

Query query = new BooleanQuery.Builder()
        .add(new BooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST))
        .add(new BooleanClause(myOldQuery, BooleanClause.Occur.SHOULD))
        .build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM