在对 Apache Lucene v7.5 进行基准测试时,我注意到一个奇怪的行为:我使用 Lucene 和 SimpleAnalyzer(没有停用词,没有词干)索引了英文维基百科转储(5,677,776 个文档)
然后我使用以下查询搜索索引:
对于布尔查询结果数量的谁是既比单项结果数量较大的,为单一期限的结果数谁,当它应该比都较小。
对此有解释吗?
代码片段:
analyzer = new SimpleAnalyzer();
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"title", "content","domain","url"},analyzer);
// Parse
Query q = parser.parse(querystr);
// top-10 results
int hitsPerPage = 10;
IndexReader indexReader = DirectoryReader.open(index);
IndexSearcher searcher = new IndexSearcher(indexReader);
// Ranker
TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage);
// Search
searcher.search(q, collector);
// Retrieve the top-10 documents
TopDocs topDocs=collector.topDocs();
ScoreDoc[] hits = topDocs.scoreDocs;
totalHits=topDocs.totalHits;
System.out.println("query: "+querystr + " " + hits.length+" "+String.format("%,d",totalHits));
解释是默认运算符是OR
而不是AND
您假设的。搜索the who
具有或者返回文件the
或who
或两者兼而有之。
the - 5,382,873
who - 1,687,254
the OR who - 5,411,305
即大多数包含 的文档who
也包含the
,除了 28 432 个文档,当您检索它们时添加到结果集中。
您可以通过更改默认运算符来更改此行为:
parser.setDefaultOperator(QueryParserBase.AND_OPERATOR)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句