mirror of https://github.com/apache/lucene.git
LUCENE-1852: Fix localization test failures.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@807499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4b6e01654c
commit
e8caefdb7d
|
@ -813,6 +813,9 @@ Test Cases
|
||||||
MultiSearcher when possible to help excercise more edge cases.
|
MultiSearcher when possible to help excercise more edge cases.
|
||||||
(Chris Hostetter, Mark Miller)
|
(Chris Hostetter, Mark Miller)
|
||||||
|
|
||||||
|
2. LUCENE-1852: Fix localization test failures.
|
||||||
|
(Robert Muir via Michael Busch)
|
||||||
|
|
||||||
======================= Release 2.4.1 2009-03-09 =======================
|
======================= Release 2.4.1 2009-03-09 =======================
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
|
|
|
@ -17,11 +17,9 @@ package org.apache.lucene.queryParser.precedence;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
import org.apache.lucene.analysis.LowerCaseTokenizer;
|
import org.apache.lucene.analysis.LowerCaseTokenizer;
|
||||||
import org.apache.lucene.analysis.SimpleAnalyzer;
|
import org.apache.lucene.analysis.SimpleAnalyzer;
|
||||||
import org.apache.lucene.analysis.Token;
|
|
||||||
import org.apache.lucene.analysis.TokenFilter;
|
import org.apache.lucene.analysis.TokenFilter;
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
import org.apache.lucene.analysis.WhitespaceAnalyzer;
|
||||||
|
@ -37,13 +35,23 @@ import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.RangeQuery;
|
import org.apache.lucene.search.RangeQuery;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
|
import org.apache.lucene.util.LocalizedTestCase;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class TestPrecedenceQueryParser extends TestCase {
|
public class TestPrecedenceQueryParser extends LocalizedTestCase {
|
||||||
|
|
||||||
|
public TestPrecedenceQueryParser(String name) {
|
||||||
|
super(name, new HashSet(Arrays.asList(new String[]{
|
||||||
|
"testDateRange", "testNumber"
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
||||||
|
|
||||||
|
@ -107,7 +115,8 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
|
|
||||||
private int originalMaxClauses;
|
private int originalMaxClauses;
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
originalMaxClauses = BooleanQuery.getMaxClauseCount();
|
originalMaxClauses = BooleanQuery.getMaxClauseCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,6 +370,14 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
assertQueryEquals("gack ( bar blar { a TO z}) ", null, "gack (bar blar {a TO z})");
|
assertQueryEquals("gack ( bar blar { a TO z}) ", null, "gack (bar blar {a TO z})");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String escapeDateString(String s) {
|
||||||
|
if (s.contains(" ")) {
|
||||||
|
return "\"" + s + "\"";
|
||||||
|
} else {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getDate(String s) throws Exception {
|
public String getDate(String s) throws Exception {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
return DateTools.dateToString(df.parse(s), DateTools.Resolution.DAY);
|
return DateTools.dateToString(df.parse(s), DateTools.Resolution.DAY);
|
||||||
|
@ -368,7 +385,7 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
|
|
||||||
public String getLocalizedDate(int year, int month, int day) {
|
public String getLocalizedDate(int year, int month, int day) {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = new GregorianCalendar();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
return df.format(calendar.getTime());
|
return df.format(calendar.getTime());
|
||||||
}
|
}
|
||||||
|
@ -376,9 +393,9 @@ public class TestPrecedenceQueryParser extends TestCase {
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1);
|
String startDate = getLocalizedDate(2002, 1, 1);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4);
|
String endDate = getLocalizedDate(2002, 1, 4);
|
||||||
assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null,
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null,
|
||||||
"[" + getDate(startDate) + " TO " + getDate(endDate) + "]");
|
"[" + getDate(startDate) + " TO " + getDate(endDate) + "]");
|
||||||
assertQueryEquals("{ " + startDate + " " + endDate + " }", null,
|
assertQueryEquals("{ " + escapeDateString(startDate) + " " + escapeDateString(endDate) + " }", null,
|
||||||
"{" + getDate(startDate) + " TO " + getDate(endDate) + "}");
|
"{" + getDate(startDate) + " TO " + getDate(endDate) + "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,11 @@ import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -68,7 +71,7 @@ import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.TermRangeQuery;
|
import org.apache.lucene.search.TermRangeQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LocalizedTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test case is a copy of the core Lucene query parser test, it was adapted
|
* This test case is a copy of the core Lucene query parser test, it was adapted
|
||||||
|
@ -76,7 +79,15 @@ import org.apache.lucene.util.LuceneTestCase;
|
||||||
*
|
*
|
||||||
* Tests QueryParser.
|
* Tests QueryParser.
|
||||||
*/
|
*/
|
||||||
public class TestQueryParserWrapper extends LuceneTestCase {
|
public class TestQueryParserWrapper extends LocalizedTestCase {
|
||||||
|
|
||||||
|
public TestQueryParserWrapper(String name) {
|
||||||
|
super(name, new HashSet(Arrays.asList(new String[]{
|
||||||
|
"testLegacyDateRange", "testDateRange",
|
||||||
|
"testCJK", "testNumber", "testFarsiRangeCollating",
|
||||||
|
"testLocalDateFormat"
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
||||||
|
|
||||||
|
@ -619,6 +630,14 @@ public class TestQueryParserWrapper extends LuceneTestCase {
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String escapeDateString(String s) {
|
||||||
|
if (s.contains(" ")) {
|
||||||
|
return "\"" + s + "\"";
|
||||||
|
} else {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** for testing legacy DateField support */
|
/** for testing legacy DateField support */
|
||||||
private String getLegacyDate(String s) throws Exception {
|
private String getLegacyDate(String s) throws Exception {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
|
@ -645,7 +664,7 @@ public class TestQueryParserWrapper extends LuceneTestCase {
|
||||||
private String getLocalizedDate(int year, int month, int day,
|
private String getLocalizedDate(int year, int month, int day,
|
||||||
boolean extendLastDate) {
|
boolean extendLastDate) {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = new GregorianCalendar();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
if (extendLastDate) {
|
if (extendLastDate) {
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
|
@ -660,20 +679,20 @@ public class TestQueryParserWrapper extends LuceneTestCase {
|
||||||
public void testLegacyDateRange() throws Exception {
|
public void testLegacyDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1, false);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4, false);
|
||||||
Calendar endDateExpected = Calendar.getInstance();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null, "["
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null, "["
|
||||||
+ getLegacyDate(startDate) + " TO "
|
+ getLegacyDate(startDate) + " TO "
|
||||||
+ DateField.dateToString(endDateExpected.getTime()) + "]");
|
+ DateField.dateToString(endDateExpected.getTime()) + "]");
|
||||||
assertQueryEquals("{ " + startDate + " " + endDate + " }", null, "{"
|
assertQueryEquals("{ " + escapeDateString(startDate) + " " + escapeDateString(endDate) + " }", null, "{"
|
||||||
+ getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
|
+ getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1, false);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4, false);
|
||||||
Calendar endDateExpected = Calendar.getInstance();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
final String defaultField = "default";
|
final String defaultField = "default";
|
||||||
|
@ -715,10 +734,10 @@ public class TestQueryParserWrapper extends LuceneTestCase {
|
||||||
public void assertDateRangeQueryEquals(QueryParserWrapper qp, String field,
|
public void assertDateRangeQueryEquals(QueryParserWrapper qp, String field,
|
||||||
String startDate, String endDate, Date endDateInclusive,
|
String startDate, String endDate, Date endDateInclusive,
|
||||||
DateTools.Resolution resolution) throws Exception {
|
DateTools.Resolution resolution) throws Exception {
|
||||||
assertQueryEquals(qp, field, field + ":[" + startDate + " TO " + endDate
|
assertQueryEquals(qp, field, field + ":[" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
|
||||||
+ "]", "[" + getDate(startDate, resolution) + " TO "
|
+ "]", "[" + getDate(startDate, resolution) + " TO "
|
||||||
+ getDate(endDateInclusive, resolution) + "]");
|
+ getDate(endDateInclusive, resolution) + "]");
|
||||||
assertQueryEquals(qp, field, field + ":{" + startDate + " TO " + endDate
|
assertQueryEquals(qp, field, field + ":{" + escapeDateString(startDate) + " TO " + escapeDateString(endDate)
|
||||||
+ "}", "{" + getDate(startDate, resolution) + " TO "
|
+ "}", "{" + getDate(startDate, resolution) + " TO "
|
||||||
+ getDate(endDate, resolution) + "}");
|
+ getDate(endDate, resolution) + "}");
|
||||||
}
|
}
|
||||||
|
@ -1124,7 +1143,7 @@ public class TestQueryParserWrapper extends LuceneTestCase {
|
||||||
int hour, int minute, int second, IndexWriter iw) throws IOException {
|
int hour, int minute, int second, IndexWriter iw) throws IOException {
|
||||||
Document d = new Document();
|
Document d = new Document();
|
||||||
d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
|
d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
|
||||||
cal.set(year, month - 1, day, hour, minute, second);
|
cal.set(year, month - 1, day, hour, minute, second);
|
||||||
d.add(new Field("date", DateField.dateToString(cal.getTime()),
|
d.add(new Field("date", DateField.dateToString(cal.getTime()),
|
||||||
Field.Store.YES, Field.Index.NOT_ANALYZED));
|
Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
|
|
|
@ -4,9 +4,11 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.apache.lucene.util.LocalizedTestCase;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +28,7 @@ import org.apache.lucene.util.LuceneTestCase;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class TestDateTools extends LuceneTestCase {
|
public class TestDateTools extends LocalizedTestCase {
|
||||||
|
|
||||||
public void testStringToDate() throws ParseException {
|
public void testStringToDate() throws ParseException {
|
||||||
|
|
||||||
|
@ -57,7 +59,7 @@ public class TestDateTools extends LuceneTestCase {
|
||||||
|
|
||||||
public void testStringtoTime() throws ParseException {
|
public void testStringtoTime() throws ParseException {
|
||||||
long time = DateTools.stringToTime("197001010000");
|
long time = DateTools.stringToTime("197001010000");
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.set(1970, 0, 1, // year=1970, month=january, day=1
|
cal.set(1970, 0, 1, // year=1970, month=january, day=1
|
||||||
0, 0, 0); // hour, minute, second
|
0, 0, 0); // hour, minute, second
|
||||||
cal.set(Calendar.MILLISECOND, 0);
|
cal.set(Calendar.MILLISECOND, 0);
|
||||||
|
@ -71,7 +73,7 @@ public class TestDateTools extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateAndTimetoString() throws ParseException {
|
public void testDateAndTimetoString() throws ParseException {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
||||||
22, 8, 56); // hour, minute, second
|
22, 8, 56); // hour, minute, second
|
||||||
|
@ -135,7 +137,7 @@ public class TestDateTools extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRound() {
|
public void testRound() {
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = new GregorianCalendar();
|
||||||
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
cal.set(2004, 1, 3, // year=2004, month=february(!), day=3
|
||||||
22, 8, 56); // hour, minute, second
|
22, 8, 56); // hour, minute, second
|
||||||
|
|
|
@ -21,8 +21,10 @@ import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -58,12 +60,20 @@ import org.apache.lucene.search.ScoreDoc;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
import org.apache.lucene.search.WildcardQuery;
|
import org.apache.lucene.search.WildcardQuery;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
|
import org.apache.lucene.util.LocalizedTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests QueryParser.
|
* Tests QueryParser.
|
||||||
*/
|
*/
|
||||||
public class TestQueryParser extends BaseTokenStreamTestCase {
|
public class TestQueryParser extends LocalizedTestCase {
|
||||||
|
|
||||||
|
public TestQueryParser(String name) {
|
||||||
|
super(name, new HashSet(Arrays.asList(new String[]{
|
||||||
|
"testLegacyDateRange", "testDateRange",
|
||||||
|
"testCJK", "testNumber", "testFarsiRangeCollating",
|
||||||
|
"testLocalDateFormat"
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
public static Analyzer qpAnalyzer = new QPTestAnalyzer();
|
||||||
|
|
||||||
|
@ -495,6 +505,14 @@ public class TestQueryParser extends BaseTokenStreamTestCase {
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String escapeDateString(String s) {
|
||||||
|
if (s.contains(" ")) {
|
||||||
|
return "\"" + s + "\"";
|
||||||
|
} else {
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** for testing legacy DateField support */
|
/** for testing legacy DateField support */
|
||||||
private String getLegacyDate(String s) throws Exception {
|
private String getLegacyDate(String s) throws Exception {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
|
@ -518,7 +536,7 @@ public class TestQueryParser extends BaseTokenStreamTestCase {
|
||||||
|
|
||||||
private String getLocalizedDate(int year, int month, int day, boolean extendLastDate) {
|
private String getLocalizedDate(int year, int month, int day, boolean extendLastDate) {
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = new GregorianCalendar();
|
||||||
calendar.set(year, month, day);
|
calendar.set(year, month, day);
|
||||||
if (extendLastDate) {
|
if (extendLastDate) {
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
calendar.set(Calendar.HOUR_OF_DAY, 23);
|
||||||
|
@ -533,19 +551,19 @@ public class TestQueryParser extends BaseTokenStreamTestCase {
|
||||||
public void testLegacyDateRange() throws Exception {
|
public void testLegacyDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1, false);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4, false);
|
||||||
Calendar endDateExpected = Calendar.getInstance();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
assertQueryEquals("[ " + startDate + " TO " + endDate + "]", null,
|
assertQueryEquals("[ " + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]", null,
|
||||||
"[" + getLegacyDate(startDate) + " TO " + DateField.dateToString(endDateExpected.getTime()) + "]");
|
"[" + getLegacyDate(startDate) + " TO " + DateField.dateToString(endDateExpected.getTime()) + "]");
|
||||||
assertQueryEquals("{ " + startDate + " " + endDate + " }", null,
|
assertQueryEquals("{ " + escapeDateString(startDate) + " " + escapeDateString(endDate) + " }", null,
|
||||||
"{" + getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
|
"{" + getLegacyDate(startDate) + " TO " + getLegacyDate(endDate) + "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDateRange() throws Exception {
|
public void testDateRange() throws Exception {
|
||||||
String startDate = getLocalizedDate(2002, 1, 1, false);
|
String startDate = getLocalizedDate(2002, 1, 1, false);
|
||||||
String endDate = getLocalizedDate(2002, 1, 4, false);
|
String endDate = getLocalizedDate(2002, 1, 4, false);
|
||||||
Calendar endDateExpected = Calendar.getInstance();
|
Calendar endDateExpected = new GregorianCalendar();
|
||||||
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
endDateExpected.set(2002, 1, 4, 23, 59, 59);
|
||||||
endDateExpected.set(Calendar.MILLISECOND, 999);
|
endDateExpected.set(Calendar.MILLISECOND, 999);
|
||||||
final String defaultField = "default";
|
final String defaultField = "default";
|
||||||
|
@ -585,9 +603,9 @@ public class TestQueryParser extends BaseTokenStreamTestCase {
|
||||||
|
|
||||||
public void assertDateRangeQueryEquals(QueryParser qp, String field, String startDate, String endDate,
|
public void assertDateRangeQueryEquals(QueryParser qp, String field, String startDate, String endDate,
|
||||||
Date endDateInclusive, DateTools.Resolution resolution) throws Exception {
|
Date endDateInclusive, DateTools.Resolution resolution) throws Exception {
|
||||||
assertQueryEquals(qp, field, field + ":[" + startDate + " TO " + endDate + "]",
|
assertQueryEquals(qp, field, field + ":[" + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "]",
|
||||||
"[" + getDate(startDate, resolution) + " TO " + getDate(endDateInclusive, resolution) + "]");
|
"[" + getDate(startDate, resolution) + " TO " + getDate(endDateInclusive, resolution) + "]");
|
||||||
assertQueryEquals(qp, field, field + ":{" + startDate + " TO " + endDate + "}",
|
assertQueryEquals(qp, field, field + ":{" + escapeDateString(startDate) + " TO " + escapeDateString(endDate) + "}",
|
||||||
"{" + getDate(startDate, resolution) + " TO " + getDate(endDate, resolution) + "}");
|
"{" + getDate(startDate, resolution) + " TO " + getDate(endDate, resolution) + "}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -985,7 +1003,7 @@ public class TestQueryParser extends BaseTokenStreamTestCase {
|
||||||
int day, int hour, int minute, int second, IndexWriter iw) throws IOException {
|
int day, int hour, int minute, int second, IndexWriter iw) throws IOException {
|
||||||
Document d = new Document();
|
Document d = new Document();
|
||||||
d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
|
d.add(new Field("f", content, Field.Store.YES, Field.Index.ANALYZED));
|
||||||
Calendar cal = Calendar.getInstance();
|
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
|
||||||
cal.set(year, month-1, day, hour, minute, second);
|
cal.set(year, month-1, day, hour, minute, second);
|
||||||
d.add(new Field("date", DateField.dateToString(cal.getTime()), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
d.add(new Field("date", DateField.dateToString(cal.getTime()), Field.Store.YES, Field.Index.NOT_ANALYZED));
|
||||||
iw.addDocument(d);
|
iw.addDocument(d);
|
||||||
|
|
Loading…
Reference in New Issue