* @see FacetParams#FACET_DATE
*/
public NamedList<Object> getFacetDateCounts() throws JahiaException, IOException,
RepositoryException {
final SolrParams required = new RequiredSolrParams(params);
final NamedList<Object> resOuter = new SimpleOrderedMap<Object>();
final String[] fields = params.getParams(FacetParams.FACET_DATE);
final Date NOW = new Date();
if (null == fields || 0 == fields.length)
return resOuter;
for (String f : fields) {
final NamedList<Object> resInner = new SimpleOrderedMap<Object>();
String fieldName = StringUtils.substringBeforeLast(f, PROPNAME_INDEX_SEPARATOR);
ExtendedPropertyDefinition epd = NodeTypeRegistry.getInstance().getNodeType(params.get("f."+f+".facet.nodetype")).getPropertyDefinition(fieldName);
String fieldNameInIndex = getFieldNameInIndex(fieldName, epd, params.getFieldParam(f,
"facet.locale"));
resOuter.add(fieldName + PROPNAME_INDEX_SEPARATOR + fieldNameInIndex, resInner);
if (!(epd.getRequiredType() == PropertyType.DATE)) {
throw new JahiaException("Can not date facet on a field which is not a DateField: "
+ f, "Can not date facet on a field which is not a DateField: " + f,
JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY);
}
Integer mincount = params.getFieldInt(f, FacetParams.FACET_MINCOUNT);
if (mincount == null) {
Boolean zeros = params.getFieldBool(f, FacetParams.FACET_ZEROS);
// mincount = (zeros!=null && zeros) ? 0 : 1;
mincount = (zeros != null && !zeros) ? 1 : 0;
// current default is to include zeros.
}
final String startS = required.getFieldParam(f,
FacetParams.FACET_DATE_START);
final Date start;
try {
start = JahiaQueryParser.DATE_TYPE.parseMath(NOW, startS);
} catch (SolrException e) {
throw new JahiaException(
"date facet 'start' is not a valid Date string: " + startS,
"date facet 'start' is not a valid Date string: " + startS,
JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY, e);
}
final String endS = required.getFieldParam(f, FacetParams.FACET_DATE_END);
Date end; // not final, hardend may change this
try {
end = JahiaQueryParser.DATE_TYPE.parseMath(NOW, endS);
} catch (SolrException e) {
throw new JahiaException("date facet 'end' is not a valid Date string: " + endS,
"date facet 'end' is not a valid Date string: " + endS,
JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY, e);
}
if (end.before(start)) {
throw new JahiaException("date facet 'end' comes before 'start': " + endS + " < "
+ startS,
"date facet 'end' comes before 'start': " + endS + " < " + startS,
JahiaException.PARAMETER_ERROR, JahiaException.ERROR_SEVERITY);
}
final String gap = required.getFieldParam(f, FacetParams.FACET_DATE_GAP);
final DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.US);
dmp.setNow(NOW);
try {
Date low = start;