SOLR-11824: Fixed bucket ordering in distributed json.facet type:range when mincount>0

This commit is contained in:
Chris Hostetter 2018-01-06 14:23:45 -07:00
parent d03cb44de7
commit d598517b96
4 changed files with 53 additions and 4 deletions

View File

@ -86,6 +86,9 @@ Bug Fixes
* SOLR-11555: If the query terms reduce to nothing, filter(clause) produces an NPE whereas
fq=clause does not (Erick Erickson)
* SOLR-11824: Fixed bucket ordering in distributed json.facet type:range when mincount>0 (hossman)
Optimizations
----------------------

View File

@ -93,9 +93,13 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
super.process();
// Under the normal mincount=0, each shard will need to return 0 counts since we don't calculate buckets at the top level.
// But if mincount>0 then our sub mincount can be set to 1.
effectiveMincount = fcontext.isShard() ? (freq.mincount > 0 ? 1 : 0) : freq.mincount;
// If mincount>0 then we could *potentially* set our sub mincount to 1...
// ...but that would require sorting the buckets (by their val) at the top level
//
// Tather then do that, which could be complicated by non trivial field types, we'll force the sub-shard effectiveMincount
// to be 0, ensuring that we can trivially merge all the buckets from every shard
// (we have to filter the merged buckets by the original mincount either way)
effectiveMincount = fcontext.isShard() ? 0 : freq.mincount;
sf = fcontext.searcher.getSchema().getField(freq.field);
response = getRangeCounts();
}

View File

@ -45,7 +45,7 @@ public class FacetRangeMerger extends FacetRequestSortedMerger<FacetRange> {
@Override
public void sortBuckets() {
// TODO: mincount>0 will mess up order?
// regardless of mincount, every shard returns a consistent set of buckets which are already in the correct order
sortedBuckets = new ArrayList<>( buckets.values() );
}

View File

@ -1028,6 +1028,48 @@ public class TestJsonFacets extends SolrTestCaseHS {
",between:{count:3,x:0.0, ny:{count:2}}" +
" } }"
);
// sparse range facet (with sub facets and stats), with "other:all"
client.testJQ(params(p, "q", "*:*", "json.facet",
"{f:{range:{field:${num_d}, start:-5, end:10, gap:1, other:all, "+
" facet:{ x:'sum(${num_i})', ny:{query:'${where_s}:NY'}} }}}"
)
, "facets=={count:6, f:{buckets:[ {val:-5.0,count:1, x:-5.0,ny:{count:1}}, "+
" {val:-4.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val:-3.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val:-2.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val:-1.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 0.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 1.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 2.0,count:1, x:3.0,ny:{count:0}} , "+
" {val: 3.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 4.0,count:1, x:2.0,ny:{count:1}} , "+
" {val: 5.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 6.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 7.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 8.0,count:0 /* ,x:0.0,ny:{count:0} */} ,"+
" {val: 9.0,count:0 /* ,x:0.0,ny:{count:0} */}"+
" ]" +
" ,before: {count:1,x:-5.0,ny:{count:0}}" +
" ,after: {count:1,x:7.0, ny:{count:0}}" +
" ,between:{count:3,x:0.0, ny:{count:2}}" +
" } }"
);
// sparse range facet (with sub facets and stats), with "other:all" & mincount==1
client.testJQ(params(p, "q", "*:*", "json.facet",
"{f:{range:{field:${num_d}, start:-5, end:10, gap:1, other:all, mincount:1, "+
" facet:{ x:'sum(${num_i})', ny:{query:'${where_s}:NY'}} }}}"
)
, "facets=={count:6, f:{buckets:[ {val:-5.0,count:1, x:-5.0,ny:{count:1}}, "+
" {val: 2.0,count:1, x:3.0,ny:{count:0}} , "+
" {val: 4.0,count:1, x:2.0,ny:{count:1}} "+
" ]" +
" ,before: {count:1,x:-5.0,ny:{count:0}}" +
" ,after: {count:1,x:7.0, ny:{count:0}}" +
" ,between:{count:3,x:0.0, ny:{count:2}}" +
" } }"
);
// range facet with sub facets and stats, with "other:all", on subset
client.testJQ(params(p, "q", "id:(3 4 6)"