当对ApacheLucenev7.5进行基准测试时,我注意到了一种奇怪的行为:我使用Lucene和SimpleAnalyzer (没有停止,没有词干)将英语维基百科转储(5,677,776个文档)编入索引。
然后,我使用以下查询搜索索引:
布尔查询的结果号when 都大于单项的结果号和单项who的结果号,当结果号应该小于两者时。
有什么解释吗?
代码片段:
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));发布于 2018-11-25 21:40:30
其解释是OR而不是您假设的AND。搜索the who将返回具有the或who或两者的文档。
the - 5,382,873
who - 1,687,254
the OR who - 5,411,305也就是说,大多数包含who的文档也包含the,除了在检索这两个文档时添加到结果集中的28432个文档之外。
可以通过更改默认运算符来更改此行为:
parser.setDefaultOperator(QueryParserBase.AND_OPERATOR)https://stackoverflow.com/questions/53435939
复制相似问题