Apache Lucene open-source search software
LUCENE-4199: allow setting of tz used for date range parsing
Robert Muir5fea62f7c82c
diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.javaindex 5ba1d07a416..13ede4260d7 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/classic/QueryParserBase.java@@ -71,6 +71,7 @@ public abstract class QueryParserBase {float fuzzyMinSim = FuzzyQuery.defaultMinSimilarity;int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;Locale locale = Locale.getDefault();+ TimeZone timeZone = TimeZone.getDefault();// the default date resolutionDateTools.Resolution dateResolution = null;@@ -329,6 +330,14 @@ public abstract class QueryParserBase {public Locale getLocale() {return locale;}++ public void setTimeZone(TimeZone timeZone) {+ this.timeZone = timeZone;+ }++ public TimeZone getTimeZone() {+ return timeZone;+ }/*** Sets the default date resolution used by RangeQueries for fields for which no@@ -678,7 +687,7 @@ public abstract class QueryParserBase {// The user can only specify the date, not the time, so make sure// the time is set to the latest possible time of that date to really// include all documents:- Calendar cal = Calendar.getInstance(locale);+ Calendar cal = Calendar.getInstance(timeZone, locale);cal.setTime(d2);cal.set(Calendar.HOUR_OF_DAY, 23);cal.set(Calendar.MINUTE, 59);diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/StandardQueryParser.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/StandardQueryParser.javaindex bd2235c9c77..9c49ee5e7bc 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/StandardQueryParser.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/StandardQueryParser.java@@ -19,6 +19,7 @@ package org.apache.lucene.queryparser.flexible.standard;import java.util.Locale;import java.util.Map;+import java.util.TimeZone;import java.util.TooManyListenersException;import org.apache.lucene.analysis.Analyzer;@@ -344,6 +345,14 @@ public class StandardQueryParser extends QueryParserHelper {return getQueryConfigHandler().get(ConfigurationKeys.LOCALE);}+ public void setTimeZone(TimeZone timeZone) {+ getQueryConfigHandler().set(ConfigurationKeys.TIMEZONE, timeZone);+ }++ public TimeZone getTimeZone() {+ return getQueryConfigHandler().get(ConfigurationKeys.TIMEZONE);+ }+/*** Sets the default slop for phrases. If zero, then exact phrase matches are* required. Default value is zero.diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/StandardQueryConfigHandler.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/StandardQueryConfigHandler.javaindex 7f814dd7bf0..fa9ff7e255c 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/StandardQueryConfigHandler.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/config/StandardQueryConfigHandler.java@@ -21,6 +21,7 @@ import java.util.HashMap;import java.util.LinkedHashMap;import java.util.Locale;import java.util.Map;+import java.util.TimeZone;import org.apache.lucene.analysis.Analyzer;import org.apache.lucene.document.DateTools;@@ -101,6 +102,8 @@ public class StandardQueryConfigHandler extends QueryConfigHandler {*/final public static ConfigurationKey<Locale> LOCALE = ConfigurationKey.newInstance();+ final public static ConfigurationKey<TimeZone> TIMEZONE = ConfigurationKey.newInstance();+/*** Key used to set the {@link RewriteMethod} used when creating queries*diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.javaindex 03b65da5d0b..b6c05e2f99f 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/nodes/NumericQueryNode.java@@ -90,7 +90,7 @@ public class NumericQueryNode extends QueryNodeImpl implements* @return the value converte to {@link String} and escaped*/protected CharSequence getTermEscaped(EscapeQuerySyntax escaper) {- return escaper.escape(NumberFormat.getNumberInstance().format(this.value),+ return escaper.escape(numberFormat.format(this.value),Locale.ROOT, Type.NORMAL);}diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.javaindex caa09360709..48ce640cb7a 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/standard/processors/TermRangeQueryNodeProcessor.java@@ -22,6 +22,7 @@ import java.util.Calendar;import java.util.Date;import java.util.List;import java.util.Locale;+import java.util.TimeZone;import org.apache.lucene.document.DateTools;import org.apache.lucene.document.DateTools.Resolution;@@ -76,6 +77,12 @@ public class TermRangeQueryNodeProcessor extends QueryNodeProcessorImpl {locale = Locale.getDefault();}+ TimeZone timeZone = getQueryConfigHandler().get(ConfigurationKeys.TIMEZONE);++ if (timeZone == null) {+ timeZone = TimeZone.getDefault();+ }+CharSequence field = termRangeNode.getField();String fieldStr = null;@@ -114,7 +121,7 @@ public class TermRangeQueryNodeProcessor extends QueryNodeProcessorImpl {// the time is set to the latest possible time of that date to// really// include all documents:- Calendar cal = Calendar.getInstance(locale);+ Calendar cal = Calendar.getInstance(timeZone, locale);cal.setTime(d2);cal.set(Calendar.HOUR_OF_DAY, 23);cal.set(Calendar.MINUTE, 59);