lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [37/50] [abbrv] lucenenet git commit: Completed implementation of QueryParser.Util.QueryParserTestBase.TestDateRange()
Date Sun, 23 Oct 2016 13:02:23 GMT
Completed implementation of QueryParser.Util.QueryParserTestBase.TestDateRange()


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/77d1948b
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/77d1948b
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/77d1948b

Branch: refs/heads/master
Commit: 77d1948be5540fcbddfe043b552cbd46d6e7315c
Parents: d3c07f6
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Oct 23 15:59:12 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Oct 23 19:36:46 2016 +0700

----------------------------------------------------------------------
 .../Classic/QueryParserBase.cs                  |  6 +-
 .../Classic/TestQueryParser.cs                  |  4 +-
 .../Util/QueryParserTestBase.cs                 | 79 ++++++++++----------
 3 files changed, 45 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/77d1948b/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs b/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs
index 83e13a2..ca10e89 100644
--- a/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs
+++ b/src/Lucene.Net.QueryParser/Classic/QueryParserBase.cs
@@ -457,7 +457,7 @@ namespace Lucene.Net.QueryParsers.Classic
                 DateTime d1, d2;
                 if (_useJavaStyleDateRangeParsing)
                 {
-                    // TODO: This doesn't emulate java perfectly.
+                    // LUCENENET TODO: This doesn't emulate java perfectly.
                     // Java allows parsing of the string up to the end of the pattern
                     // and then ignores everything else.  .NET will throw an exception, 
                     // so this will fail in those cases, though the code below is clear
@@ -478,11 +478,11 @@ namespace Lucene.Net.QueryParsers.Classic
                     // the time is set to the latest possible time of that date to really
                     // include all documents:
 
-                    // TODO: Try to work out if the Time Zone is pertinent here or
+                    // LUCENENET TODO: Try to work out if the Time Zone is pertinent here
or
                     // whether it should just be removed from the API entirely.
                     // In Java:
                     // Calendar cal = Calendar.getInstance(timeZone, locale);
-
+                    
                     var cal = Locale.Calendar;
                     d2 = cal.AddHours(d2, 23);
                     d2 = cal.AddMinutes(d2, 59);

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/77d1948b/src/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs b/src/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
index d1fb5e6..2b71216 100644
--- a/src/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Classic/TestQueryParser.cs
@@ -109,11 +109,11 @@ namespace Lucene.Net.QueryParsers.Classic
             qp.AutoGeneratePhraseQueries = value;
         }
 
-        public override void SetDateResolution(ICommonQueryParserConfiguration cqpC, ICharSequence
field, DateTools.Resolution value)
+        public override void SetDateResolution(ICommonQueryParserConfiguration cqpC, string
field, DateTools.Resolution value)
         {
             Debug.Assert(cqpC is QueryParser);
             QueryParser qp = (QueryParser)cqpC;
-            qp.SetDateResolution(field.toString(), value);
+            qp.SetDateResolution(field, value);
         }
 
         [Test]

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/77d1948b/src/Lucene.Net.Tests.QueryParser/Util/QueryParserTestBase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Util/QueryParserTestBase.cs b/src/Lucene.Net.Tests.QueryParser/Util/QueryParserTestBase.cs
index e484902..698ba35 100644
--- a/src/Lucene.Net.Tests.QueryParser/Util/QueryParserTestBase.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Util/QueryParserTestBase.cs
@@ -11,6 +11,7 @@ using Lucene.Net.Util;
 using Lucene.Net.Util.Automaton;
 using NUnit.Framework;
 using System;
+using System.Globalization;
 
 namespace Lucene.Net.QueryParsers.Util
 {
@@ -117,7 +118,7 @@ namespace Lucene.Net.QueryParsers.Util
 
         public abstract void SetAutoGeneratePhraseQueries(ICommonQueryParserConfiguration
cqpC, bool value);
 
-        public abstract void SetDateResolution(ICommonQueryParserConfiguration cqpC, ICharSequence
field, DateTools.Resolution value);
+        public abstract void SetDateResolution(ICommonQueryParserConfiguration cqpC, string
field, DateTools.Resolution value);
 
         public abstract Query GetQuery(string query, ICommonQueryParserConfiguration cqpC);
 
@@ -661,9 +662,8 @@ namespace Lucene.Net.QueryParsers.Util
 
         private string GetLocalizedDate(int year, int month, int day)
         {
-            // TODO: Is this the right way to get the localized date?
             DateTime d = new DateTime(year, month, day, 23, 59, 59, 999);
-            return d.ToString();
+            return d.ToShortDateString();
 
             //// we use the default Locale/TZ since LuceneTestCase randomizes it
             //DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
@@ -677,45 +677,46 @@ namespace Lucene.Net.QueryParsers.Util
             //return df.format(calendar.getTime());
         }
 
-        // TODO: Fix this test
         [Test]
         public virtual void TestDateRange()
         {
-            Assert.Fail("Test is not implemented");
-
-        //    string startDate = GetLocalizedDate(2002, 1, 1);
-        //    string endDate = GetLocalizedDate(2002, 1, 4);
-        //    // we use the default Locale/TZ since LuceneTestCase randomizes it
-        //    Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
-        //    endDateExpected.clear();
-        //    endDateExpected.set(2002, 1, 4, 23, 59, 59);
-        //    endDateExpected.set(Calendar.MILLISECOND, 999);
-        //    string defaultField = "default";
-        //    string monthField = "month";
-        //    string hourField = "hour";
-        //    Analyzer a = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true);
-        //    CommonQueryParserConfiguration qp = GetParserConfig(a);
-
-        //    // set a field specific date resolution
-        //    SetDateResolution(qp, monthField, DateTools.Resolution.MONTH);
-
-        //    // set default date resolution to MILLISECOND
-        //    qp.SetDateResolution(DateTools.Resolution.MILLISECOND);
-
-        //    // set second field specific date resolution    
-        //    SetDateResolution(qp, hourField, DateTools.Resolution.HOUR);
-
-        //    // for this field no field specific date resolution has been set,
-        //    // so verify if the default resolution is used
-        //    AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
-        //            endDateExpected.getTime(), DateTools.Resolution.MILLISECOND);
-
-        //    // verify if field specific date resolutions are used for these two fields
-        //    AssertDateRangeQueryEquals(qp, monthField, startDate, endDate,
-        //            endDateExpected.getTime(), DateTools.Resolution.MONTH);
-
-        //    AssertDateRangeQueryEquals(qp, hourField, startDate, endDate,
-        //            endDateExpected.getTime(), DateTools.Resolution.HOUR);
+            string startDate = GetLocalizedDate(2002, 1, 1);
+            string endDate = GetLocalizedDate(2002, 1, 4);
+
+            // we use the default Locale/TZ since LuceneTestCase randomizes it
+            //Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
+            //endDateExpected.clear();
+            //endDateExpected.set(2002, 1, 4, 23, 59, 59);
+            //endDateExpected.set(Calendar.MILLISECOND, 999);
+
+            // we use the default Locale/TZ since LuceneTestCase randomizes it
+            DateTime endDateExpected = new DateTime(2002, 1, 4, 23, 59, 59, 999, new GregorianCalendar());
+            string defaultField = "default";
+            string monthField = "month";
+            string hourField = "hour";
+            Analyzer a = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true);
+            ICommonQueryParserConfiguration qp = GetParserConfig(a);
+
+            // set a field specific date resolution
+            SetDateResolution(qp, monthField, DateTools.Resolution.MONTH);
+
+            // set default date resolution to MILLISECOND
+            qp.SetDateResolution(DateTools.Resolution.MILLISECOND);
+
+            // set second field specific date resolution    
+            SetDateResolution(qp, hourField, DateTools.Resolution.HOUR);
+
+            // for this field no field specific date resolution has been set,
+            // so verify if the default resolution is used
+            AssertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
+                    endDateExpected /*.getTime()*/, DateTools.Resolution.MILLISECOND);
+
+            // verify if field specific date resolutions are used for these two fields
+            AssertDateRangeQueryEquals(qp, monthField, startDate, endDate,
+                    endDateExpected /*.getTime()*/, DateTools.Resolution.MONTH);
+
+            AssertDateRangeQueryEquals(qp, hourField, startDate, endDate,
+                    endDateExpected /*.getTime()*/, DateTools.Resolution.HOUR);
         }
 
         public void AssertDateRangeQueryEquals(ICommonQueryParserConfiguration cqpC, string
field, string startDate, string endDate,


Mime
View raw message