SOLR-343: Date faceting now respects facet.mincount limiting

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@888136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2009-12-07 21:04:09 +00:00
parent 1d4a59519e
commit e797cf3c95
3 changed files with 62 additions and 2 deletions

View File

@ -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)

View File

@ -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) {

View File

@ -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"