Skip to content

Apache Lucene open-source search software

LUCENE-1846: Fix more Locale problems

Uwe Schindler5dd1810b0cc2
diff --git a/CHANGES.txt b/CHANGES.txt
index ed48d1b8f7a..000ca47e774 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -195,6 +195,12 @@ Changes in runtime behavior
basis. There is currently no way provided to rebase the docids in the Scorer to
the top level IndexReader. (Mark Miller, Mike McCandless)
+14. LUCENE-1846: DateTools now uses the US locale to format the numbers in its
+ date/time strings instead of the default locale. For most locales there will
+ be no change in the index format, as DateFormatSymbols is using ASCII digits.
+ The usage of the US locale is important to guarantee correct ordering of
+ generated terms. (Uwe Schindler)
+
API Changes
1. LUCENE-1419: Add expert API to set custom indexing chain. This API is
diff --git a/contrib/analyzers/common/src/test/org/apache/lucene/analysis/sinks/DateRecognizerSinkTokenizerTest.java b/contrib/analyzers/common/src/test/org/apache/lucene/analysis/sinks/DateRecognizerSinkTokenizerTest.java
index cbb6990b820..baad73dddd5 100644
--- a/contrib/analyzers/common/src/test/org/apache/lucene/analysis/sinks/DateRecognizerSinkTokenizerTest.java
+++ b/contrib/analyzers/common/src/test/org/apache/lucene/analysis/sinks/DateRecognizerSinkTokenizerTest.java
@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.sinks;
import java.io.IOException;
import java.io.StringReader;
import java.text.SimpleDateFormat;
+import java.util.Locale;
import junit.framework.TestCase;
@@ -41,7 +42,7 @@ public class DateRecognizerSinkTokenizerTest extends TestCase {
}
public void test() throws IOException {
- DateRecognizerSinkFilter sinkFilter = new DateRecognizerSinkFilter(new SimpleDateFormat("MM/dd/yyyy"));
+ DateRecognizerSinkFilter sinkFilter = new DateRecognizerSinkFilter(new SimpleDateFormat("MM/dd/yyyy", Locale.US));
String test = "The quick red fox jumped over the lazy brown dogs on 7/11/2006 The dogs finally reacted on 7/12/2006";
TeeSinkTokenFilter tee = new TeeSinkTokenFilter(new WhitespaceTokenizer(new StringReader(test)));
SinkTokenStream sink = tee.newSinkTokenStream(sinkFilter);
diff --git a/src/java/org/apache/lucene/document/DateTools.java b/src/java/org/apache/lucene/document/DateTools.java
index b4db10aa20f..e45ab052fef 100644
--- a/src/java/org/apache/lucene/document/DateTools.java
+++ b/src/java/org/apache/lucene/document/DateTools.java
@@ -22,6 +22,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
+import java.util.Locale;
import org.apache.lucene.search.NumericRangeQuery; // for javadocs
import org.apache.lucene.util.NumericUtils; // for javadocs
@@ -52,13 +53,13 @@ public class DateTools {
private final static TimeZone GMT = TimeZone.getTimeZone("GMT");
- private static final SimpleDateFormat YEAR_FORMAT = new SimpleDateFormat("yyyy");
- private static final SimpleDateFormat MONTH_FORMAT = new SimpleDateFormat("yyyyMM");
- private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("yyyyMMdd");
- private static final SimpleDateFormat HOUR_FORMAT = new SimpleDateFormat("yyyyMMddHH");
- private static final SimpleDateFormat MINUTE_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
- private static final SimpleDateFormat SECOND_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");
- private static final SimpleDateFormat MILLISECOND_FORMAT = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+ private static final SimpleDateFormat YEAR_FORMAT = new SimpleDateFormat("yyyy", Locale.US);
+ private static final SimpleDateFormat MONTH_FORMAT = new SimpleDateFormat("yyyyMM", Locale.US);
+ private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("yyyyMMdd", Locale.US);
+ private static final SimpleDateFormat HOUR_FORMAT = new SimpleDateFormat("yyyyMMddHH", Locale.US);
+ private static final SimpleDateFormat MINUTE_FORMAT = new SimpleDateFormat("yyyyMMddHHmm", Locale.US);
+ private static final SimpleDateFormat SECOND_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss", Locale.US);
+ private static final SimpleDateFormat MILLISECOND_FORMAT = new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.US);
static {
// times need to be normalized so the value doesn't depend on the
// location the index is created/used:
diff --git a/src/test/org/apache/lucene/document/TestDateTools.java b/src/test/org/apache/lucene/document/TestDateTools.java
index e27d2a5217b..afaf75e9860 100644
--- a/src/test/org/apache/lucene/document/TestDateTools.java
+++ b/src/test/org/apache/lucene/document/TestDateTools.java
@@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
+import java.util.Locale;
import org.apache.lucene.util.LuceneTestCase;
@@ -172,7 +173,7 @@ public class TestDateTools extends LuceneTestCase {
}
private String isoFormat(Date date) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
return sdf.format(date);
}