mirror of https://github.com/apache/lucene.git
LUCENE-7493: FacetCollector.search now accepts limit=0, for getting facets but not search hits
This commit is contained in:
parent
e8360714fa
commit
739981b6c8
|
@ -89,6 +89,9 @@ Bug Fixes
|
|||
* LUCENE-6914: Fixed DecimalDigitFilter in case of supplementary code points.
|
||||
(Hossman)
|
||||
|
||||
* LUCENE-7493: FacetCollector.search threw an unexpected exception if
|
||||
you asked for zero hits but wanted facets (Mahesh via Mike McCandless)
|
||||
|
||||
Improvements
|
||||
|
||||
* LUCENE-7439: FuzzyQuery now matches all terms within the specified
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.lucene.search.TopDocsCollector;
|
|||
import org.apache.lucene.search.TopFieldCollector;
|
||||
import org.apache.lucene.search.TopFieldDocs;
|
||||
import org.apache.lucene.search.TopScoreDocCollector;
|
||||
import org.apache.lucene.search.TotalHitCountCollector;
|
||||
import org.apache.lucene.util.ArrayUtil;
|
||||
import org.apache.lucene.util.BitDocIdSet;
|
||||
import org.apache.lucene.util.FixedBitSet;
|
||||
|
@ -251,23 +252,32 @@ public class FacetsCollector extends SimpleCollector implements Collector {
|
|||
+ after.doc + " limit=" + limit);
|
||||
}
|
||||
|
||||
TopDocsCollector<?> hitsCollector;
|
||||
if (sort != null) {
|
||||
if (after != null && !(after instanceof FieldDoc)) {
|
||||
// TODO: if we fix type safety of TopFieldDocs we can
|
||||
// remove this
|
||||
throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
|
||||
}
|
||||
boolean fillFields = true;
|
||||
hitsCollector = TopFieldCollector.create(sort, n,
|
||||
(FieldDoc) after,
|
||||
fillFields,
|
||||
doDocScores,
|
||||
doMaxScore);
|
||||
TopDocs topDocs = null;
|
||||
if (n==0) {
|
||||
TotalHitCountCollector totalHitCountCollector = new TotalHitCountCollector();
|
||||
searcher.search(q, MultiCollector.wrap(totalHitCountCollector, fc));
|
||||
topDocs = new TopDocs(totalHitCountCollector.getTotalHits(), new ScoreDoc[0], Float.NaN);
|
||||
} else {
|
||||
hitsCollector = TopScoreDocCollector.create(n, after);
|
||||
TopDocsCollector<?> hitsCollector;
|
||||
if (sort != null) {
|
||||
if (after != null && !(after instanceof FieldDoc)) {
|
||||
// TODO: if we fix type safety of TopFieldDocs we can
|
||||
// remove this
|
||||
throw new IllegalArgumentException("after must be a FieldDoc; got " + after);
|
||||
}
|
||||
boolean fillFields = true;
|
||||
hitsCollector = TopFieldCollector.create(sort, n,
|
||||
(FieldDoc) after,
|
||||
fillFields,
|
||||
doDocScores,
|
||||
doMaxScore);
|
||||
} else {
|
||||
hitsCollector = TopScoreDocCollector.create(n, after);
|
||||
}
|
||||
searcher.search(q, MultiCollector.wrap(hitsCollector, fc));
|
||||
|
||||
topDocs = hitsCollector.topDocs();
|
||||
}
|
||||
searcher.search(q, MultiCollector.wrap(hitsCollector, fc));
|
||||
return hitsCollector.topDocs();
|
||||
return topDocs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -182,6 +182,17 @@ public class TestDrillDownQuery extends FacetTestCase {
|
|||
assertEquals(10, docs.totalHits);
|
||||
}
|
||||
|
||||
public void testZeroLimit() throws IOException {
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
DrillDownQuery q = new DrillDownQuery(config);
|
||||
q.add("b", "1");
|
||||
int limit = 0;
|
||||
FacetsCollector facetCollector = new FacetsCollector();
|
||||
FacetsCollector.search(searcher, q, limit, facetCollector);
|
||||
Facets facets = getTaxonomyFacetCounts(taxo, config, facetCollector, config.getDimConfig("b").indexFieldName);
|
||||
assertNotNull(facets.getTopChildren(10, "b"));
|
||||
}
|
||||
|
||||
public void testScoring() throws IOException {
|
||||
// verify that drill-down queries do not modify scores
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
|
|
Loading…
Reference in New Issue