diff --git a/CHANGES.txt b/CHANGES.txt index d917b385a13..e857e639b01 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -110,6 +110,9 @@ Bug Fixes * SOLR-1628: log contains incorrect number of adds and deletes. (Thijs Vonk via yonik) +* SOLR-343: Date faceting now respects facet.mincount limiting + (Uri Boness, Raiko Eckstein via hossman) + * SOLR-1624: Highlighter only highlights values from the first field value in a multivalued field when term positions (term vectors) are stored. (Chris Harris via yonik) diff --git a/src/java/org/apache/solr/request/SimpleFacets.java b/src/java/org/apache/solr/request/SimpleFacets.java index 26fa1321127..d7b4166a38a 100644 --- a/src/java/org/apache/solr/request/SimpleFacets.java +++ b/src/java/org/apache/solr/request/SimpleFacets.java @@ -596,7 +596,9 @@ public class SimpleFacets { final String gap = required.getFieldParam(f,FacetParams.FACET_DATE_GAP); final DateMathParser dmp = new DateMathParser(ft.UTC, Locale.US); dmp.setNow(NOW); - + + int minCount = params.getFieldInt(f,FacetParams.FACET_MINCOUNT, 0); + try { Date low = start; @@ -617,7 +619,10 @@ public class SimpleFacets { (SolrException.ErrorCode.BAD_REQUEST, "date facet infinite loop (is gap negative?)"); } - resInner.add(label, rangeCount(sf,low,high,true,true)); + int count = rangeCount(sf,low,high,true,true); + if (count >= minCount) { + resInner.add(label, count); + } low = high; } } catch (java.text.ParseException e) { diff --git a/src/test/org/apache/solr/request/SimpleFacetsTest.java b/src/test/org/apache/solr/request/SimpleFacetsTest.java index e72d9a42043..edf343d4b21 100644 --- a/src/test/org/apache/solr/request/SimpleFacetsTest.java +++ b/src/test/org/apache/solr/request/SimpleFacetsTest.java @@ -284,6 +284,58 @@ public class SimpleFacetsTest extends AbstractSolrTestCase { ); + assertQ("check counts for month of facet by day with global mincount = 1", + req( "q", "*:*" + ,"rows", "0" + ,"facet", "true" + ,"facet.date", f + ,"facet.date.start", "1976-07-01T00:00:00.000Z" + ,"facet.date.end", "1976-07-01T00:00:00.000Z+1MONTH" + ,"facet.date.gap", "+1DAY" + ,"facet.date.other", "all" + ,"facet.mincount", "1" + ) + // 31 days + pre+post+inner = 34 + ,"*[count("+pre+"/int)=11]" + ,pre+"/int[@name='1976-07-03T00:00:00Z'][.='2' ]" + // july4th = 2 because exists doc @ 00:00:00.000 on July5 + // (date faceting is inclusive) + ,pre+"/int[@name='1976-07-04T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='1976-07-05T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='1976-07-12T00:00:00Z'][.='1' ]" + ,pre+"/int[@name='1976-07-13T00:00:00Z'][.='1' ]" + ,pre+"/int[@name='1976-07-15T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='1976-07-21T00:00:00Z'][.='1' ]" + ,pre+"/int[@name='1976-07-30T00:00:00Z'][.='1' ]" + ,pre+"/int[@name='before' ][.='2']" + ,pre+"/int[@name='after' ][.='1']" + ,pre+"/int[@name='between'][.='11']" + ); + + assertQ("check counts for month of facet by day with field mincount = 1", + req( "q", "*:*" + ,"rows", "0" + ,"facet", "true" + ,"facet.date", f + ,"facet.date.start", "1976-07-01T00:00:00.000Z" + ,"facet.date.end", "1976-07-01T00:00:00.000Z+1MONTH" + ,"facet.date.gap", "+1DAY" + ,"facet.date.other", "all" + ,"f." + f + ".facet.mincount", "2" + ) + // 31 days + pre+post+inner = 34 + ,"*[count("+pre+"/int)=7]" + ,pre+"/int[@name='1976-07-03T00:00:00Z'][.='2' ]" + // july4th = 2 because exists doc @ 00:00:00.000 on July5 + // (date faceting is inclusive) + ,pre+"/int[@name='1976-07-04T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='1976-07-05T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='1976-07-15T00:00:00Z'][.='2' ]" + ,pre+"/int[@name='before' ][.='2']" + ,pre+"/int[@name='after' ][.='1']" + ,pre+"/int[@name='between'][.='11']" + ); + assertQ("check hardend=false", req( "q", "*:*" ,"rows", "0"