Apache Solr open-source search software
SOLR-7803: Prevent class loading deadlock in TrieDateField; refactor date formatting and parsing out of TrieDateField and move to static utility class DateFormatUtil
Uwe Schindler50f168ed4ca0
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 1735f7bc365..3b11623e967 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -339,6 +339,10 @@ Other Changes* SOLR-7805: Update Kite Morphlines to 1.1.0 (Mark Miller)+* SOLR-7803: Prevent class loading deadlock in TrieDateField; refactor date+ formatting and parsing out of TrieDateField and move to static utility class+ DateFormatUtil. (Markus Heiden, Uwe Schindler)+================== 5.2.1 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/BasicAccumulator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/BasicAccumulator.javaindex 11eb67527a4..23472fdabe4 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/BasicAccumulator.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/BasicAccumulator.java@@ -34,9 +34,9 @@ import org.apache.solr.analytics.statistics.StatsCollectorSupplierFactory;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.util.NamedList;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.search.DocSet;import org.apache.solr.search.SolrIndexSearcher;+import org.apache.solr.util.DateFormatUtil;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -143,7 +143,7 @@ public class BasicAccumulator extends ValueAccumulator {if (expressionName.equals(expressionNames[count])) {Comparable value = expressions[count].getValue();if (value.getClass().equals(Date.class)) {- return TrieDateField.formatExternal((Date)value);+ return DateFormatUtil.formatExternal((Date)value);} else {return value.toString();}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/FacetingAccumulator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/FacetingAccumulator.javaindex 62a4a5701df..065216c124c 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/FacetingAccumulator.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/FacetingAccumulator.java@@ -57,11 +57,11 @@ import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.util.NamedList;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.schema.SchemaField;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.search.DocSet;import org.apache.solr.search.QParser;import org.apache.solr.search.SolrIndexSearcher;import org.apache.solr.search.SyntaxError;+import org.apache.solr.util.DateFormatUtil;import com.google.common.collect.Iterables;@@ -377,7 +377,7 @@ public class FacetingAccumulator extends BasicAccumulator implements FacetValueAif (expressionName.equals(expressionNames[count])) {Comparable value = facetExpressions[count].getValue();if (value.getClass().equals(Date.class)) {- return TrieDateField.formatExternal((Date)value);+ return DateFormatUtil.formatExternal((Date)value);} else {return value.toString();}@@ -431,7 +431,7 @@ public class FacetingAccumulator extends BasicAccumulator implements FacetValueAif (expressionName.equals(expressionNames[count])) {Comparable value = facetExpressions[count].getValue();if (value.getClass().equals(Date.class)) {- return TrieDateField.formatExternal((Date)value);+ return DateFormatUtil.formatExternal((Date)value);} else {return value.toString();}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/facet/FieldFacetAccumulator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/facet/FieldFacetAccumulator.javaindex ec6c4cb0dd6..4f300108f0a 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/facet/FieldFacetAccumulator.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/accumulator/facet/FieldFacetAccumulator.java@@ -33,8 +33,8 @@ import org.apache.solr.analytics.util.AnalyticsParsers.Parser;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.util.NamedList;+import org.apache.solr.schema.DateValueFieldType;import org.apache.solr.schema.SchemaField;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.search.SolrIndexSearcher;/**@@ -67,7 +67,7 @@ public class FieldFacetAccumulator extends ValueAccumulator {}this.multiValued = schemaField.multiValued();this.numField = schemaField.getType().getNumericType()!=null;- this.dateField = schemaField.getType().getClass().equals(TrieDateField.class);+ this.dateField = schemaField.getType() instanceof DateValueFieldType;this.parent = parent;this.parser = AnalyticsParsers.getParser(schemaField.getType().getClass());}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/expression/ExpressionFactory.javaindex 0fd9db01a2e..29f94b04d94 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/expression/ExpressionFactory.java@@ -25,7 +25,7 @@ import org.apache.solr.analytics.statistics.StatsCollector;import org.apache.solr.analytics.util.AnalyticsParams;import org.apache.solr.common.SolrException;import org.apache.solr.common.SolrException.ErrorCode;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;public class ExpressionFactory {@@ -83,7 +83,7 @@ public class ExpressionFactory {}} else if (topOperation.equals(AnalyticsParams.CONSTANT_DATE)) {try {- return new ConstantDateExpression(TrieDateField.parseDate(operands));+ return new ConstantDateExpression(DateFormatUtil.parseDate(operands));} catch (ParseException e) {throw new SolrException(ErrorCode.BAD_REQUEST, "The constant "+operands+" cannot be converted into a date.",e);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.javaindex 35b5d582c50..d59e40bb362 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/statistics/StatsCollectorSupplierFactory.java@@ -67,6 +67,7 @@ import org.apache.solr.schema.TrieDoubleField;import org.apache.solr.schema.TrieFloatField;import org.apache.solr.schema.TrieIntField;import org.apache.solr.schema.TrieLongField;+import org.apache.solr.util.DateFormatUtil;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -443,7 +444,7 @@ public class StatsCollectorSupplierFactory {}} else if ( src instanceof DateFieldSource || src instanceof MultiDateFunction) {try {- defaultObject = TrieDateField.parseDate(arguments[1]);+ defaultObject = DateFormatUtil.parseDate(arguments[1]);} catch (ParseException e) {throw new SolrException(ErrorCode.BAD_REQUEST,"The filter value "+arguments[1]+" cannot be converted into a date.",e);}@@ -578,7 +579,7 @@ public class StatsCollectorSupplierFactory {throw new SolrException(ErrorCode.BAD_REQUEST,"The constant date declaration ["+expressionString+"] does not have exactly 1 argument.");}try {- return new ConstDateSource(TrieDateField.parseDate(operands));+ return new ConstDateSource(DateFormatUtil.parseDate(operands));} catch (ParseException e) {throw new SolrException(ErrorCode.BAD_REQUEST,"The constant "+operands+" cannot be converted into a date.",e);}diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/AnalyticsParsers.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/AnalyticsParsers.javaindex 0e4ecebe439..320d3f5c248 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/AnalyticsParsers.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/AnalyticsParsers.java@@ -29,6 +29,7 @@ import org.apache.solr.schema.TrieDoubleField;import org.apache.solr.schema.TrieFloatField;import org.apache.solr.schema.TrieIntField;import org.apache.solr.schema.TrieLongField;+import org.apache.solr.util.DateFormatUtil;/*** Class to hold the parsers used for Solr Analytics.@@ -148,7 +149,7 @@ public class AnalyticsParsers {@SuppressWarnings("deprecation")public String parse(BytesRef bytes) throws IOException {try {- return TrieDateField.formatExternal(new Date(NumericUtils.prefixCodedToLong(bytes)));+ return DateFormatUtil.formatExternal(new Date(NumericUtils.prefixCodedToLong(bytes)));} catch (NumberFormatException e) {throw new IOException("The byte array "+Arrays.toString(bytes.bytes)+" cannot be converted to a date.");}@@ -156,7 +157,7 @@ public class AnalyticsParsers {@SuppressWarnings("deprecation")@Overridepublic String parseNum(long l) {- return ""+TrieDateField.formatExternal(new Date(l));+ return ""+DateFormatUtil.formatExternal(new Date(l));}};diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/RangeEndpointCalculator.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/RangeEndpointCalculator.javaindex 6eabe292d2b..b7d02440d4c 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/RangeEndpointCalculator.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/RangeEndpointCalculator.java@@ -32,6 +32,7 @@ import org.apache.solr.schema.SchemaField;import org.apache.solr.schema.TrieDateField;import org.apache.solr.schema.TrieField;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;public abstract class RangeEndpointCalculator<T extends Comparable<T>> {@@ -332,12 +333,12 @@ public abstract class RangeEndpointCalculator<T extends Comparable<T>> {@Overridepublic String formatValue(Date val) {- return ((TrieDateField)field.getType()).toExternal(val);+ return DateFormatUtil.formatExternal(val);}@Overrideprotected Date parseVal(String rawval) {- return ((TrieDateField)field.getType()).parseMath(now, rawval);+ return DateFormatUtil.parseMath(now, rawval);}@Overridediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/ConstDateSource.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/ConstDateSource.javaindex bdde1696fe4..19acfee9970 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/ConstDateSource.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/ConstDateSource.java@@ -28,7 +28,7 @@ import org.apache.lucene.queries.function.docvalues.FloatDocValues;import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueDate;import org.apache.solr.analytics.util.AnalyticsParams;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;/*** <code>ConstDateSource</code> returns a constant date for all documents@@ -47,7 +47,7 @@ public class ConstDateSource extends ConstDoubleSource {@SuppressWarnings("deprecation")@Overridepublic String description() {- return name()+"(" + TrieDateField.formatExternal(new Date(getLong())) + ")";+ return name()+"(" + DateFormatUtil.formatExternal(new Date(getLong())) + ")";}protected String name() {@@ -84,7 +84,7 @@ public class ConstDateSource extends ConstDoubleSource {@SuppressWarnings("deprecation")@Overridepublic String strVal(int doc) {- return TrieDateField.formatExternal(new Date(longVal(doc)));+ return DateFormatUtil.formatExternal(new Date(longVal(doc)));}@Overridepublic boolean boolVal(int doc) {diff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/DateFieldSource.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/DateFieldSource.javaindex 352c9334c70..947e81177ab 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/DateFieldSource.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/DateFieldSource.java@@ -32,7 +32,7 @@ import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.NumericUtils;import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueDate;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;/*** Extends {@link LongFieldSource} to have a field source that takes in@@ -54,7 +54,7 @@ public class DateFieldSource extends LongFieldSource {@SuppressWarnings("deprecation")public String longToString(long val) {- return TrieDateField.formatExternal((Date)longToObject(val));+ return DateFormatUtil.formatExternal((Date)longToObject(val));}@Overridediff --git a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/FilterFieldSource.java b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/FilterFieldSource.javaindex a360d0cb674..272dfc476e5 100644--- a/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/FilterFieldSource.java+++ b/solr/contrib/analytics/src/java/org/apache/solr/analytics/util/valuesource/FilterFieldSource.java@@ -26,7 +26,7 @@ import org.apache.lucene.queries.function.FunctionValues;import org.apache.lucene.queries.function.ValueSource;import org.apache.lucene.util.mutable.MutableValue;import org.apache.solr.analytics.util.AnalyticsParams;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;/*** <code>DefaultIsMissingFieldSource</code> wraps a field source to return missing values@@ -50,7 +50,7 @@ public class FilterFieldSource extends ValueSource {@Overridepublic String description() {if (missValue.getClass().equals(Date.class)) {- return name()+"("+source.description()+","+TrieDateField.formatExternal((Date)missValue)+")";+ return name()+"("+source.description()+","+DateFormatUtil.formatExternal((Date)missValue)+")";} else {return name()+"("+source.description()+","+missValue.toString()+")";}diff --git a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java b/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.javaindex 5cf8be110d2..737f137218f 100644--- a/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java+++ b/solr/contrib/analytics/src/test/org/apache/solr/analytics/expression/ExpressionTest.java@@ -23,8 +23,8 @@ import org.apache.lucene.util.IOUtils;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.analytics.AbstractAnalyticsStatsTest;import org.apache.solr.request.SolrQueryRequest;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;import org.junit.BeforeClass;import org.junit.Test;@@ -162,15 +162,15 @@ public class ExpressionTest extends AbstractAnalyticsStatsTest {public void dateMathTest() throws Exception {String math = (String) getStatResult("dmr", "cme", VAL_TYPE.STRING);DateMathParser date = new DateMathParser();- date.setNow(TrieDateField.parseDate((String) getStatResult("dmr", "median", VAL_TYPE.DATE)));+ date.setNow(DateFormatUtil.parseDate((String) getStatResult("dmr", "median", VAL_TYPE.DATE)));String dateMath = (String) getStatResult("dmr", "dmme", VAL_TYPE.DATE);- assertEquals(getRawResponse(), TrieDateField.parseDate(dateMath), date.parseMath(math));+ assertEquals(getRawResponse(), DateFormatUtil.parseDate(dateMath), date.parseMath(math));math = (String) getStatResult("dmr", "cma", VAL_TYPE.STRING);date = new DateMathParser();- date.setNow(TrieDateField.parseDate((String) getStatResult("dmr", "max", VAL_TYPE.DATE)));+ date.setNow(DateFormatUtil.parseDate((String) getStatResult("dmr", "max", VAL_TYPE.DATE)));dateMath = (String) getStatResult("dmr", "dmma", VAL_TYPE.DATE);- assertEquals(getRawResponse(), TrieDateField.parseDate(dateMath), date.parseMath(math));+ assertEquals(getRawResponse(), DateFormatUtil.parseDate(dateMath), date.parseMath(math));}@Testdiff --git a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.javaindex 303fbd7cc7d..0d2146d5cce 100644--- a/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java+++ b/solr/core/src/java/org/apache/solr/core/SolrDeletionPolicy.java@@ -21,8 +21,8 @@ import org.apache.lucene.index.IndexDeletionPolicy;import org.apache.lucene.store.Directory;import org.apache.lucene.store.FSDirectory;import org.apache.solr.common.util.NamedList;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.plugin.NamedListInitializedPlugin;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -174,7 +174,7 @@ public class SolrDeletionPolicy extends IndexDeletionPolicy implements NamedListtry {if (maxCommitAge != null) {if (maxCommitAgeTimeStamp==-1) {- DateMathParser dmp = new DateMathParser(TrieDateField.UTC, Locale.ROOT);+ DateMathParser dmp = new DateMathParser(DateFormatUtil.UTC, Locale.ROOT);maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();}if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) {diff --git a/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorState.java b/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorState.javaindex f45872b52e7..c8c06827aad 100644--- a/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorState.java+++ b/solr/core/src/java/org/apache/solr/handler/CdcrReplicatorState.java@@ -18,9 +18,9 @@ package org.apache.solr.handler;*/import org.apache.solr.client.solrj.impl.CloudSolrClient;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.update.CdcrUpdateLog;import org.apache.solr.update.UpdateLog;+import org.apache.solr.util.DateFormatUtil;import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -133,7 +133,7 @@ class CdcrReplicatorState {Iterator<ErrorQueueEntry> it = errorsQueue.iterator();while (it.hasNext()) {ErrorQueueEntry entry = it.next();- lastErrors.add(new String[]{TrieDateField.formatExternal(new Date(entry.timestamp)), entry.type.toLower()});+ lastErrors.add(new String[]{DateFormatUtil.formatExternal(new Date(entry.timestamp)), entry.type.toLower()});}}return lastErrors;@@ -145,7 +145,7 @@ class CdcrReplicatorState {String getTimestampOfLastProcessedOperation() {if (logReader != null && logReader.getLastVersion() != -1) {// Shift back to the right by 20 bits the version number - See VersionInfo#getNewClock- return TrieDateField.formatExternal(new Date(logReader.getLastVersion() >> 20));+ return DateFormatUtil.formatExternal(new Date(logReader.getLastVersion() >> 20));}return new String();}diff --git a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.javaindex b94ec102aa6..49c2e748e51 100644--- a/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/PingRequestHandler.java@@ -29,14 +29,12 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.plugin.SolrCoreAware;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestHandler;import org.apache.solr.response.SolrQueryResponse;-import org.apache.commons.io.FileUtils;-import org.slf4j.Logger;import org.slf4j.LoggerFactory;@@ -275,7 +273,7 @@ public class PingRequestHandler extends RequestHandlerBase implements SolrCoreAwtry {// write out when the file was createdFileUtils.write(healthcheck,- TrieDateField.formatExternal(new Date()), "UTF-8");+ DateFormatUtil.formatExternal(new Date()), "UTF-8");} catch (IOException e) {throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Unable to write healthcheck flag file", e);diff --git a/solr/core/src/java/org/apache/solr/handler/component/DateFacetProcessor.java b/solr/core/src/java/org/apache/solr/handler/component/DateFacetProcessor.javaindex 65d92ad4f21..8760240b8d0 100644--- a/solr/core/src/java/org/apache/solr/handler/component/DateFacetProcessor.java+++ b/solr/core/src/java/org/apache/solr/handler/component/DateFacetProcessor.java@@ -30,12 +30,14 @@ import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;import org.apache.solr.request.SimpleFacets;import org.apache.solr.request.SolrQueryRequest;+import org.apache.solr.schema.FieldType;import org.apache.solr.schema.IndexSchema;import org.apache.solr.schema.SchemaField;import org.apache.solr.schema.TrieDateField;import org.apache.solr.search.DocSet;import org.apache.solr.search.SyntaxError;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;/*** Process date facets@@ -78,12 +80,11 @@ public class DateFacetProcessor extends SimpleFacets {(SolrException.ErrorCode.BAD_REQUEST,"Can not date facet on a field which is not a TrieDateField: " + f);}- final TrieDateField ft = (TrieDateField) sf.getType();final String startS= required.getFieldParam(f, FacetParams.FACET_DATE_START);final Date start;try {- start = ft.parseMath(null, startS);+ start = DateFormatUtil.parseMath(null, startS);} catch (SolrException e) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,@@ -93,7 +94,7 @@ public class DateFacetProcessor extends SimpleFacets {= required.getFieldParam(f, FacetParams.FACET_DATE_END);Date end; // not final, hardend may change thistry {- end = ft.parseMath(null, endS);+ end = DateFormatUtil.parseMath(null, endS);} catch (SolrException e) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,@@ -126,7 +127,7 @@ public class DateFacetProcessor extends SimpleFacets {Date low = start;while (low.before(end)) {dmp.setNow(low);- String label = ft.toExternal(low);+ String label = DateFormatUtil.formatExternal(low);Date high = dmp.parseMath(gap);if (end.before(high)) {@@ -246,7 +247,9 @@ public class DateFacetProcessor extends SimpleFacets {@Deprecatedprotected int rangeCount(ParsedParams parsed, SchemaField sf, Date low, Date high,boolean iLow, boolean iHigh) throws IOException {- Query rangeQ = ((TrieDateField) (sf.getType())).getRangeQuery(null, sf, low, high, iLow, iHigh);+ String lowStr = (low == null) ? null : DateFormatUtil.formatExternal(low);+ String highStr = (high == null) ? null : DateFormatUtil.formatExternal(high);+ Query rangeQ = sf.getType().getRangeQuery(null, sf, lowStr, highStr, iLow, iHigh);return searcher.numDocs(rangeQ, parsed.docs);}}diff --git a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.javaindex 26e9800cbb3..51a2c2afe17 100644--- a/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java+++ b/solr/core/src/java/org/apache/solr/handler/component/PivotFacetValue.java@@ -27,7 +27,7 @@ import java.util.Map;import org.apache.solr.common.params.FacetParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.common.util.SimpleOrderedMap;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.PivotListEntry;/**@@ -93,7 +93,7 @@ public class PivotFacetValue {if (null == value) {out.add(null);} else if (value instanceof Date) {- out.add(TrieDateField.formatExternal((Date) value));+ out.add(DateFormatUtil.formatExternal((Date) value));} else {out.add(value.toString());}diff --git a/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java b/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.javaindex ada0864124a..5fa034fa32a 100644--- a/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java+++ b/solr/core/src/java/org/apache/solr/handler/component/RangeFacetRequest.java@@ -39,6 +39,7 @@ import org.apache.solr.schema.SchemaField;import org.apache.solr.schema.TrieDateField;import org.apache.solr.schema.TrieField;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;/*** Encapsulates a single facet.range request along with all its parameters. This class@@ -707,12 +708,12 @@ public class RangeFacetRequest extends FacetComponent.FacetBase {@Overridepublic String formatValue(Date val) {- return ((TrieDateField) field.getType()).toExternal(val);+ return DateFormatUtil.formatExternal(val);}@Overrideprotected Date parseVal(String rawval) {- return ((TrieDateField) field.getType()).parseMath(now, rawval);+ return DateFormatUtil.parseMath(now, rawval);}@Override@@ -743,7 +744,7 @@ public class RangeFacetRequest extends FacetComponent.FacetBase {@Overridepublic String formatValue(Date val) {- return TrieDateField.formatExternal(val);+ return DateFormatUtil.formatExternal(val);}@Overridediff --git a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.javaindex 0ed17f516e6..4e51a606b52 100644--- a/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/TextResponseWriter.java@@ -30,7 +30,7 @@ import org.apache.solr.common.EnumFieldValue;import org.apache.solr.common.SolrDocument;import org.apache.solr.common.SolrDocumentList;import org.apache.solr.common.util.Base64;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.FastWriter;import org.apache.solr.common.util.NamedList;import org.apache.solr.request.SolrQueryRequest;@@ -327,7 +327,7 @@ public abstract class TextResponseWriter {public void writeDate(String name, Date val) throws IOException {- writeDate(name, TrieDateField.formatExternal(val));+ writeDate(name, DateFormatUtil.formatExternal(val));}diff --git a/solr/core/src/java/org/apache/solr/schema/DateRangeField.java b/solr/core/src/java/org/apache/solr/schema/DateRangeField.javaindex 6590476b331..a2f47aac2e5 100644--- a/solr/core/src/java/org/apache/solr/schema/DateRangeField.java+++ b/solr/core/src/java/org/apache/solr/schema/DateRangeField.java@@ -24,6 +24,7 @@ import java.util.List;import java.util.Map;import com.spatial4j.core.shape.Shape;+import org.apache.lucene.index.StorableField;import org.apache.lucene.search.Query;import org.apache.lucene.spatial.prefix.NumberRangePrefixTreeStrategy;@@ -37,6 +38,7 @@ import org.apache.solr.common.params.SolrParams;import org.apache.solr.request.SolrRequestInfo;import org.apache.solr.search.QParser;import org.apache.solr.search.SyntaxError;+import org.apache.solr.util.DateFormatUtil;/*** A field for indexed dates and date ranges. It's mostly compatible with TrieDateField.@@ -50,8 +52,6 @@ public class DateRangeField extends AbstractSpatialPrefixTreeFieldType<NumberRanprivate static final DateRangePrefixTree tree = DateRangePrefixTree.INSTANCE;- private static final TrieDateField trieDateField = new TrieDateField();//used for utility methods-@Overrideprotected void init(IndexSchema schema, Map<String, String> args) {super.init(schema, args);@@ -76,7 +76,7 @@ public class DateRangeField extends AbstractSpatialPrefixTreeFieldType<NumberRanif (unitShape.getLevel() == tree.getMaxLevels()) {//fully precise date. We can be fully compatible with TrieDateField.Date date = tree.toCalendar(unitShape).getTime();- return TrieDateField.formatExternal(date);+ return DateFormatUtil.formatExternal(date);}}return (shapeStr == null ? shape.toString() : shapeStr);//we don't normalize ranges here; should we?@@ -101,7 +101,7 @@ public class DateRangeField extends AbstractSpatialPrefixTreeFieldType<NumberRanif (str.startsWith("NOW") || str.lastIndexOf('Z') >= 0) {//use Solr standard date format parsing rules.//TODO parse a Calendar instead of a Date, rounded according to DateMath syntax.- Date date = trieDateField.parseMath(null, str);+ Date date = DateFormatUtil.parseMath(null, str);Calendar cal = tree.newCal();cal.setTime(date);return cal;@@ -116,9 +116,9 @@ public class DateRangeField extends AbstractSpatialPrefixTreeFieldType<NumberRan}}- /** For easy compatibility with {@link TrieDateField#parseMath(Date, String)}. */+ /** For easy compatibility with {@link DateFormatUtil#parseMath(Date, String)}. */public Date parseMath(Date now, String rawval) {- return trieDateField.parseMath(now, rawval);+ return DateFormatUtil.parseMath(now, rawval);}@Override@@ -128,7 +128,7 @@ public class DateRangeField extends AbstractSpatialPrefixTreeFieldType<NumberRanif (unitShape.getLevel() == tree.getMaxLevels()) {//fully precise date. We can be fully compatible with TrieDateField.Date date = tree.toCalendar(unitShape).getTime();- return TrieDateField.formatExternal(date);+ return DateFormatUtil.formatExternal(date);}}return shape.toString();//range shapediff --git a/solr/core/src/java/org/apache/solr/schema/TrieDateField.java b/solr/core/src/java/org/apache/solr/schema/TrieDateField.javaindex 4fe108d79c1..0e73ce73f4e 100644--- a/solr/core/src/java/org/apache/solr/schema/TrieDateField.java+++ b/solr/core/src/java/org/apache/solr/schema/TrieDateField.java@@ -17,27 +17,12 @@package org.apache.solr.schema;-import org.apache.solr.common.SolrException;-import org.apache.solr.common.util.DateUtil;-import org.apache.solr.request.SolrQueryRequest;-import org.apache.solr.search.QParser;+import java.util.Date;++import org.apache.lucene.index.StorableField;import org.apache.solr.update.processor.TimestampUpdateProcessorFactory; //jdoc+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.DateMathParser;-import org.apache.lucene.index.StorableField;-import org.apache.lucene.search.Query;-import org.apache.lucene.search.NumericRangeQuery;--import java.text.DateFormat;-import java.text.DecimalFormat;-import java.text.DecimalFormatSymbols;-import java.text.FieldPosition;-import java.text.NumberFormat;-import java.text.ParseException;-import java.text.ParsePosition;-import java.text.SimpleDateFormat;-import java.util.Locale;-import java.util.Date;-import java.util.TimeZone;/*** FieldType that can represent any Date/Time with millisecond precision.@@ -101,257 +86,19 @@ import java.util.TimeZone;*/public class TrieDateField extends TrieField implements DateValueFieldType {{- type = TrieTypes.DATE;+ this.type = TrieTypes.DATE;}- public static final TimeZone UTC = TimeZone.getTimeZone("UTC");-- /**- * Fixed TimeZone (UTC) needed for parsing/formatting Dates in the- * canonical representation.- */- protected static final TimeZone CANONICAL_TZ = UTC;- /**- * Fixed Locale needed for parsing/formatting Milliseconds in the- * canonical representation.- */- protected static final Locale CANONICAL_LOCALE = Locale.ROOT;-- protected static final String NOW = "NOW";- protected static final char Z = 'Z';--- /**- * Parses a String which may be a date (in the standard format)- * followed by an optional math expression.- * @param now an optional fixed date to use as "NOW" in the DateMathParser- * @param val the string to parse- */- public Date parseMath(Date now, String val) {- String math = null;- final DateMathParser p = new DateMathParser();-- if (null != now) p.setNow(now);-- if (val.startsWith(NOW)) {- math = val.substring(NOW.length());- } else {- final int zz = val.indexOf(Z);- if (0 < zz) {- math = val.substring(zz+1);- try {- // p.setNow(toObject(val.substring(0,zz)));- p.setNow(parseDate(val.substring(0,zz+1)));- } catch (ParseException e) {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date in Date Math String:'" + val + '\'', e);- }- } else {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date String:'" +val+'\'');- }- }-- if (null == math || math.equals("")) {- return p.getNow();- }-- try {- return p.parseMath(math);- } catch (ParseException e) {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date Math String:'" +val+'\'',e);- }- }-- /**- * Thread safe method that can be used by subclasses to format a Date- * without the trailing 'Z'.- */- protected String formatDate(Date d) {- return fmtThreadLocal.get().format(d);- }-- /**- * Return the standard human readable form of the date- */- public static String formatExternal(Date d) {- return fmtThreadLocal.get().format(d) + Z;- }-- /**- * @see #formatExternal- */- public String toExternal(Date d) {- return formatExternal(d);- }-- /**- * Thread safe method that can be used by subclasses to parse a Date- * without the trailing 'Z'- */- public static Date parseDate(String s) throws ParseException {- return fmtThreadLocal.get().parse(s);- }-- /** Parse a date string in the standard format, or any supported by DateUtil.parseDate */- public Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException {- // request could define timezone in the future- try {- return fmtThreadLocal.get().parse(s);- } catch (Exception e) {- return DateUtil.parseDate(s);- }- }-- /**- * Parses a String which may be a date- * followed by an optional math expression.- * @param now an optional fixed date to use as "NOW" in the DateMathParser- * @param val the string to parse- */- public Date parseMathLenient(Date now, String val, SolrQueryRequest req) {- String math = null;- final DateMathParser p = new DateMathParser();-- if (null != now) p.setNow(now);-- if (val.startsWith(NOW)) {- math = val.substring(NOW.length());- } else {- final int zz = val.indexOf(Z);- if (0 < zz) {- math = val.substring(zz+1);- try {- // p.setNow(toObject(val.substring(0,zz)));- p.setNow(parseDateLenient(val.substring(0,zz+1), req));- } catch (ParseException e) {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date in Date Math String: '" + val + '\'', e);- }- } else {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date String: '" +val+'\'');- }- }-- if (null == math || math.equals("")) {- return p.getNow();- }-- try {- return p.parseMath(math);- } catch (ParseException e) {- throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Invalid Date Math String: '" +val+'\'',e);- }- }-- /**- * Thread safe DateFormat that can <b>format</b> in the canonical- * ISO8601 date format, not including the trailing "Z" (since it is- * left off in the internal indexed values)- */- private final static ThreadLocalDateFormat fmtThreadLocal- = new ThreadLocalDateFormat(new ISO8601CanonicalDateFormat());-- private static class ISO8601CanonicalDateFormat extends SimpleDateFormat {-- protected NumberFormat millisParser- = NumberFormat.getIntegerInstance(CANONICAL_LOCALE);-- protected NumberFormat millisFormat = new DecimalFormat- (".###", new DecimalFormatSymbols(CANONICAL_LOCALE));-- public ISO8601CanonicalDateFormat() {- super("yyyy-MM-dd'T'HH:mm:ss", CANONICAL_LOCALE);- this.setTimeZone(CANONICAL_TZ);- }-- @Override- public Date parse(String i, ParsePosition p) {- /* delegate to SimpleDateFormat for easy stuff */- Date d = super.parse(i, p);- int milliIndex = p.getIndex();- /* worry about the milliseconds ourselves */- if (null != d &&- -1 == p.getErrorIndex() &&- milliIndex + 1 < i.length() &&- '.' == i.charAt(milliIndex)) {- p.setIndex(++milliIndex); // NOTE: ++ to chomp '.'- Number millis = millisParser.parse(i, p);- if (-1 == p.getErrorIndex()) {- int endIndex = p.getIndex();- d = new Date(d.getTime()- + (long)(millis.doubleValue() * Math.pow(10, (3 - endIndex + milliIndex))));- }- }- return d;- }-- @Override- public StringBuffer format(Date d, StringBuffer toAppendTo, FieldPosition pos) {- /* delegate to SimpleDateFormat for easy stuff */- super.format(d, toAppendTo, pos);- /* worry about the milliseconds ourselves */- long millis = d.getTime() % 1000l;- if (0L == millis) {- return toAppendTo;- }- if (millis < 0L) {- // original date was prior to epoch- millis += 1000L;- }- int posBegin = toAppendTo.length();- toAppendTo.append(millisFormat.format(millis / 1000d));- if (DateFormat.MILLISECOND_FIELD == pos.getField()) {- pos.setBeginIndex(posBegin);- pos.setEndIndex(toAppendTo.length());- }- return toAppendTo;- }-- @Override- public DateFormat clone() {- ISO8601CanonicalDateFormat c = (ISO8601CanonicalDateFormat)super.clone();- c.millisParser = NumberFormat.getIntegerInstance(CANONICAL_LOCALE);- c.millisFormat = new DecimalFormat(".###", new DecimalFormatSymbols(CANONICAL_LOCALE));- return c;- }- }-- private static class ThreadLocalDateFormat extends ThreadLocal<DateFormat> {- DateFormat proto;- public ThreadLocalDateFormat(DateFormat d) {- super();- proto = d;- }- @Override- protected DateFormat initialValue() {- return (DateFormat)proto.clone();- }- }-@Overridepublic Date toObject(StorableField f) {return (Date)super.toObject(f);}- /** TrieDateField specific range query */- public Query getRangeQuery(QParser parser, SchemaField sf, Date min, Date max, boolean minInclusive, boolean maxInclusive) {- return NumericRangeQuery.newLongRange(sf.getName(), precisionStep,- min == null ? null : min.getTime(),- max == null ? null : max.getTime(),- minInclusive, maxInclusive);- }-@Overridepublic Object toNativeType(Object val) {- if(val==null) return null;- if (val instanceof Date) return val;-- if (val instanceof String) return parseMath(null,(String)val);-+ if (val instanceof String) {+ return DateFormatUtil.parseMath(null, (String)val);+ }return super.toNativeType(val);}}diff --git a/solr/core/src/java/org/apache/solr/schema/TrieField.java b/solr/core/src/java/org/apache/solr/schema/TrieField.javaindex 84d526022b8..d3b9c2900c0 100644--- a/solr/core/src/java/org/apache/solr/schema/TrieField.java+++ b/solr/core/src/java/org/apache/solr/schema/TrieField.java@@ -54,6 +54,7 @@ import org.apache.lucene.util.mutable.MutableValueLong;import org.apache.solr.common.SolrException;import org.apache.solr.response.TextResponseWriter;import org.apache.solr.search.QParser;+import org.apache.solr.util.DateFormatUtil;/*** Provides field types to support for Lucene's {@link@@ -81,13 +82,6 @@ public class TrieField extends PrimitiveFieldType {protected int precisionStepArg = TrieField.DEFAULT_PRECISION_STEP; // the one passed in or defaultedprotected int precisionStep; // normalizedprotected TrieTypes type;- protected Object missingValue;--- /**- * Used for handling date types- */- static final TrieDateField dateField = new TrieDateField();@Overrideprotected void init(IndexSchema schema, Map<String, String> args) {@@ -304,7 +298,7 @@ public class TrieField extends PrimitiveFieldType {return super.getRangeQuery(parser, field, min, max, minInclusive, maxInclusive);}int ps = precisionStep;- Query query = null;+ Query query;final boolean matchOnly = field.hasDocValues() && !field.indexed();switch (type) {case INTEGER:@@ -362,13 +356,13 @@ public class TrieField extends PrimitiveFieldType {case DATE:if (matchOnly) {query = DocValuesRangeQuery.newLongRange(field.getName(),- min == null ? null : dateField.parseMath(null, min).getTime(),- max == null ? null : dateField.parseMath(null, max).getTime(),+ min == null ? null : DateFormatUtil.parseMath(null, min).getTime(),+ max == null ? null : DateFormatUtil.parseMath(null, max).getTime(),minInclusive, maxInclusive);} else {query = NumericRangeQuery.newLongRange(field.getName(), ps,- min == null ? null : dateField.parseMath(null, min).getTime(),- max == null ? null : dateField.parseMath(null, max).getTime(),+ min == null ? null : DateFormatUtil.parseMath(null, min).getTime(),+ max == null ? null : DateFormatUtil.parseMath(null, max).getTime(),minInclusive, maxInclusive);}break;@@ -432,7 +426,7 @@ public class TrieField extends PrimitiveFieldType {NumericUtils.longToPrefixCodedBytes(NumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);break;case DATE:- NumericUtils.longToPrefixCodedBytes(dateField.parseMath(null, s).getTime(), 0, result);+ NumericUtils.longToPrefixCodedBytes(DateFormatUtil.parseMath(null, s).getTime(), 0, result);break;default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);@@ -456,7 +450,7 @@ public class TrieField extends PrimitiveFieldType {@Overridepublic String toExternal(StorableField f) {return (type == TrieTypes.DATE)- ? dateField.toExternal((Date) toObject(f))+ ? DateFormatUtil.formatExternal((Date) toObject(f)): toObject(f).toString();}@@ -473,7 +467,7 @@ public class TrieField extends PrimitiveFieldType {case DOUBLE:return Double.toString( NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexedForm)) );case DATE:- return dateField.toExternal( new Date(NumericUtils.prefixCodedToLong(indexedForm)) );+ return DateFormatUtil.formatExternal(new Date(NumericUtils.prefixCodedToLong(indexedForm)));default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);}@@ -496,7 +490,7 @@ public class TrieField extends PrimitiveFieldType {value = Double.toString( NumericUtils.sortableLongToDouble(NumericUtils.prefixCodedToLong(indexedForm)) );break;case DATE:- value = dateField.toExternal( new Date(NumericUtils.prefixCodedToLong(indexedForm)) );+ value = DateFormatUtil.formatExternal(new Date(NumericUtils.prefixCodedToLong(indexedForm)));break;default:throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);@@ -654,7 +648,7 @@ public class TrieField extends PrimitiveFieldType {case DATE:Date date = (value instanceof Date)? ((Date)value)- : dateField.parseMath(null, value.toString());+ : DateFormatUtil.parseMath(null, value.toString());f = new org.apache.lucene.document.LongField(field.getName(), date.getTime(), ft);break;default:@@ -759,12 +753,12 @@ class TrieDateFieldSource extends LongFieldSource {@Overridepublic String longToString(long val) {- return TrieField.dateField.toExternal(longToObject(val));+ return DateFormatUtil.formatExternal(longToObject(val));}@Overridepublic long externalToLong(String extVal) {- return TrieField.dateField.parseMath(null, extVal).getTime();+ return DateFormatUtil.parseMath(null, extVal).getTime();}}diff --git a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.javaindex e0c9fb2ca10..19936a209ec 100644--- a/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java+++ b/solr/core/src/java/org/apache/solr/search/ValueSourceParser.java@@ -54,6 +54,7 @@ import org.apache.solr.search.function.CollapseScoreFunction;import org.apache.solr.search.function.OrdFieldSource;import org.apache.solr.search.function.ReverseOrdFieldSource;import org.apache.solr.search.function.distance.*;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.plugin.NamedListInitializedPlugin;import java.io.IOException;@@ -974,8 +975,6 @@ public abstract class ValueSourceParser implements NamedListInitializedPlugin {class DateValueSourceParser extends ValueSourceParser {- TrieDateField df = new TrieDateField();-@Overridepublic void init(NamedList args) {}@@ -983,7 +982,7 @@ class DateValueSourceParser extends ValueSourceParser {public Date getDate(FunctionQParser fp, String arg) {if (arg == null) return null;if (arg.startsWith("NOW") || (arg.length() > 0 && Character.isDigit(arg.charAt(0)))) {- return df.parseMathLenient(null, arg, fp.req);+ return DateFormatUtil.parseMathLenient(null, arg, fp.req);}return null;}diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRange.javaindex 124df7c4e7b..3b13967b675 100644--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRange.java@@ -34,6 +34,7 @@ import org.apache.solr.schema.TrieDateField;import org.apache.solr.schema.TrieField;import org.apache.solr.search.DocSet;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;public class FacetRange extends FacetRequest {String field;@@ -533,11 +534,11 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {@Overridepublic String formatValue(Comparable val) {- return ((TrieDateField)field.getType()).toExternal( (Date)val );+ return DateFormatUtil.formatExternal( (Date)val );}@Overrideprotected Date parseStr(String rawval) {- return ((TrieDateField)field.getType()).parseMath(now, rawval);+ return DateFormatUtil.parseMath(now, rawval);}@Overrideprotected Object parseGap(final String rawval) {diff --git a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.javaindex fa57cb54166..7dc553b4f56 100644--- a/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java+++ b/solr/core/src/java/org/apache/solr/update/processor/DocExpirationUpdateProcessorFactory.java@@ -20,12 +20,13 @@ package org.apache.solr.update.processor;import java.io.IOException;import org.apache.solr.common.SolrException;+import static org.apache.solr.common.SolrException.ErrorCode.*;+import org.apache.solr.common.util.NamedList;import org.apache.solr.common.SolrInputDocument;import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.Slice;-import org.apache.solr.core.CloseHook;import org.apache.solr.core.SolrCore;import org.apache.solr.core.CoreContainer;@@ -35,11 +36,11 @@ import org.apache.solr.request.SolrRequestInfo;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.LocalSolrQueryRequest;import org.apache.solr.response.SolrQueryResponse;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.update.AddUpdateCommand;import org.apache.solr.update.CommitUpdateCommand;import org.apache.solr.update.DeleteUpdateCommand;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.DefaultSolrThreadFactory;import org.apache.solr.util.plugin.SolrCoreAware;@@ -402,7 +403,7 @@ public final class DocExpirationUpdateProcessorFactorytry {DeleteUpdateCommand del = new DeleteUpdateCommand(req);del.setQuery("{!cache=false}" + expireField + ":[* TO " +- TrieDateField.formatExternal(SolrRequestInfo.getRequestInfo().getNOW())+ DateFormatUtil.formatExternal(SolrRequestInfo.getRequestInfo().getNOW())+ "]");proc.processDelete(del);diff --git a/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java b/solr/core/src/java/org/apache/solr/util/DateFormatUtil.javanew file mode 100644index 00000000000..f06118af6c3--- /dev/null+++ b/solr/core/src/java/org/apache/solr/util/DateFormatUtil.java@@ -0,0 +1,258 @@+package org.apache.solr.util;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import java.text.DateFormat;+import java.text.DecimalFormat;+import java.text.DecimalFormatSymbols;+import java.text.FieldPosition;+import java.text.NumberFormat;+import java.text.ParseException;+import java.text.ParsePosition;+import java.text.SimpleDateFormat;+import java.util.Date;+import java.util.Locale;+import java.util.TimeZone;++import org.apache.solr.common.SolrException;+import org.apache.solr.common.util.DateUtil;+import org.apache.solr.request.SolrQueryRequest;++public final class DateFormatUtil {++ public static final TimeZone UTC = TimeZone.getTimeZone("UTC");+ /**+ * Fixed TimeZone (UTC) needed for parsing/formatting Dates in the+ * canonical representation.+ */+ public static final TimeZone CANONICAL_TZ = UTC;+ /**+ * Fixed Locale needed for parsing/formatting Milliseconds in the+ * canonical representation.+ */+ public static final Locale CANONICAL_LOCALE = Locale.ROOT;+ public static final String NOW = "NOW";+ public static final char Z = 'Z';+ /**+ * Thread safe DateFormat that can <b>format</b> in the canonical+ * ISO8601 date format, not including the trailing "Z" (since it is+ * left off in the internal indexed values)+ */+ public final static ThreadLocalDateFormat FORMAT_THREAD_LOCAL+ = new ThreadLocalDateFormat(new ISO8601CanonicalDateFormat());++ private DateFormatUtil() {}++ /**+ * Parses a String which may be a date (in the standard format)+ * followed by an optional math expression.+ * @param now an optional fixed date to use as "NOW" in the DateMathParser+ * @param val the string to parse+ */+ public static Date parseMath(Date now, String val) {+ String math;+ final DateMathParser p = new DateMathParser();++ if (null != now) p.setNow(now);++ if (val.startsWith(NOW)) {+ math = val.substring(NOW.length());+ } else {+ final int zz = val.indexOf(Z);+ if (0 < zz) {+ math = val.substring(zz+1);+ try {+ // p.setNow(toObject(val.substring(0,zz)));+ p.setNow(parseDate(val.substring(0,zz+1)));+ } catch (ParseException e) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date in Date Math String:'" + val + '\'', e);+ }+ } else {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date String:'" +val+'\'');+ }+ }++ if (null == math || math.equals("")) {+ return p.getNow();+ }++ try {+ return p.parseMath(math);+ } catch (ParseException e) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date Math String:'" +val+'\'',e);+ }+ }++ /**+ * Return the standard human readable form of the date (with trailing 'Z')+ */+ public static String formatExternal(Date d) {+ return FORMAT_THREAD_LOCAL.get().format(d) + Z;+ }++ /**+ * Return the standard human readable form of the date+ */+ public static String formatDate(Date d) {+ return FORMAT_THREAD_LOCAL.get().format(d);+ }++ /**+ * Thread safe method that can be used to parse a Date+ * without the trailing 'Z'+ */+ public static Date parseDate(String s) throws ParseException {+ return FORMAT_THREAD_LOCAL.get().parse(s);+ }++ /** Parse a date string in the standard format, or any supported by DateUtil.parseDate */+ public static Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException {+ // request could define timezone in the future+ try {+ return DateFormatUtil.FORMAT_THREAD_LOCAL.get().parse(s);+ } catch (Exception e) {+ return DateUtil.parseDate(s);+ }+ }++ /**+ * Parses a String which may be a date+ * followed by an optional math expression.+ * @param now an optional fixed date to use as "NOW" in the DateMathParser+ * @param val the string to parse+ */+ public static Date parseMathLenient(Date now, String val, SolrQueryRequest req) {+ String math;+ final DateMathParser p = new DateMathParser();++ if (null != now) p.setNow(now);++ if (val.startsWith(DateFormatUtil.NOW)) {+ math = val.substring(DateFormatUtil.NOW.length());+ } else {+ final int zz = val.indexOf(DateFormatUtil.Z);+ if (0 < zz) {+ math = val.substring(zz+1);+ try {+ // p.setNow(toObject(val.substring(0,zz)));+ p.setNow(parseDateLenient(val.substring(0,zz+1), req));+ } catch (ParseException e) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date in Date Math String: '" + val + '\'', e);+ }+ } else {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date String: '" +val+'\'');+ }+ }++ if (null == math || math.equals("")) {+ return p.getNow();+ }++ try {+ return p.parseMath(math);+ } catch (ParseException e) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "Invalid Date Math String: '" +val+'\'',e);+ }+ }++ @SuppressWarnings("serial")+ static class ISO8601CanonicalDateFormat extends SimpleDateFormat {++ protected NumberFormat millisParser+ = NumberFormat.getIntegerInstance(CANONICAL_LOCALE);++ protected NumberFormat millisFormat = new DecimalFormat+ (".###", new DecimalFormatSymbols(CANONICAL_LOCALE));++ public ISO8601CanonicalDateFormat() {+ super("yyyy-MM-dd'T'HH:mm:ss", CANONICAL_LOCALE);+ this.setTimeZone(CANONICAL_TZ);+ }++ @Override+ public Date parse(String i, ParsePosition p) {+ /* delegate to SimpleDateFormat for easy stuff */+ Date d = super.parse(i, p);+ int milliIndex = p.getIndex();+ /* worry about the milliseconds ourselves */+ if (null != d &&+ -1 == p.getErrorIndex() &&+ milliIndex + 1 < i.length() &&+ '.' == i.charAt(milliIndex)) {+ p.setIndex(++milliIndex); // NOTE: ++ to chomp '.'+ Number millis = millisParser.parse(i, p);+ if (-1 == p.getErrorIndex()) {+ int endIndex = p.getIndex();+ d = new Date(d.getTime()+ + (long)(millis.doubleValue() * Math.pow(10, (3 - endIndex + milliIndex))));+ }+ }+ return d;+ }++ @Override+ public StringBuffer format(Date d, StringBuffer toAppendTo, FieldPosition pos) {+ /* delegate to SimpleDateFormat for easy stuff */+ super.format(d, toAppendTo, pos);+ /* worry about the milliseconds ourselves */+ long millis = d.getTime() % 1000l;+ if (0L == millis) {+ return toAppendTo;+ }+ if (millis < 0L) {+ // original date was prior to epoch+ millis += 1000L;+ }+ int posBegin = toAppendTo.length();+ toAppendTo.append(millisFormat.format(millis / 1000d));+ if (DateFormat.MILLISECOND_FIELD == pos.getField()) {+ pos.setBeginIndex(posBegin);+ pos.setEndIndex(toAppendTo.length());+ }+ return toAppendTo;+ }++ @Override+ public DateFormat clone() {+ ISO8601CanonicalDateFormat c = (ISO8601CanonicalDateFormat)super.clone();+ c.millisParser = NumberFormat.getIntegerInstance(CANONICAL_LOCALE);+ c.millisFormat = new DecimalFormat(".###", new DecimalFormatSymbols(CANONICAL_LOCALE));+ return c;+ }+ }++ public static class ThreadLocalDateFormat extends ThreadLocal<DateFormat> {+ private final DateFormat proto;++ public ThreadLocalDateFormat(DateFormat d) {+ super();+ proto = d;+ }++ @Override+ protected DateFormat initialValue() {+ return (DateFormat) proto.clone();+ }+ }+}diff --git a/solr/core/src/test/org/apache/solr/TestTrie.java b/solr/core/src/test/org/apache/solr/TestTrie.javaindex e9da8bc9f96..db855c3bd99 100644--- a/solr/core/src/test/org/apache/solr/TestTrie.java+++ b/solr/core/src/test/org/apache/solr/TestTrie.java@@ -18,9 +18,9 @@ package org.apache.solr;import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.schema.FieldType;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.schema.TrieField;import org.apache.solr.util.DateMathParser;+import org.apache.solr.util.DateFormatUtil;import org.junit.After;import org.junit.BeforeClass;import org.junit.Test;@@ -173,7 +173,7 @@ public class TestTrie extends SolrTestCaseJ4 {format.setTimeZone(TimeZone.getTimeZone("UTC"));assertU(delQ("*:*"));- DateMathParser dmp = new DateMathParser(TrieDateField.UTC, Locale.ROOT);+ DateMathParser dmp = new DateMathParser(DateFormatUtil.UTC, Locale.ROOT);String largestDate = "";for (int i = 0; i < 10; i++) {// index 10 days starting with today@@ -222,7 +222,7 @@ public class TestTrie extends SolrTestCaseJ4 {// For tdate testsSimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT);format.setTimeZone(TimeZone.getTimeZone("UTC"));- DateMathParser dmp = new DateMathParser(TrieDateField.UTC, Locale.ROOT);+ DateMathParser dmp = new DateMathParser(DateFormatUtil.UTC, Locale.ROOT);for (int i = 0; i < 10; i++) {long l = Integer.MAX_VALUE + i*1L;diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java b/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.javaindex 22bb7df91e7..60c95b550f6 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestCloudPivotFacet.java@@ -29,7 +29,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.params.StatsParams;import org.apache.solr.common.util.NamedList;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.junit.BeforeClass;import org.junit.Test;import org.slf4j.Logger;@@ -468,7 +468,7 @@ public class TestCloudPivotFacet extends AbstractFullDistribZkTestBase {// otherwise, build up a term filter...String prefix = "{!term f=" + constraint.getField() + "}";if (value instanceof Date) {- return prefix + TrieDateField.formatExternal((Date)value);+ return prefix + DateFormatUtil.formatExternal((Date)value);} else {return prefix + value;}diff --git a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.javaindex 9bbb29f9570..7dff39fe4c3 100644--- a/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java+++ b/solr/core/src/test/org/apache/solr/request/SimpleFacetsTest.java@@ -36,7 +36,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.response.SolrQueryResponse;import org.apache.solr.schema.SchemaField;-import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.TimeZoneUtils;import org.junit.BeforeClass;import org.junit.Test;@@ -2992,8 +2992,8 @@ public class SimpleFacetsTest extends SolrTestCaseJ4 {}int gapNum = random().nextInt(100) + 1;- params.add(FacetParams.FACET_RANGE_START, TrieDateField.formatExternal(dates[0]));- params.add(FacetParams.FACET_RANGE_END, TrieDateField.formatExternal(dates[1]));+ params.add(FacetParams.FACET_RANGE_START, DateFormatUtil.formatExternal(dates[0]));+ params.add(FacetParams.FACET_RANGE_END, DateFormatUtil.formatExternal(dates[1]));params.add(FacetParams.FACET_RANGE_GAP, String.format(Locale.ROOT, "+%d%s", gapNum, gapUnit));addCommonRandomRangeParams(params);params.add(FacetParams.FACET_RANGE, field);diff --git a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.javaindex a5da2b4e168..1739c71ed40 100644--- a/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java+++ b/solr/core/src/test/org/apache/solr/schema/DateFieldTest.java@@ -22,7 +22,7 @@ import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.core.SolrConfig;import org.apache.solr.core.SolrResourceLoader;import org.apache.solr.util.DateMathParser;-+import org.apache.solr.util.DateFormatUtil;import org.junit.BeforeClass;import org.junit.Ignore;@@ -34,7 +34,7 @@ import java.util.TimeZone;import java.util.Locale;public class DateFieldTest extends SolrTestCaseJ4 {- public static TimeZone UTC = TimeZone.getTimeZone("UTC");+ public static TimeZone UTC = DateFormatUtil.UTC;private final String testInstanceDir = TEST_HOME() + File.separator + "collection1";private final String testConfHome = testInstanceDir + File.separator + "conf"+ File.separator;private TrieDateField f = null;@@ -54,11 +54,11 @@ public class DateFieldTest extends SolrTestCaseJ4 {}public void assertFormatParsed(String expected, String input) throws ParseException {- assertEquals("Input: " + input, expected, f.formatDate(f.parseMath(new Date(), input)));+ assertEquals("Input: " + input, expected, DateFormatUtil.formatDate(DateFormatUtil.parseMath(new Date(), input)));}public void assertFormatDate(String expected, long input) {- assertEquals("Input: " + input, expected, f.formatDate(new Date(input)));+ assertEquals("Input: " + input, expected, DateFormatUtil.formatDate(new Date(input)));}public void testToInternal() throws Exception {@@ -77,7 +77,7 @@ public class DateFieldTest extends SolrTestCaseJ4 {assertFormatParsed("1995-12-31T23:59:59", "1995-12-31T23:59:59.0Z");// kind of kludgy, but we have other tests for the actual date math- assertFormatParsed(f.formatDate(p.parseMath("/DAY")), "NOW/DAY");+ assertFormatParsed(DateFormatUtil.formatDate(p.parseMath("/DAY")), "NOW/DAY");// as of Solr 1.3assertFormatParsed("1995-12-31T00:00:00", "1995-12-31T23:59:59Z/DAY");@@ -94,7 +94,7 @@ public class DateFieldTest extends SolrTestCaseJ4 {public void assertParseMath(long expected, String input) {Date d = new Date(0);- assertEquals("Input: "+input, expected, f.parseMath(d, input).getTime());+ assertEquals("Input: "+input, expected, DateFormatUtil.parseMath(d, input).getTime());}// as of Solr1.3@@ -171,12 +171,12 @@ public class DateFieldTest extends SolrTestCaseJ4 {}protected void assertFormat(final String expected, final long millis) {- assertEquals(expected, f.formatDate(new Date(millis)));+ assertEquals(expected, DateFormatUtil.formatDate(new Date(millis)));}protected void assertRoundTrip(String canonicalDate) throws Exception {- Date d = TrieDateField.parseDate(canonicalDate);- String result = TrieDateField.formatExternal(d);+ Date d = DateFormatUtil.parseDate(canonicalDate);+ String result = DateFormatUtil.formatExternal(d);assertEquals("d:" + d.getTime(), canonicalDate, result);}diff --git a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.javaindex b726a6aade0..989e4730e5d 100644--- a/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java+++ b/solr/core/src/test/org/apache/solr/update/processor/AtomicUpdatesTest.java@@ -7,6 +7,7 @@ import java.util.List;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.SolrInputDocument;import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.junit.Before;import org.junit.BeforeClass;import org.junit.Ignore;@@ -598,45 +599,45 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {doc = new SolrInputDocument();doc.setField("id", "10001");TrieDateField trieDF = new TrieDateField();- Date tempDate = trieDF.parseMath(null, "2014-02-01T12:00:00Z");- doc.setField("dateRemove", new Date[]{trieDF.parseMath(null, "2014-02-01T12:00:00Z"),- trieDF.parseMath(null, "2014-07-02T12:00:00Z"),- trieDF.parseMath(null, "2014-02-03T12:00:00Z"),- trieDF.parseMath(null, "2014-02-03T12:00:00Z"),- trieDF.parseMath(null, "2014-02-04T12:00:00Z")+ Date tempDate = DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z");+ doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-07-02T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")});assertU(adoc(doc));doc = new SolrInputDocument();doc.setField("id", "10002");- doc.setField("dateRemove", new Date[]{trieDF.parseMath(null, "2014-02-01T12:00:00Z"),- trieDF.parseMath(null, "2014-07-02T12:00:00Z"),- trieDF.parseMath(null, "2014-02-02T12:00:00Z"),- trieDF.parseMath(null, "2014-02-03T12:00:00Z"),- trieDF.parseMath(null, "2014-02-04T12:00:00Z")+ doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-07-02T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")});assertU(adoc(doc));doc = new SolrInputDocument();doc.setField("id", "10020");- doc.setField("dateRemove", new Date[]{trieDF.parseMath(null, "2014-02-01T12:00:00Z"),- trieDF.parseMath(null, "2014-02-03T12:00:00Z"),- trieDF.parseMath(null, "2014-02-04T12:00:00Z")+ doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-03T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")});assertU(adoc(doc));doc = new SolrInputDocument();doc.setField("id", "10021");- doc.setField("dateRemove", new Date[]{trieDF.parseMath(null, "2014-02-01T12:00:00Z"),- trieDF.parseMath(null, "2014-02-02T12:00:00Z"),- trieDF.parseMath(null, "2014-02-04T12:00:00Z")+ doc.setField("dateRemove", new Date[]{DateFormatUtil.parseMath(null, "2014-02-01T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z"),+ DateFormatUtil.parseMath(null, "2014-02-04T12:00:00Z")});assertU(adoc(doc));assertU(commit());assertQ(req("q", "dateRemove:*", "indent", "true"), "//result[@numFound = '4']");- String dateString = trieDF.parseMath(null, "2014-02-02T12:00:00Z").toString();+ String dateString = DateFormatUtil.parseMath(null, "2014-02-02T12:00:00Z").toString();// assertQ(req("q", "dateRemove:"+URLEncoder.encode(dateString, "UTF-8"), "indent", "true"), "//result[@numFound = '3']");// assertQ(req("q", "dateRemove:\"2014-09-02T12:00:00Z\"", "indent", "true"), "//result[@numFound = '3']");// assertQ(req("q", "dateRemove:"+dateString, "indent", "true"), "//result[@numFound = '3']"); //Sun Feb 02 10:00:00 FNT 2014@@ -646,8 +647,8 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {doc = new SolrInputDocument();doc.setField("id", "10001");List<Date> removeList = new ArrayList<Date>();- removeList.add(trieDF.parseMath(null, "2014-09-02T12:00:00Z"));- removeList.add(trieDF.parseMath(null, "2014-09-03T12:00:00Z"));+ removeList.add(DateFormatUtil.parseMath(null, "2014-09-02T12:00:00Z"));+ removeList.add(DateFormatUtil.parseMath(null, "2014-09-03T12:00:00Z"));doc.setField("dateRemove", ImmutableMap.of("remove", removeList)); //behavior when hitting Solr through ZKassertU(adoc(doc));@@ -659,8 +660,8 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {doc = new SolrInputDocument();doc.setField("id", "10021");removeList = new ArrayList<Date>();- removeList.add(trieDF.parseMath(null, "2014-09-02T12:00:00Z"));- removeList.add(trieDF.parseMath(null, "2014-09-03T12:00:00Z"));+ removeList.add(DateFormatUtil.parseMath(null, "2014-09-02T12:00:00Z"));+ removeList.add(DateFormatUtil.parseMath(null, "2014-09-03T12:00:00Z"));doc.setField("dateRemove", ImmutableMap.of("remove", removeList)); //behavior when hitting Solr through ZKassertU(adoc(doc));assertU(commit());@@ -670,7 +671,7 @@ public class AtomicUpdatesTest extends SolrTestCaseJ4 {doc = new SolrInputDocument();doc.setField("id", "10001");- doc.setField("dateRemove", ImmutableMap.of("remove", trieDF.parseMath(null, "2014-09-01T12:00:00Z"))); //behavior when hitting Solr directly+ doc.setField("dateRemove", ImmutableMap.of("remove", DateFormatUtil.parseMath(null, "2014-09-01T12:00:00Z"))); //behavior when hitting Solr directlyassertU(adoc(doc));assertU(commit());diff --git a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.javaindex 21cb96fe9aa..48779277efe 100644--- a/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java+++ b/solr/test-framework/src/java/org/apache/solr/BaseDistributedSearchTestCase.java@@ -18,6 +18,7 @@ package org.apache.solr;*/import junit.framework.Assert;+import org.apache.commons.io.FileUtils;import org.apache.lucene.util.Constants;import org.apache.lucene.util.TestUtil;@@ -37,6 +38,7 @@ import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;import org.apache.solr.schema.TrieDateField;+import org.apache.solr.util.DateFormatUtil;import org.eclipse.jetty.servlet.ServletHolder;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -48,6 +50,7 @@ import org.slf4j.Logger;import org.slf4j.LoggerFactory;import javax.servlet.Filter;+import java.io.File;import java.io.IOException;import java.lang.annotation.ElementType;@@ -1042,13 +1045,11 @@ public abstract class BaseDistributedSearchTestCase extends SolrTestCaseJ4 {}public static class RandDate extends RandVal {- public static TrieDateField df = new TrieDateField();-@Overridepublic Object val() {long v = r.nextLong();Date d = new Date(v);- return df.toExternal(d);+ return DateFormatUtil.formatExternal(d);}}diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.javaindex 31a59cb9818..9b5e34d7732 100644--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java@@ -93,10 +93,10 @@ import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestHandler;import org.apache.solr.schema.IndexSchema;import org.apache.solr.schema.SchemaField;-import org.apache.solr.schema.TrieDateField;import org.apache.solr.search.SolrIndexSearcher;import org.apache.solr.servlet.DirectSolrConnection;import org.apache.solr.util.AbstractSolrTestCase;+import org.apache.solr.util.DateFormatUtil;import org.apache.solr.util.RevertDefaultThreadHandlerRule;import org.apache.solr.util.SSLTestConfig;import org.apache.solr.util.TestHarness;@@ -2087,7 +2087,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {* @see #randomSkewedDate*/public static String randomDate() {- return TrieDateField.formatExternal(new Date(random().nextLong()));+ return DateFormatUtil.formatExternal(new Date(random().nextLong()));}/**