SOLR-7452: add support for refining missing allBuckets

This commit is contained in:
yonik 2017-04-06 09:29:29 -04:00
parent ad1326698d
commit 53aeffade5
3 changed files with 40 additions and 3 deletions

View File

@ -177,9 +177,11 @@ public class FacetFieldMerger extends FacetRequestSortedMerger<FacetField> {
if (freq.missing) {
refinement = getRefinementSpecial(mcontext, refinement, tagsWithPartial, missingBucket, "missing");
}
/** allBuckets does not execute sub-facets because we don't change the domain. We may need refinement info in the future though for stats.
if (freq.allBuckets) {
refinement = getRefinementSpecial(mcontext, refinement, tagsWithPartial, allBuckets, "allBuckets");
}
**/
}
return refinement;
}

View File

@ -24,6 +24,8 @@ import org.apache.lucene.util.BytesRefBuilder;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.schema.SchemaField;
import static org.apache.solr.search.facet.FacetContext.SKIP_FACET;
/**
* Base class for DV/UIF accumulating counts into an array by ordinal. It's
* for {@link org.apache.lucene.index.SortedDocValues} and {@link org.apache.lucene.index.SortedSetDocValues} only.
@ -57,8 +59,14 @@ abstract class FacetFieldProcessorByArray extends FacetFieldProcessor {
}
private SimpleOrderedMap<Object> calcFacets() throws IOException {
SimpleOrderedMap<Object> refineResult = null;
boolean skipThisFacet = (fcontext.flags & SKIP_FACET) != 0;
if (fcontext.facetInfo != null) {
return refineFacets();
refineResult = refineFacets();
// if we've seen this facet bucket, then refining can be done. If we haven't, we still
// only need to continue if we need allBuckets or numBuckets info.
if (skipThisFacet || (!freq.allBuckets && !freq.numBuckets)) return refineResult;
}
String prefix = freq.prefix;
@ -71,6 +79,20 @@ abstract class FacetFieldProcessorByArray extends FacetFieldProcessor {
findStartAndEndOrds();
if (refineResult != null) {
if (freq.allBuckets) {
createAccs(nDocs, 1);
allBucketsAcc = new SpecialSlotAcc(fcontext, null, -1, accs, 0);
collectDocs();
SimpleOrderedMap<Object> allBuckets = new SimpleOrderedMap<>();
allBuckets.add("count", allBucketsAcc.getSpecialCount());
allBucketsAcc.setValues(allBuckets, -1); // -1 slotNum is unused for SpecialSlotAcc
refineResult.add("allBuckets", allBuckets);
return refineResult;
}
}
maxSlots = nTerms;
if (freq.allBuckets) {

View File

@ -387,8 +387,21 @@ public class TestJsonFacetRefinement extends SolrTestCaseHS {
"}"
);
// test filling in missing "allBuckets"
// test filling in "missing" bucket for partially refined facets
client.testJQ(params(p, "q", "*:*",
"json.facet", "{" +
" cat :{type:terms, field:${cat_s}, limit:1, overrequest:0, refine:false, allBuckets:true, facet:{ xy:{type:terms, field:${xy_s}, limit:1, overrequest:0, allBuckets:true, refine:false} } }" +
", cat2:{type:terms, field:${cat_s}, limit:1, overrequest:0, refine:true , allBuckets:true, facet:{ xy:{type:terms, field:${xy_s}, limit:1, overrequest:0, allBuckets:true, refine:true } } }" +
", cat3:{type:terms, field:${cat_s}, limit:1, overrequest:0, refine:true , allBuckets:true, facet:{ xy:{type:terms, field:${xy_s}, limit:1, overrequest:0, allBuckets:true, refine:true , facet:{f:'sum(${num_d})'} } } }" +
"}"
)
, "facets=={ count:8" +
", cat:{ allBuckets:{count:8}, buckets:[ {val:A, count:3, xy:{buckets:[{count:2, val:X}], allBuckets:{count:3}}}] }" +
",cat2:{ allBuckets:{count:8}, buckets:[ {val:A, count:4, xy:{buckets:[{count:3, val:X}], allBuckets:{count:4}}}] }" +
",cat3:{ allBuckets:{count:8}, buckets:[ {val:A, count:4, xy:{buckets:[{count:3, val:X, f:23.0}], allBuckets:{count:4, f:4.0}}}] }" +
"}"
);
}