lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [19/58] lucenenet git commit: QueryParser.Flexible: Fixed all TestNumericQueryParser tests.
Date Tue, 06 Dec 2016 15:11:54 GMT
QueryParser.Flexible: Fixed all TestNumericQueryParser tests.


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

Branch: refs/heads/master
Commit: 6e7a7332bce9c9aaf7e43b887ddaeba204c902af
Parents: 67cd448
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Fri Dec 2 20:37:38 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Fri Dec 2 20:41:00 2016 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj           |    1 +
 src/Lucene.Net.Core/Support/NumberFormat.cs     |  138 ++
 .../Flexible/Core/Parser/EscapeQuerySyntax.cs   |   10 +
 .../Standard/Config/NumberDateFormat.cs         |  152 ++-
 .../Flexible/Standard/Config/NumericConfig.cs   |    9 +-
 .../Flexible/Standard/Nodes/NumericQueryNode.cs |   15 +-
 .../Standard/Parser/EscapeQuerySyntaxImpl.cs    |   10 +-
 .../Processors/NumericQueryNodeProcessor.cs     |    8 +-
 .../NumericRangeQueryNodeProcessor.cs           |   11 +-
 .../Flexible/Standard/TestNumericQueryParser.cs | 1291 ++++++++++--------
 10 files changed, 1063 insertions(+), 582 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj
index 5ce5f82..85ab464 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -649,6 +649,7 @@
     <Compile Include="Support\LurchTable.cs" />
     <Compile Include="Support\MathExtension.cs" />
     <Compile Include="Support\MemoryMappedFileByteBuffer.cs" />
+    <Compile Include="Support\NumberFormat.cs" />
     <Compile Include="Support\ObjectExtensions.cs" />
     <Compile Include="Support\PriorityQueue.cs" />
     <Compile Include="Support\ReentrantLock.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.Core/Support/NumberFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/NumberFormat.cs b/src/Lucene.Net.Core/Support/NumberFormat.cs
new file mode 100644
index 0000000..269f8e7
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/NumberFormat.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.Support
+{
+    public class NumberFormat
+    {
+        protected readonly CultureInfo locale;
+
+        private int maximumIntegerDigits;
+        private int minimumIntegerDigits;
+        private int maximumFractionDigits;
+        private int minimumFractionDigits;
+
+        public NumberFormat(CultureInfo locale)
+        {
+            this.locale = locale;
+        }
+
+        public virtual string Format(object number)
+        {
+            string format = GetNumberFormat();
+
+            if (number is int)
+            {
+                return ((int)number).ToString(format, locale);
+            }
+            else if (number is long)
+            {
+                return ((long)number).ToString(format, locale);
+            }
+            else if (number is short)
+            {
+                return ((short)number).ToString(format, locale);
+            }
+            else if (number is float)
+            {
+                return ((float)number).ToString(format, locale);
+            }
+            else if (number is double)
+            {
+                return ((double)number).ToString(format, locale);
+            }
+            else if (number is decimal)
+            {
+                return ((decimal)number).ToString(format, locale);
+            }
+
+            throw new ArgumentException("Cannot format given object as a Number");
+        }
+
+        public virtual string Format(double number)
+        {
+            string format = GetNumberFormat();
+            return number.ToString(format, locale);
+        }
+
+        public virtual string Format(long number)
+        {
+            string format = GetNumberFormat();
+            return number.ToString(format, locale);
+        }
+
+        protected virtual string GetNumberFormat()
+        {
+            return null;
+        }
+
+        public virtual /*Number*/ object Parse(string source)
+        {
+            return decimal.Parse(source, locale);
+        }
+
+        // LUCENENET TODO: Add additional functionality to edit the NumberFormatInfo
+        // properties, which provides somewhat similar functionality to the below Java
+        // getters and setters.
+
+        //public virtual int MaximumIntegerDigits
+        //{
+        //    get { return this.maximumIntegerDigits; }
+        //}
+
+        //public virtual void SetMaximumIntegerDigits(int newValue)
+        //{
+        //    this.maximumIntegerDigits = Math.Max(0, newValue);
+        //    if (maximumIntegerDigits < minimumIntegerDigits)
+        //    {
+        //        minimumIntegerDigits = maximumIntegerDigits;
+        //    }
+        //}
+
+        //public virtual int MinimumIntegerDigits
+        //{
+        //    get { return this.minimumIntegerDigits; }
+        //}
+
+        //public virtual void SetMinimumIntegerDigits(int newValue)
+        //{
+        //    this.minimumIntegerDigits = Math.Max(0, newValue);
+        //    if (minimumIntegerDigits > maximumIntegerDigits)
+        //    {
+        //        maximumIntegerDigits = minimumIntegerDigits;
+        //    }
+        //}
+
+        //public virtual int MaximumFractionDigits
+        //{
+        //    get { return this.maximumFractionDigits; }
+        //}
+
+        //public virtual void SetMaximumFractionDigits(int newValue)
+        //{
+        //    maximumFractionDigits = Math.Max(0, newValue);
+        //    if (maximumFractionDigits < minimumFractionDigits)
+        //    {
+        //        minimumFractionDigits = maximumFractionDigits;
+        //    }
+        //}
+
+        //public virtual int MinimumFractionDigits
+        //{
+        //    get { return this.minimumFractionDigits; }
+        //}
+
+        //public void SetMinimumFractionDigits(int newValue)
+        //{
+        //    minimumFractionDigits = Math.Max(0, newValue);
+        //    if (maximumFractionDigits < minimumFractionDigits)
+        //    {
+        //        maximumFractionDigits = minimumFractionDigits;
+        //    }
+        //}
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Core/Parser/EscapeQuerySyntax.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Core/Parser/EscapeQuerySyntax.cs b/src/Lucene.Net.QueryParser/Flexible/Core/Parser/EscapeQuerySyntax.cs
index d0e6803..ade0394 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Core/Parser/EscapeQuerySyntax.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Core/Parser/EscapeQuerySyntax.cs
@@ -21,6 +21,16 @@ namespace Lucene.Net.QueryParsers.Flexible.Core.Parser
         /// <param name="locale">locale for the current query</param>
         /// <param name="type">select the type of escape operation to use</param>
         /// <returns>escaped text</returns>
+        // LUCENENET specific overload for text as string
+        string Escape(string text, CultureInfo locale, EscapeQuerySyntax.Type type);
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="text"> text to be escaped</param>
+        /// <param name="locale">locale for the current query</param>
+        /// <param name="type">select the type of escape operation to use</param>
+        /// <returns>escaped text</returns>
         ICharSequence Escape(ICharSequence text, CultureInfo locale, EscapeQuerySyntax.Type type);
     }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
index c7f9f63..fc821eb 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumberDateFormat.cs
@@ -1,4 +1,154 @@
-// LUCENENET TODO: Do we need this class?
+using Lucene.Net.Documents;
+using Lucene.Net.Support;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
+{
+    /// <summary>
+    /// LUCENENET specific enum for mimicking the Java DateFormat
+    /// </summary>
+    public enum DateStyle
+    {
+        FULL, LONG,
+        MEDIUM, SHORT
+    }
+
+    /// <summary>
+    /// This {@link Format} parses {@link Long} into date strings and vice-versa. It
+    /// uses the given {@link DateFormat} to parse and format dates, but before, it
+    /// converts {@link Long} to {@link Date} objects or vice-versa.
+    /// </summary>
+    public class NumberDateFormat : NumberFormat
+    {
+        //private static readonly long serialVersionUID = 964823936071308283L;
+
+        // The .NET ticks representing January 1, 1970 0:00:00, also known as the "epoch".
+        private const long EPOCH = 621355968000000000;
+
+        //private readonly DateFormat dateFormat;
+        private readonly DateStyle dateStyle;
+        private readonly DateStyle timeStyle;
+        //private readonly CultureInfo locale;
+        private readonly TimeZoneInfo timeZone;
+
+        /**
+         * Constructs a {@link NumberDateFormat} object using the given {@link DateFormat}.
+         * 
+         * @param dateFormat {@link DateFormat} used to parse and format dates
+         */
+        //public NumberDateFormat(DateFormat dateFormat)
+        //{
+        //    this.dateFormat = dateFormat;
+        //}
+
+        //public NumberDateFormat(string dateFormat, CultureInfo locale)
+        //{
+        //    this.dateFormat = dateFormat;
+        //    this.locale = locale;
+        //}
+
+        //public NumberDateFormat(string dateFormat)
+        //    : this(dateFormat, CultureInfo.CurrentCulture)
+        //{
+        //}
+
+        public NumberDateFormat(DateStyle dateStyle, DateStyle timeStyle, CultureInfo locale, TimeZoneInfo timeZone)
+            : base(locale)
+        {
+            this.dateStyle = dateStyle;
+            this.timeStyle = timeStyle;
+            //this.locale = locale;
+            this.timeZone = timeZone;
+        }
+
+        public override string Format(double number)
+        {
+            //long ticks = (long)number + EPOCH;
+            //return new DateTime(ticks).ToString(GetDateFormat(), this.locale);
+
+            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(), this.locale);
+        }
+
+
+        public override string Format(long number)
+        {
+            //long ticks = number + EPOCH;
+            //return new DateTime(ticks).ToString(GetDateFormat(), this.locale);
+
+            return new DateTime(EPOCH).AddMilliseconds(number).ToString(GetDateFormat(), this.locale);
+        }
+
+
+        public override /*Number*/ object Parse(string source)
+        {
+            return (DateTime.Parse(source, this.locale) - new DateTime(EPOCH)).TotalMilliseconds;
+
+            //DateTime date = DateTime.Parse(source, this.locale);
+            //return date.Ticks - EPOCH;
+
+            //DateTime date = dateFormat.parse(source, parsePosition);
+            //return (date == null) ? null : date.getTime();
+        }
+
+
+        public override string Format(object number)
+        {
+            //long ticks = Convert.ToInt64(number) + EPOCH;
+            //return new DateTime(ticks).ToString(GetDateFormat(), this.locale);
+
+            return new DateTime(EPOCH).AddMilliseconds(Convert.ToInt64(number)).ToString(GetDateFormat(), this.locale);
+        }
+
+
+        private string GetDateFormat()
+        {
+            string datePattern = "", timePattern = "";
+
+            switch (dateStyle)
+            {
+                case DateStyle.SHORT:
+                    datePattern = locale.DateTimeFormat.ShortDatePattern;
+                    break;
+                case DateStyle.MEDIUM:
+                    datePattern = locale.DateTimeFormat.LongDatePattern
+                        .Replace("dddd,", "").Replace(", dddd", "") // Remove the day of the week
+                        .Replace("MMMM", "MMM"); // Replace month with abbreviated month
+                    break;
+                case DateStyle.LONG:
+                    datePattern = locale.DateTimeFormat.LongDatePattern
+                        .Replace("dddd,", "").Replace(", dddd", ""); // Remove the day of the week
+                    break;
+                case DateStyle.FULL:
+                    datePattern = locale.DateTimeFormat.LongDatePattern;
+                    break;
+            }
+
+            switch (timeStyle)
+            {
+                case DateStyle.SHORT:
+                    timePattern = locale.DateTimeFormat.ShortTimePattern;
+                    break;
+                case DateStyle.MEDIUM:
+                    timePattern = locale.DateTimeFormat.LongTimePattern;
+                    break;
+                case DateStyle.LONG:
+                    timePattern = locale.DateTimeFormat.LongTimePattern; // LUCENENET TODO: Time zone info not being added
+                    break;
+                case DateStyle.FULL:
+                    timePattern = locale.DateTimeFormat.LongTimePattern; // LUCENENET TODO: Time zone info not being added, but Java doc is unclear on what the difference is between this and LONG
+                    break;
+            }
+
+            return string.Concat(datePattern, " ", timePattern);
+        }
+    }
+}
+
 
 //using System;
 //using System.Collections.Generic;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
index 1147a6d..280fe1f 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Config/NumericConfig.cs
@@ -1,4 +1,5 @@
-using System;
+using Lucene.Net.Support;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -17,7 +18,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
     {
         private int precisionStep;
 
-        private /*NumberFormat*/ string format;
+        private NumberFormat format;
 
         private NumericType type;
 
@@ -36,7 +37,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
          * @see NumericConfig#setNumberFormat(NumberFormat)
          * @see #setType(org.apache.lucene.document.FieldType.NumericType)
          */
-        public NumericConfig(int precisionStep, /*NumberFormat*/ string format,
+        public NumericConfig(int precisionStep, NumberFormat format,
             NumericType type)
         {
             PrecisionStep = precisionStep;
@@ -64,7 +65,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Config
          * @return the {@link NumberFormat} used to parse a {@link String} to
          *         {@link Number}
          */
-        public virtual /*NumberFormat*/ string NumberFormat
+        public virtual NumberFormat NumberFormat
         {
             get { return format; }
             set

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
index 01526f3..b3f55fc 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Nodes/NumericQueryNode.cs
@@ -18,7 +18,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
     /// <seealso cref="NumericConfig"/>
     public class NumericQueryNode : QueryNodeImpl, IFieldValuePairQueryNode<object> // LUCENENET TODO: Can we use Decimal??
     {
-        private /*NumberFormat*/ string numberFormat;
+        private NumberFormat numberFormat;
 
         private string field;
 
@@ -34,7 +34,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
          * @param numberFormat the {@link NumberFormat} used to convert the value to {@link String}
          */
         public NumericQueryNode(string field, /*Number*/ object value,
-            /*NumberFormat*/ string numberFormat)
+            NumberFormat numberFormat)
             : base()
         {
             NumberFormat = numberFormat;
@@ -76,8 +76,11 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
          */
         protected string GetTermEscaped(IEscapeQuerySyntax escaper)
         {
-            return escaper.Escape(new StringCharSequenceWrapper(string.Format(numberFormat, this.value)) /*numberFormat.format(this.value)*/,
-                CultureInfo.CurrentCulture, EscapeQuerySyntax.Type.NORMAL).ToString();
+            //return escaper.Escape(new StringCharSequenceWrapper(/*string.Format(numberFormat, this.value))*/ numberFormat.Format(this.value),
+            //    CultureInfo.CurrentCulture, EscapeQuerySyntax.Type.NORMAL).ToString();
+
+            return escaper.Escape(numberFormat.Format(this.value),
+                CultureInfo.CurrentCulture, EscapeQuerySyntax.Type.NORMAL);
         }
 
 
@@ -98,7 +101,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
          * 
          * @return the {@link NumberFormat} used to convert the value to {@link String}
          */
-        public virtual /*NumberFormat*/ string NumberFormat
+        public virtual NumberFormat NumberFormat
         {
             get { return this.numberFormat; }
             set { this.numberFormat = value; }
@@ -131,7 +134,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Nodes
         public override string ToString()
         {
             return "<numeric field='" + this.field + "' number='"
-                + string.Format(numberFormat, value) + "'/>";
+                + numberFormat.Format(value) + "'/>";
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/EscapeQuerySyntaxImpl.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/EscapeQuerySyntaxImpl.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/EscapeQuerySyntaxImpl.cs
index 589a968..5eff8f8 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/EscapeQuerySyntaxImpl.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Parser/EscapeQuerySyntaxImpl.cs
@@ -296,7 +296,15 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Parser
             return buffer;
         }
 
-        // LUCENENET TODO: Add overload for string
+        // LUCENENET specific overload for text as string
+        public virtual string Escape(string text, CultureInfo locale, EscapeQuerySyntax.Type type)
+        {
+            if (text == null || text.Length == 0)
+                return text;
+
+            return Escape(text.ToCharSequence(), locale, type).ToString();
+        }
+
         public virtual ICharSequence Escape(ICharSequence text, CultureInfo locale, EscapeQuerySyntax.Type type)  
         {
             if (text == null || text.Length == 0)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
index 2bbffe4..5772699 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericQueryNodeProcessor.cs
@@ -7,6 +7,7 @@ using Lucene.Net.QueryParsers.Flexible.Core.Processors;
 using Lucene.Net.QueryParsers.Flexible.Messages;
 using Lucene.Net.QueryParsers.Flexible.Standard.Config;
 using Lucene.Net.QueryParsers.Flexible.Standard.Nodes;
+using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -69,8 +70,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Processors
                         if (numericConfig != null)
                         {
 
-                            /*NumberFormat*/
-                            string numberFormat = numericConfig.NumberFormat;
+                            NumberFormat numberFormat = numericConfig.NumberFormat;
                             string text = fieldNode.GetTextAsString();
                             /*Number*/
                             object number = null;
@@ -80,8 +80,8 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Processors
 
                                 try
                                 {
-                                    //number = numberFormat.parse(text);
-                                    number = decimal.Parse(text, NumberStyles.Any);// LUCENENET TODO: use the current culture?
+                                    number = numberFormat.Parse(text);
+                                    //number = decimal.Parse(text, NumberStyles.Any);// LUCENENET TODO: use the current culture?
 
                                 }
                                 catch (FormatException e)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
index 88ed011..98d3c6f 100644
--- a/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
+++ b/src/Lucene.Net.QueryParser/Flexible/Standard/Processors/NumericRangeQueryNodeProcessor.cs
@@ -8,6 +8,7 @@ using Lucene.Net.QueryParsers.Flexible.Core.Util;
 using Lucene.Net.QueryParsers.Flexible.Messages;
 using Lucene.Net.QueryParsers.Flexible.Standard.Config;
 using Lucene.Net.QueryParsers.Flexible.Standard.Nodes;
+using Lucene.Net.Support;
 using System;
 using System.Collections.Generic;
 using System.Globalization;
@@ -68,7 +69,7 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Processors
 
                             string lowerText = lower.GetTextAsString();
                             string upperText = upper.GetTextAsString();
-                            /*NumberFormat*/ string numberFormat = numericConfig.NumberFormat;
+                            NumberFormat numberFormat = numericConfig.NumberFormat;
                             /*Number*/
                             object lowerNumber = null, upperNumber = null;
 
@@ -77,8 +78,8 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Processors
 
                                 try
                                 {
-                                    //lowerNumber = numberFormat.parse(lowerText);
-                                    lowerNumber = decimal.Parse(lowerText, NumberStyles.Any);// LUCENENET TODO: use the current culture?
+                                    lowerNumber = numberFormat.Parse(lowerText);
+                                    //lowerNumber = decimal.Parse(lowerText, NumberStyles.Any);// LUCENENET TODO: use the current culture?
                                 }
                                 catch (FormatException e)
                                 {
@@ -95,8 +96,8 @@ namespace Lucene.Net.QueryParsers.Flexible.Standard.Processors
 
                                 try
                                 {
-                                    //upperNumber = numberFormat.parse(upperText);
-                                    upperNumber = decimal.Parse(upperText, NumberStyles.Any);// LUCENENET TODO: use the current culture?
+                                    upperNumber = numberFormat.Parse(upperText);
+                                    //upperNumber = decimal.Parse(upperText, NumberStyles.Any);// LUCENENET TODO: use the current culture?
                                 }
                                 catch (FormatException e)
                                 {

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6e7a7332/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
index 21aacb1..a516a10 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
@@ -1,565 +1,734 @@
-//using Lucene.Net;
-//using Lucene.Net.Analysis;
-//using Lucene.Net.Documents;
-//using Lucene.Net.Index;
-//using Lucene.Net.QueryParsers.Flexible.Core.Parser;
-//using Lucene.Net.QueryParsers.Flexible.Standard.Config;
-//using Lucene.Net.QueryParsers.Flexible.Standard.Parser;
-//using Lucene.Net.Search;
-//using Lucene.Net.Store;
-//using Lucene.Net.Support;
-//using Lucene.Net.Util;
-//using NUnit.Framework;
-//using System;
-//using System.Collections.Generic;
-//using System.Globalization;
-//using System.Linq;
-//using System.Text;
-//using System.Threading.Tasks;
-
-//namespace Lucene.Net.QueryParsers.Flexible.Standard
-//{
-//    public class TestNumericQueryParser : LuceneTestCase
-//    {
-//        public enum NumberType
-//        {
-//            NEGATIVE, ZERO, POSITIVE
-//        }
-
-//        /// <summary>
-//        /// LUCENENET specific enum for mimicking the Java DateFormat
-//        /// </summary>
-//        public enum DateFormat
-//        {
-//            FULL, LONG,
-//            MEDIUM, SHORT
-//        }
-
-//        //  private readonly static int[] DATE_STYLES = {DateFormat.FULL, DateFormat.LONG,
-//        //DateFormat.MEDIUM, DateFormat.SHORT};
-//        private readonly static int[] DATE_STYLES = {(int)DateFormat.FULL, (int)DateFormat.LONG,
-//            (int)DateFormat.MEDIUM, (int)DateFormat.SHORT};
-
-//        private readonly static int PRECISION_STEP = 8;
-//        private readonly static String FIELD_NAME = "field";
-//        private static CultureInfo LOCALE;
-//        private static TimeZoneInfo TIMEZONE;
-//        private static IDictionary<String, /*Number*/ object> RANDOM_NUMBER_MAP;
-//        private readonly static IEscapeQuerySyntax ESCAPER = new EscapeQuerySyntaxImpl();
-//        private readonly static String DATE_FIELD_NAME = "date";
-//        private static int DATE_STYLE;
-//        private static int TIME_STYLE;
-
-//        private static Analyzer ANALYZER;
-
-//        private static /*NumberFormat*/ string NUMBER_FORMAT;
-
-//        private static StandardQueryParser qp;
-
-//        private static /*NumberDateFormat*/ string DATE_FORMAT;
-
-//        private static Directory directory = null;
-//        private static IndexReader reader = null;
-//        private static IndexSearcher searcher = null;
-
-//        private static bool checkDateFormatSanity(/*DateFormat*/string dateFormat, long date)
-//        {
-//            DateTime result;
-//            return DateTime.TryParseExact(new DateTime(date).ToString(dateFormat),
-//                dateFormat, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out result);
-//            //try
-//            //{
-//            //    return date == dateFormat.parse(dateFormat.format(new DateTime(date)))
-//            //      .getTime();
-//            //}
-//            //catch (ParseException e)
-//            //{
-//            //    return false;
-//            //}
-//        }
-
-//        [TestFixtureSetUp]
-//        public void BeforeClass()
-//        {
-//            ANALYZER = new MockAnalyzer(Random());
-
-//            qp = new StandardQueryParser(ANALYZER);
-
-//            HashMap<String, /*Number*/object> randomNumberMap = new HashMap<string, object>();
-
-//            /*SimpleDateFormat*/
-//            string dateFormat;
-//            long randomDate;
-//            bool dateFormatSanityCheckPass;
-//            int count = 0;
-//            do
-//            {
-//                if (count > 100)
-//                {
-//                    fail("This test has problems to find a sane random DateFormat/NumberFormat. Stopped trying after 100 iterations.");
-//                }
-
-//                dateFormatSanityCheckPass = true;
-//                LOCALE = randomLocale(Random());
-//                TIMEZONE = randomTimeZone(Random());
-//                DATE_STYLE = randomDateStyle(Random());
-//                TIME_STYLE = randomDateStyle(Random());
-
-//                //// assumes localized date pattern will have at least year, month, day,
-//                //// hour, minute
-//                //dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(
-//                //    DATE_STYLE, TIME_STYLE, LOCALE);
-
-//                //// not all date patterns includes era, full year, timezone and second,
-//                //// so we add them here
-//                //dateFormat.applyPattern(dateFormat.toPattern() + " G s Z yyyy");
-//                //dateFormat.setTimeZone(TIMEZONE);
-
-//                //DATE_FORMAT = new NumberDateFormat(dateFormat);
-
-
-//                do
-//                {
-//                    randomDate = Random().nextLong();
-
-//                    // prune date value so it doesn't pass in insane values to some
-//                    // calendars.
-//                    randomDate = randomDate % 3400000000000l;
-
-//                    // truncate to second
-//                    randomDate = (randomDate / 1000L) * 1000L;
-
-//                    // only positive values
-//                    randomDate = Math.Abs(randomDate);
-//                } while (randomDate == 0L);
-
-//                dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, randomDate);
-
-//                dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, 0);
-
-//                dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat,
-//                          -randomDate);
-
-//                count++;
-//            } while (!dateFormatSanityCheckPass);
-
-//            NUMBER_FORMAT = NumberFormat.getNumberInstance(LOCALE);
-//            NUMBER_FORMAT.setMaximumFractionDigits((Random().nextInt() & 20) + 1);
-//            NUMBER_FORMAT.setMinimumFractionDigits((Random().nextInt() & 20) + 1);
-//            NUMBER_FORMAT.setMaximumIntegerDigits((Random().nextInt() & 20) + 1);
-//            NUMBER_FORMAT.setMinimumIntegerDigits((Random().nextInt() & 20) + 1);
-
-//            double randomDouble;
-//            long randomLong;
-//            int randomInt;
-//            float randomFloat;
-
-//            while ((randomLong = Convert.ToInt64(normalizeNumber(Math.Abs(Random().nextLong()))
-//                )) == 0L)
-//                ;
-//            while ((randomDouble = Convert.ToDouble(normalizeNumber(Math.Abs(Random().NextDouble()))
-//                )) == 0.0)
-//                ;
-//            while ((randomFloat = Convert.ToSingle(normalizeNumber(Math.Abs(Random().nextFloat()))
-//                )) == 0.0f)
-//                ;
-//            while ((randomInt = Convert.ToInt32(normalizeNumber(Math.Abs(Random().nextInt())))) == 0)
-//                ;
-
-//            randomNumberMap.Put(FieldType.NumericType.LONG.ToString(), randomLong);
-//            randomNumberMap.Put(FieldType.NumericType.INT.ToString(), randomInt);
-//            randomNumberMap.Put(FieldType.NumericType.FLOAT.ToString(), randomFloat);
-//            randomNumberMap.Put(FieldType.NumericType.DOUBLE.ToString(), randomDouble);
-//            randomNumberMap.Put(DATE_FIELD_NAME, randomDate);
-
-//            RANDOM_NUMBER_MAP = Collections.UnmodifiableMap(randomNumberMap);
-
-//            directory = NewDirectory();
-//            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory,
-//                NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
-//                    .SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000))
-//                    .SetMergePolicy(NewLogMergePolicy()));
-
-//            Document doc = new Document();
-//            HashMap<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
-//            HashMap<String, Field> numericFieldMap = new HashMap<String, Field>();
-//            qp.SetNumericConfigMap(numericConfigMap);
-
-//            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
-//            {
-//                numericConfigMap.Put(type.ToString(), new NumericConfig(PRECISION_STEP,
-//                    NUMBER_FORMAT, type));
-
-//                FieldType ft2 = new FieldType(IntField.TYPE_NOT_STORED);
-//                ft2.NumericTypeValue = (type);
-//                ft2.Stored = (true);
-//                ft2.NumericPrecisionStep = (PRECISION_STEP);
-//                ft2.Freeze();
-//                Field field;
-
-//                switch (type)
-//                {
-//                    case FieldType.NumericType.INT:
-//                        field = new IntField(type.ToString(), 0, ft2);
-//                        break;
-//                    case FieldType.NumericType.FLOAT:
-//                        field = new FloatField(type.ToString(), 0.0f, ft2);
-//                        break;
-//                    case FieldType.NumericType.LONG:
-//                        field = new LongField(type.ToString(), 0L, ft2);
-//                        break;
-//                    case FieldType.NumericType.DOUBLE:
-//                        field = new DoubleField(type.ToString(), 0.0, ft2);
-//                        break;
-//                    default:
-//                        fail();
-//                        field = null;
-//                        break;
-//                }
-//                numericFieldMap.Put(type.ToString(), field);
-//                doc.Add(field);
-//            }
-
-//            numericConfigMap.Put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
-//                DATE_FORMAT, FieldType.NumericType.LONG));
-//            FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
-//            ft.Stored = (true);
-//            ft.NumericPrecisionStep = (PRECISION_STEP);
-//            LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
-//            numericFieldMap.Put(DATE_FIELD_NAME, dateField);
-//            doc.Add(dateField);
-
-//            foreach (NumberType numberType in Enum.GetValues(typeof(NumberType)))
-//            {
-//                setFieldValues(numberType, numericFieldMap);
-//                if (VERBOSE) Console.WriteLine("Indexing document: " + doc);
-//                writer.AddDocument(doc);
-//            }
-
-//            reader = writer.Reader;
-//            searcher = NewSearcher(reader);
-//            writer.Dispose();
-
-//        }
-
-//        private static /*Number*/ object getNumberType(NumberType? numberType, String fieldName)
-//        {
-
-//            if (numberType == null)
-//            {
-//                return null;
-//            }
-
-//            switch (numberType)
-//            {
-
-//                case NumberType.POSITIVE:
-//                    return RANDOM_NUMBER_MAP[fieldName];
-
-//                case NumberType.NEGATIVE:
-//                    /*Number*/
-//                    object number = RANDOM_NUMBER_MAP[fieldName];
-
-//                    if (FieldType.NumericType.LONG.ToString().equals(fieldName)
-//                        || DATE_FIELD_NAME.equals(fieldName))
-//                    {
-//                        number = -Convert.ToInt64(number);
-
-//                    }
-//                    else if (FieldType.NumericType.DOUBLE.ToString().equals(fieldName))
-//                    {
-//                        number = -Convert.ToDouble(number);
-
-//                    }
-//                    else if (FieldType.NumericType.FLOAT.ToString().equals(fieldName))
-//                    {
-//                        number = -Convert.ToSingle(number);
-
-//                    }
-//                    else if (FieldType.NumericType.INT.ToString().equals(fieldName))
-//                    {
-//                        number = -Convert.ToInt32(number);
-
-//                    }
-//                    else
-//                    {
-//                        throw new ArgumentException("field name not found: "
-//                            + fieldName);
-//                    }
-
-//                    return number;
-
-//                default:
-//                    return 0;
-
-//            }
-
-//        }
-
-//        private static void setFieldValues(NumberType numberType,
-//            HashMap<String, Field> numericFieldMap)
-//        {
-
-//            /*Number*/
-//            object number = getNumberType(numberType, FieldType.NumericType.DOUBLE
-//     .ToString());
-//            numericFieldMap[FieldType.NumericType.DOUBLE.ToString()].DoubleValue = Convert.ToDouble(
-//                number);
-
-//            number = getNumberType(numberType, FieldType.NumericType.INT.ToString());
-//            numericFieldMap[FieldType.NumericType.INT.ToString()].IntValue = Convert.ToInt32(
-//                number);
-
-//            number = getNumberType(numberType, FieldType.NumericType.LONG.ToString());
-//            numericFieldMap[FieldType.NumericType.LONG.ToString()].LongValue = Convert.ToInt64(
-//                number);
-
-//            number = getNumberType(numberType, FieldType.NumericType.FLOAT.ToString());
-//            numericFieldMap[FieldType.NumericType.FLOAT.ToString()].FloatValue = Convert.ToSingle(
-//                number);
-
-//            number = getNumberType(numberType, DATE_FIELD_NAME);
-//            numericFieldMap[DATE_FIELD_NAME].LongValue = Convert.ToInt64(number);
-//        }
-
-//        private static int randomDateStyle(Random random)
-//        {
-//            return DATE_STYLES[random.nextInt(DATE_STYLES.Length)];
-//        }
-
-//        [Test]
-//        public void testInclusiveNumericRange()
-//        {
-//            assertRangeQuery(NumberType.ZERO, NumberType.ZERO, true, true, 1);
-//            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, true, 2);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, true, true, 2);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, true, true, 3);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, true, true, 1);
-//        }
-
-//        [Test]
-//        // test disabled since standard syntax parser does not work with inclusive and
-//        // exclusive at the same time
-//        public void testInclusiveLowerNumericRange()
-//        {
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, false, true, 1);
-//            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, false, true, 1);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, false, true, 2);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, false, true, 0);
-//        }
-
-//        [Test]
-//        // test disabled since standard syntax parser does not work with inclusive and
-//        // exclusive at the same time
-//        public void testInclusiveUpperNumericRange()
-//        {
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, true, false, 1);
-//            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, false, 1);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, true, false, 2);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, true, false, 0);
-//        }
-
-//        [Test]
-//        public void testExclusiveNumericRange()
-//        {
-//            assertRangeQuery(NumberType.ZERO, NumberType.ZERO, false, false, 0);
-//            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, false, false, 0);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, false, false, 0);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, false, false, 1);
-//            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, false, false, 0);
-//        }
-
-//        [Test]
-//        public void testOpenRangeNumericQuery()
-//        {
-//            assertOpenRangeQuery(NumberType.ZERO, "<", 1);
-//            assertOpenRangeQuery(NumberType.POSITIVE, "<", 2);
-//            assertOpenRangeQuery(NumberType.NEGATIVE, "<", 0);
-
-//            assertOpenRangeQuery(NumberType.ZERO, "<=", 2);
-//            assertOpenRangeQuery(NumberType.POSITIVE, "<=", 3);
-//            assertOpenRangeQuery(NumberType.NEGATIVE, "<=", 1);
-
-//            assertOpenRangeQuery(NumberType.ZERO, ">", 1);
-//            assertOpenRangeQuery(NumberType.POSITIVE, ">", 0);
-//            assertOpenRangeQuery(NumberType.NEGATIVE, ">", 2);
-
-//            assertOpenRangeQuery(NumberType.ZERO, ">=", 2);
-//            assertOpenRangeQuery(NumberType.POSITIVE, ">=", 1);
-//            assertOpenRangeQuery(NumberType.NEGATIVE, ">=", 3);
-
-//            assertOpenRangeQuery(NumberType.NEGATIVE, "=", 1);
-//            assertOpenRangeQuery(NumberType.ZERO, "=", 1);
-//            assertOpenRangeQuery(NumberType.POSITIVE, "=", 1);
-
-//            assertRangeQuery(NumberType.NEGATIVE, null, true, true, 3);
-//            assertRangeQuery(NumberType.NEGATIVE, null, false, true, 2);
-//            assertRangeQuery(NumberType.POSITIVE, null, true, false, 1);
-//            assertRangeQuery(NumberType.ZERO, null, false, false, 1);
-
-//            assertRangeQuery(null, NumberType.POSITIVE, true, true, 3);
-//            assertRangeQuery(null, NumberType.POSITIVE, true, false, 2);
-//            assertRangeQuery(null, NumberType.NEGATIVE, false, true, 1);
-//            assertRangeQuery(null, NumberType.ZERO, false, false, 1);
-
-//            assertRangeQuery(null, null, false, false, 3);
-//            assertRangeQuery(null, null, true, true, 3);
-
-//        }
-
-//        [Test]
-//        public void testSimpleNumericQuery()
-//        {
-//            assertSimpleQuery(NumberType.ZERO, 1);
-//            assertSimpleQuery(NumberType.POSITIVE, 1);
-//            assertSimpleQuery(NumberType.NEGATIVE, 1);
-//        }
-
-//        public void assertRangeQuery(NumberType? lowerType, NumberType? upperType,
-//            bool lowerInclusive, bool upperInclusive, int expectedDocCount)
-//        {
-
-
-//            StringBuilder sb = new StringBuilder();
-
-//            String lowerInclusiveStr = (lowerInclusive ? "[" : "{");
-//            String upperInclusiveStr = (upperInclusive ? "]" : "}");
-
-//            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
-//            {
-//                String lowerStr = numberToString(getNumberType(lowerType, type.ToString()));
-//                String upperStr = numberToString(getNumberType(upperType, type.ToString()));
-
-//                sb.append("+").append(type.ToString()).append(':').append(lowerInclusiveStr)
-//                  .append('"').append(lowerStr).append("\" TO \"").append(upperStr)
-//                  .append('"').append(upperInclusiveStr).append(' ');
-//            }
-
-//            /*Number*/
-//            object lowerDateNumber = getNumberType(lowerType, DATE_FIELD_NAME);
-//            /*Number*/
-//            object upperDateNumber = getNumberType(upperType, DATE_FIELD_NAME);
-//            String lowerDateStr;
-//            String upperDateStr;
-
-//            if (lowerDateNumber != null)
-//            {
-//                lowerDateStr = ESCAPER.Escape(
-//                    DATE_FORMAT.format(new DateTime(lowerDateNumber.longValue())), LOCALE,
-//                    EscapeQuerySyntax.Type.STRING).toString();
+using Lucene.Net;
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.QueryParsers.Flexible.Core.Parser;
+using Lucene.Net.QueryParsers.Flexible.Standard.Config;
+using Lucene.Net.QueryParsers.Flexible.Standard.Parser;
+using Lucene.Net.Search;
+using Lucene.Net.Store;
+using Lucene.Net.Support;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Lucene.Net.QueryParsers.Flexible.Standard
+{
+    public class TestNumericQueryParser : LuceneTestCase
+    {
+        public enum NumberType
+        {
+            NEGATIVE, ZERO, POSITIVE
+        }
+
+        
+
+        //  private readonly static int[] DATE_STYLES = {DateFormat.FULL, DateFormat.LONG,
+        //DateFormat.MEDIUM, DateFormat.SHORT};
+        private readonly static DateStyle[] DATE_STYLES = {DateStyle.FULL, DateStyle.LONG,
+            DateStyle.MEDIUM, DateStyle.SHORT};
+
+        private readonly static int PRECISION_STEP = 8;
+        private readonly static String FIELD_NAME = "field";
+        private static CultureInfo LOCALE;
+        private static TimeZoneInfo TIMEZONE;
+        private static IDictionary<String, /*Number*/ object> RANDOM_NUMBER_MAP;
+        private readonly static IEscapeQuerySyntax ESCAPER = new EscapeQuerySyntaxImpl();
+        private readonly static String DATE_FIELD_NAME = "date";
+        private static DateStyle DATE_STYLE;
+        private static DateStyle TIME_STYLE;
+
+        private static Analyzer ANALYZER;
+
+        private static NumberFormat NUMBER_FORMAT;
+        
+
+        private static StandardQueryParser qp;
+
+        private static NumberDateFormat DATE_FORMAT;
+
+        private static Directory directory = null;
+        private static IndexReader reader = null;
+        private static IndexSearcher searcher = null;
+
+        private static bool checkDateFormatSanity(/*DateFormat*/string dateFormat, long date)
+        {
+            DateTime result;
+            return DateTime.TryParseExact(new DateTime(date).ToString(dateFormat),
+                dateFormat, CultureInfo.CurrentCulture, DateTimeStyles.RoundtripKind, out result);
+            //try
+            //{
+            //    return date == dateFormat.parse(dateFormat.format(new DateTime(date)))
+            //      .getTime();
+            //}
+            //catch (ParseException e)
+            //{
+            //    return false;
+            //}
+        }
+
+        [TestFixtureSetUp]
+        public void BeforeClass()
+        {
+            ANALYZER = new MockAnalyzer(Random());
+
+            qp = new StandardQueryParser(ANALYZER);
+
+            HashMap<String, /*Number*/object> randomNumberMap = new HashMap<string, object>();
+
+            /*SimpleDateFormat*/
+            string dateFormat;
+            long randomDate;
+            bool dateFormatSanityCheckPass;
+            int count = 0;
+            do
+            {
+                if (count > 100)
+                {
+                    fail("This test has problems to find a sane random DateFormat/NumberFormat. Stopped trying after 100 iterations.");
+                }
+
+                dateFormatSanityCheckPass = true;
+                LOCALE = randomLocale(Random());
+                TIMEZONE = randomTimeZone(Random());
+                DATE_STYLE = randomDateStyle(Random());
+                TIME_STYLE = randomDateStyle(Random());
+
+                //// assumes localized date pattern will have at least year, month, day,
+                //// hour, minute
+                //dateFormat = (SimpleDateFormat)DateFormat.getDateTimeInstance(
+                //    DATE_STYLE, TIME_STYLE, LOCALE);
+
+                //// not all date patterns includes era, full year, timezone and second,
+                //// so we add them here
+                //dateFormat.applyPattern(dateFormat.toPattern() + " G s Z yyyy");
+                //dateFormat.setTimeZone(TIMEZONE);
+
+                //DATE_FORMAT = new NumberDateFormat(dateFormat);
+
+                //dateFormat = GetDateFormat((FormattingStyle)DATE_STYLE, (FormattingStyle)TIME_STYLE, LOCALE, TIMEZONE);
+
+                // LUCENENET TODO: NumberDateFormat...?
+                // DATE_FORMAT = GetDateFormat((FormattingStyle)DATE_STYLE, (FormattingStyle)TIME_STYLE, LOCALE, TIMEZONE);
+                DATE_FORMAT = new NumberDateFormat(DATE_STYLE, TIME_STYLE, LOCALE, TIMEZONE);
+
+
+                do
+                {
+                    randomDate = Random().nextLong();
+
+                    // prune date value so it doesn't pass in insane values to some
+                    // calendars.
+                    randomDate = randomDate % 3400000000000L;
+
+                    // truncate to second
+                    randomDate = (randomDate / 1000L) * 1000L;
+
+                    // only positive values
+                    randomDate = Math.Abs(randomDate);
+                } while (randomDate == 0L);
+
+                //dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, randomDate);
+
+                //dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat, 0);
+
+                // LUCENENET TODO: passing a negative number for ticks is invalid in .NET
+                //dateFormatSanityCheckPass &= checkDateFormatSanity(dateFormat,
+                //          -randomDate);
+
+                count++;
+            } while (!dateFormatSanityCheckPass);
+
+            //NUMBER_FORMAT = NumberFormat.getNumberInstance(LOCALE);
+            //NUMBER_FORMAT.setMaximumFractionDigits((Random().nextInt() & 20) + 1);
+            //NUMBER_FORMAT.setMinimumFractionDigits((Random().nextInt() & 20) + 1);
+            //NUMBER_FORMAT.setMaximumIntegerDigits((Random().nextInt() & 20) + 1);
+            //NUMBER_FORMAT.setMinimumIntegerDigits((Random().nextInt() & 20) + 1);
+
+            //NUMBER_FORMAT = (NumberFormatInfo)LOCALE.NumberFormat.Clone();
+            //NUMBER_FORMAT.NumberDecimalDigits = (Random().nextInt() & 20) + 1;
+            //NUMBER_FORMAT.CurrencyDecimalDigits = (Random().nextInt() & 20) + 1;
+
+            //NUMBER_FORMAT = GetNumberFormat();
+
+            NUMBER_FORMAT = new NumberFormat(LOCALE);
+
+            double randomDouble;
+            long randomLong;
+            int randomInt;
+            float randomFloat;
+
+            while ((randomLong = Convert.ToInt64(normalizeNumber(Math.Abs(Random().nextLong()))
+                )) == 0L)
+                ;
+            while ((randomDouble = Convert.ToDouble(normalizeNumber(Math.Abs(Random().NextDouble()))
+                )) == 0.0)
+                ;
+            while ((randomFloat = Convert.ToSingle(normalizeNumber(Math.Abs(Random().nextFloat()))
+                )) == 0.0f)
+                ;
+            while ((randomInt = Convert.ToInt32(normalizeNumber(Math.Abs(Random().nextInt())))) == 0)
+                ;
+
+            randomNumberMap.Put(FieldType.NumericType.LONG.ToString(), randomLong);
+            randomNumberMap.Put(FieldType.NumericType.INT.ToString(), randomInt);
+            randomNumberMap.Put(FieldType.NumericType.FLOAT.ToString(), randomFloat);
+            randomNumberMap.Put(FieldType.NumericType.DOUBLE.ToString(), randomDouble);
+            randomNumberMap.Put(DATE_FIELD_NAME, randomDate);
+
+            RANDOM_NUMBER_MAP = Collections.UnmodifiableMap(randomNumberMap);
+
+            directory = NewDirectory();
+            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory,
+                NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()))
+                    .SetMaxBufferedDocs(TestUtil.NextInt(Random(), 50, 1000))
+                    .SetMergePolicy(NewLogMergePolicy()));
+
+            Document doc = new Document();
+            HashMap<String, NumericConfig> numericConfigMap = new HashMap<String, NumericConfig>();
+            HashMap<String, Field> numericFieldMap = new HashMap<String, Field>();
+            qp.NumericConfigMap = (numericConfigMap);
+
+            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
+            {
+                numericConfigMap.Put(type.ToString(), new NumericConfig(PRECISION_STEP,
+                    NUMBER_FORMAT, type)); 
+
+                FieldType ft2 = new FieldType(IntField.TYPE_NOT_STORED);
+                ft2.NumericTypeValue = (type);
+                ft2.Stored = (true);
+                ft2.NumericPrecisionStep = (PRECISION_STEP);
+                ft2.Freeze();
+                Field field;
+
+                switch (type)
+                {
+                    case FieldType.NumericType.INT:
+                        field = new IntField(type.ToString(), 0, ft2);
+                        break;
+                    case FieldType.NumericType.FLOAT:
+                        field = new FloatField(type.ToString(), 0.0f, ft2);
+                        break;
+                    case FieldType.NumericType.LONG:
+                        field = new LongField(type.ToString(), 0L, ft2);
+                        break;
+                    case FieldType.NumericType.DOUBLE:
+                        field = new DoubleField(type.ToString(), 0.0, ft2);
+                        break;
+                    default:
+                        fail();
+                        field = null;
+                        break;
+                }
+                numericFieldMap.Put(type.ToString(), field);
+                doc.Add(field);
+            }
+
+            numericConfigMap.Put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
+                DATE_FORMAT, FieldType.NumericType.LONG));
+            FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
+            ft.Stored = (true);
+            ft.NumericPrecisionStep = (PRECISION_STEP);
+            LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
+            numericFieldMap.Put(DATE_FIELD_NAME, dateField);
+            doc.Add(dateField);
+
+            foreach (NumberType numberType in Enum.GetValues(typeof(NumberType)))
+            {
+                setFieldValues(numberType, numericFieldMap);
+                if (VERBOSE) Console.WriteLine("Indexing document: " + doc);
+                writer.AddDocument(doc);
+            }
+
+            reader = writer.Reader;
+            searcher = NewSearcher(reader);
+            writer.Dispose();
+
+        }
+
+        private static /*Number*/ object getNumberType(NumberType? numberType, String fieldName)
+        {
+
+            if (numberType == null)
+            {
+                return null;
+            }
+
+            switch (numberType)
+            {
+
+                case NumberType.POSITIVE:
+                    return RANDOM_NUMBER_MAP[fieldName];
+
+                case NumberType.NEGATIVE:
+                    /*Number*/
+                    object number = RANDOM_NUMBER_MAP[fieldName];
+
+                    if (FieldType.NumericType.LONG.ToString().equals(fieldName)
+                        || DATE_FIELD_NAME.equals(fieldName))
+                    {
+                        number = -Convert.ToInt64(number);
+
+                    }
+                    else if (FieldType.NumericType.DOUBLE.ToString().equals(fieldName))
+                    {
+                        number = -Convert.ToDouble(number);
+
+                    }
+                    else if (FieldType.NumericType.FLOAT.ToString().equals(fieldName))
+                    {
+                        number = -Convert.ToSingle(number);
+
+                    }
+                    else if (FieldType.NumericType.INT.ToString().equals(fieldName))
+                    {
+                        number = -Convert.ToInt32(number);
+
+                    }
+                    else
+                    {
+                        throw new ArgumentException("field name not found: "
+                            + fieldName);
+                    }
+
+                    return number;
+
+                default:
+                    return 0;
+
+            }
+
+        }
+
+        private static void setFieldValues(NumberType numberType,
+            HashMap<String, Field> numericFieldMap)
+        {
+
+            /*Number*/
+            object number = getNumberType(numberType, FieldType.NumericType.DOUBLE
+                .ToString());
+            numericFieldMap[FieldType.NumericType.DOUBLE.ToString()].DoubleValue = Convert.ToDouble(
+                number);
+
+            number = getNumberType(numberType, FieldType.NumericType.INT.ToString());
+            numericFieldMap[FieldType.NumericType.INT.ToString()].IntValue = Convert.ToInt32(
+                number);
+
+            number = getNumberType(numberType, FieldType.NumericType.LONG.ToString());
+            numericFieldMap[FieldType.NumericType.LONG.ToString()].LongValue = Convert.ToInt64(
+                number);
+
+            number = getNumberType(numberType, FieldType.NumericType.FLOAT.ToString());
+            numericFieldMap[FieldType.NumericType.FLOAT.ToString()].FloatValue = Convert.ToSingle(
+                number);
+
+            number = getNumberType(numberType, DATE_FIELD_NAME);
+            numericFieldMap[DATE_FIELD_NAME].LongValue = Convert.ToInt64(number);
+        }
+
+        private static DateStyle randomDateStyle(Random random)
+        {
+            return DATE_STYLES[random.nextInt(DATE_STYLES.Length)];
+        }
+
+        [Test]
+        public void testInclusiveNumericRange()
+        {
+            assertRangeQuery(NumberType.ZERO, NumberType.ZERO, true, true, 1);
+            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, true, 2);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, true, true, 2);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, true, true, 3);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, true, true, 1);
+        }
+
+        [Test]
+        // test disabled since standard syntax parser does not work with inclusive and
+        // exclusive at the same time
+        public void testInclusiveLowerNumericRange()
+        {
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, false, true, 1);
+            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, false, true, 1);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, false, true, 2);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, false, true, 0);
+        }
+
+        [Test]
+        // test disabled since standard syntax parser does not work with inclusive and
+        // exclusive at the same time
+        public void testInclusiveUpperNumericRange()
+        {
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, true, false, 1);
+            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, false, 1);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, true, false, 2);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, true, false, 0);
+        }
+
+        [Test]
+        public void testExclusiveNumericRange()
+        {
+            assertRangeQuery(NumberType.ZERO, NumberType.ZERO, false, false, 0);
+            assertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, false, false, 0);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.ZERO, false, false, 0);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.POSITIVE, false, false, 1);
+            assertRangeQuery(NumberType.NEGATIVE, NumberType.NEGATIVE, false, false, 0);
+        }
+
+        [Test]
+        public void testOpenRangeNumericQuery()
+        {
+            assertOpenRangeQuery(NumberType.ZERO, "<", 1);
+            assertOpenRangeQuery(NumberType.POSITIVE, "<", 2);
+            assertOpenRangeQuery(NumberType.NEGATIVE, "<", 0);
+
+            assertOpenRangeQuery(NumberType.ZERO, "<=", 2);
+            assertOpenRangeQuery(NumberType.POSITIVE, "<=", 3);
+            assertOpenRangeQuery(NumberType.NEGATIVE, "<=", 1);
+
+            assertOpenRangeQuery(NumberType.ZERO, ">", 1);
+            assertOpenRangeQuery(NumberType.POSITIVE, ">", 0);
+            assertOpenRangeQuery(NumberType.NEGATIVE, ">", 2);
+
+            assertOpenRangeQuery(NumberType.ZERO, ">=", 2);
+            assertOpenRangeQuery(NumberType.POSITIVE, ">=", 1);
+            assertOpenRangeQuery(NumberType.NEGATIVE, ">=", 3);
+
+            assertOpenRangeQuery(NumberType.NEGATIVE, "=", 1);
+            assertOpenRangeQuery(NumberType.ZERO, "=", 1);
+            assertOpenRangeQuery(NumberType.POSITIVE, "=", 1);
+
+            assertRangeQuery(NumberType.NEGATIVE, null, true, true, 3);
+            assertRangeQuery(NumberType.NEGATIVE, null, false, true, 2);
+            assertRangeQuery(NumberType.POSITIVE, null, true, false, 1);
+            assertRangeQuery(NumberType.ZERO, null, false, false, 1);
+
+            assertRangeQuery(null, NumberType.POSITIVE, true, true, 3);
+            assertRangeQuery(null, NumberType.POSITIVE, true, false, 2);
+            assertRangeQuery(null, NumberType.NEGATIVE, false, true, 1);
+            assertRangeQuery(null, NumberType.ZERO, false, false, 1);
+
+            assertRangeQuery(null, null, false, false, 3);
+            assertRangeQuery(null, null, true, true, 3);
+
+        }
+
+        [Test]
+        public void testSimpleNumericQuery()
+        {
+            assertSimpleQuery(NumberType.ZERO, 1);
+            assertSimpleQuery(NumberType.POSITIVE, 1);
+            assertSimpleQuery(NumberType.NEGATIVE, 1);
+        }
+
+        public void assertRangeQuery(NumberType? lowerType, NumberType? upperType,
+            bool lowerInclusive, bool upperInclusive, int expectedDocCount)
+        {
+
+
+            StringBuilder sb = new StringBuilder();
+
+            String lowerInclusiveStr = (lowerInclusive ? "[" : "{");
+            String upperInclusiveStr = (upperInclusive ? "]" : "}");
+
+            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
+            {
+                String lowerStr = numberToString(getNumberType(lowerType, type.ToString()));
+                String upperStr = numberToString(getNumberType(upperType, type.ToString()));
+
+                sb.append("+").append(type.ToString()).append(':').append(lowerInclusiveStr)
+                  .append('"').append(lowerStr).append("\" TO \"").append(upperStr)
+                  .append('"').append(upperInclusiveStr).append(' ');
+            }
+
+            /*Number*/
+            object lowerDateNumber = getNumberType(lowerType, DATE_FIELD_NAME);
+            /*Number*/
+            object upperDateNumber = getNumberType(upperType, DATE_FIELD_NAME);
+            String lowerDateStr;
+            String upperDateStr;
+
+            if (lowerDateNumber != null)
+            {
+                //lowerDateStr = ESCAPER.Escape(
+                //    DATE_FORMAT.format(new DateTime(lowerDateNumber.longValue())), LOCALE,
+                //    EscapeQuerySyntax.Type.STRING).toString();
+
+                //lowerDateStr = ESCAPER.Escape(
+                //        string.Format(LOCALE, "{0:" + DATE_FORMAT + "}", new DateTime(Convert.ToInt64(lowerDateNumber))),
+                //        LOCALE,
+                //        EscapeQuerySyntax.Type.STRING).toString();
+
+                lowerDateStr = ESCAPER.Escape(
+                            DATE_FORMAT.Format(Convert.ToInt64(lowerDateNumber)),
+                            LOCALE,
+                            EscapeQuerySyntax.Type.STRING).toString();
+            }
+            else
+            {
+                lowerDateStr = "*";
+            }
+
+            if (upperDateNumber != null)
+            {
+                //upperDateStr = ESCAPER.Escape(
+                //      DATE_FORMAT.format(new DateTime(upperDateNumber.longValue())), LOCALE,
+                //      EscapeQuerySyntax.Type.STRING).toString();
+
+                //upperDateStr = ESCAPER.Escape(
+                //            string.Format(LOCALE, "{0:" + DATE_FORMAT + "}", new DateTime(Convert.ToInt64(upperDateNumber))),
+                //            LOCALE,
+                //            EscapeQuerySyntax.Type.STRING).toString();
 
-//            }
-//            else
-//            {
-//                lowerDateStr = "*";
-//            }
+                upperDateStr = ESCAPER.Escape(
+                                DATE_FORMAT.Format(Convert.ToInt64(upperDateNumber)),
+                                LOCALE,
+                                EscapeQuerySyntax.Type.STRING).toString();
+            }
+            else
+            {
+                upperDateStr = "*";
+            }
+
+            sb.append("+").append(DATE_FIELD_NAME).append(':')
+                .append(lowerInclusiveStr).append('"').append(lowerDateStr).append(
+                    "\" TO \"").append(upperDateStr).append('"').append(
+                    upperInclusiveStr);
 
-//            if (upperDateNumber != null)
-//            {
-//                upperDateStr = ESCAPER.Escape(
-//                      DATE_FORMAT.format(new DateTime(upperDateNumber.longValue())), LOCALE,
-//                      EscapeQuerySyntax.Type.STRING).toString();
-
-//            }
-//            else
-//            {
-//                upperDateStr = "*";
-//            }
 
-//            sb.append("+").append(DATE_FIELD_NAME).append(':')
-//                .append(lowerInclusiveStr).append('"').append(lowerDateStr).append(
-//                    "\" TO \"").append(upperDateStr).append('"').append(
-//                    upperInclusiveStr);
+            testQuery(sb.toString(), expectedDocCount);
 
-
-//            testQuery(sb.toString(), expectedDocCount);
-
-//        }
-
-//        public void assertOpenRangeQuery(NumberType boundType, String @operator, int expectedDocCount)
-//        {
-
-//            StringBuilder sb = new StringBuilder();
-
-//            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
-//            {
-//                String boundStr = numberToString(getNumberType(boundType, type.ToString()));
-
-//                sb.append("+").append(type.ToString()).append(@operator).append('"').append(boundStr).append('"').append(' ');
-//            }
-
-//            String boundDateStr = ESCAPER.Escape(
-//                DATE_FORMAT.format(new Date(getNumberType(boundType, DATE_FIELD_NAME)
-//                    .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
-
-//            sb.append("+").append(DATE_FIELD_NAME).append(@operator).append('"').append(boundDateStr).append('"');
-
-
-//            testQuery(sb.toString(), expectedDocCount);
-//        }
-
-//        public void assertSimpleQuery(NumberType numberType, int expectedDocCount)
-//        {
-//            StringBuilder sb = new StringBuilder();
-
-//            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
-//            {
-//                String numberStr = numberToString(getNumberType(numberType, type.ToString()));
-//                sb.append('+').append(type.ToString()).append(":\"").append(numberStr)
-//                          .append("\" ");
-//            }
-
-//            String dateStr = ESCAPER.Escape(
-//                DATE_FORMAT.format(new DateTime(getNumberType(numberType, DATE_FIELD_NAME)
-//                    .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
-
-//            sb.append('+').append(DATE_FIELD_NAME).append(":\"").append(dateStr)
-//                    .append('"');
-
-
-//            testQuery(sb.toString(), expectedDocCount);
-
-//        }
-
-//        [Test]
-//        private void testQuery(String queryStr, int expectedDocCount)
-//        {
-//            if (VERBOSE) Console.WriteLine("Parsing: " + queryStr);
-
-//            Query query = qp.Parse(queryStr, FIELD_NAME);
-//            if (VERBOSE) Console.WriteLine("Querying: " + query);
-//            TopDocs topDocs = searcher.Search(query, 1000);
-
-//            String msg = "Query <" + queryStr + "> retrieved " + topDocs.TotalHits
-//                + " document(s), " + expectedDocCount + " document(s) expected.";
-
-//            if (VERBOSE) Console.WriteLine(msg);
-
-
-//            assertEquals(msg, expectedDocCount, topDocs.TotalHits);
-//        }
-
-//        private static String numberToString(/*Number*/ object number)
-//        {
-//            return number == null ? "*" : ESCAPER.Escape(/*NUMBER_FORMAT.format(number)*/ string.Format(NUMBER_FORMAT, number).ToCharSequence(),
-//                LOCALE, EscapeQuerySyntax.Type.STRING).toString();
-//        }
-
-//        private static /*Number*/ object normalizeNumber(/*Number*/ object number)
-//        {
-//            return decimal.Parse(string.Format(NUMBER_FORMAT, number));
-//            //return NUMBER_FORMAT.parse(NUMBER_FORMAT.format(number));
-//        }
-
-//        [TestFixtureTearDown]
-//        public static void afterClass()
-//        {
-//            searcher = null;
-//            reader.Dispose();
-//            reader = null;
-//            directory.Dispose();
-//            directory = null;
-//            qp = null;
-//        }
-//    }
-//}
+        }
+
+        public void assertOpenRangeQuery(NumberType boundType, String @operator, int expectedDocCount)
+        {
+
+            StringBuilder sb = new StringBuilder();
+
+            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
+            {
+                String boundStr = numberToString(getNumberType(boundType, type.ToString()));
+
+                sb.append("+").append(type.ToString()).append(@operator).append('"').append(boundStr).append('"').append(' ');
+            }
+
+            //String boundDateStr = ESCAPER.Escape(
+            //    DATE_FORMAT.format(new Date(getNumberType(boundType, DATE_FIELD_NAME)
+            //        .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
+
+            //string boundDateStr = ESCAPER.Escape(
+            //                string.Format(LOCALE, "{0:" + DATE_FORMAT + "}", new DateTime(Convert.ToInt64(getNumberType(boundType, DATE_FIELD_NAME)))),
+            //                LOCALE,
+            //                EscapeQuerySyntax.Type.STRING).toString();
+
+            string boundDateStr = ESCAPER.Escape(
+                                DATE_FORMAT.Format(Convert.ToInt64(getNumberType(boundType, DATE_FIELD_NAME))),
+                                LOCALE,
+                                EscapeQuerySyntax.Type.STRING).toString();
+
+            sb.append("+").append(DATE_FIELD_NAME).append(@operator).append('"').append(boundDateStr).append('"');
+
+
+            testQuery(sb.toString(), expectedDocCount);
+        }
+
+        public void assertSimpleQuery(NumberType numberType, int expectedDocCount)
+        {
+            StringBuilder sb = new StringBuilder();
+
+            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
+            {
+                String numberStr = numberToString(getNumberType(numberType, type.ToString()));
+                sb.append('+').append(type.ToString()).append(":\"").append(numberStr)
+                          .append("\" ");
+            }
+
+            //String dateStr = ESCAPER.Escape(
+            //    DATE_FORMAT.format(new DateTime(getNumberType(numberType, DATE_FIELD_NAME)
+            //        .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
+
+            //string dateStr = ESCAPER.Escape(
+            //                string.Format(LOCALE, "{0:" + DATE_FORMAT + "}", new DateTime(Convert.ToInt64(getNumberType(numberType, DATE_FIELD_NAME)))),
+            //                LOCALE,
+            //                EscapeQuerySyntax.Type.STRING).toString();
+
+            string dateStr = ESCAPER.Escape(
+                                DATE_FORMAT.Format(Convert.ToInt64(getNumberType(numberType, DATE_FIELD_NAME))),
+                                LOCALE,
+                                EscapeQuerySyntax.Type.STRING).toString();
+
+            sb.append('+').append(DATE_FIELD_NAME).append(":\"").append(dateStr)
+                    .append('"');
+
+
+            testQuery(sb.toString(), expectedDocCount);
+
+        }
+
+        private void testQuery(String queryStr, int expectedDocCount)
+        {
+            if (VERBOSE) Console.WriteLine("Parsing: " + queryStr);
+
+            Query query = qp.Parse(queryStr, FIELD_NAME);
+            if (VERBOSE) Console.WriteLine("Querying: " + query);
+            TopDocs topDocs = searcher.Search(query, 1000);
+
+            String msg = "Query <" + queryStr + "> retrieved " + topDocs.TotalHits
+                + " document(s), " + expectedDocCount + " document(s) expected.";
+
+            if (VERBOSE) Console.WriteLine(msg);
+
+
+            assertEquals(msg, expectedDocCount, topDocs.TotalHits);
+        }
+
+        private static String numberToString(/*Number*/ object number)
+        {
+            //return number == null ? "*" : ESCAPER.Escape(/*NUMBER_FORMAT.format(number)*/ string.Format("{0:" + NUMBER_FORMAT + "}", number).ToCharSequence(),
+            //    LOCALE, EscapeQuerySyntax.Type.STRING).toString();
+            return number == null ? "*" : ESCAPER.Escape(NUMBER_FORMAT.Format(number),
+                LOCALE, EscapeQuerySyntax.Type.STRING).toString();
+        }
+
+        private static /*Number*/ object normalizeNumber(/*Number*/ object number)
+        {
+            //return decimal.Parse(string.Format("{0:" + NUMBER_FORMAT + "}", number));
+            return NUMBER_FORMAT.Parse(NUMBER_FORMAT.Format(number));
+        }
+
+        [TestFixtureTearDown]
+        public static void afterClass()
+        {
+            searcher = null;
+            reader.Dispose();
+            reader = null;
+            directory.Dispose();
+            directory = null;
+            qp = null;
+        }
+
+
+        //private string GetDateFormat(DateFormat dateStyle, DateFormat timeStyle, CultureInfo locale, TimeZoneInfo timeZone)
+        //{
+        //    string datePattern = "", timePattern = "";
+
+        //    switch (dateStyle)
+        //    {
+        //        case DateFormat.SHORT:
+        //            datePattern = locale.DateTimeFormat.ShortDatePattern;
+        //            break;
+        //        case DateFormat.MEDIUM:
+        //            datePattern = locale.DateTimeFormat.LongDatePattern
+        //                .Replace("dddd,", "").Replace(", dddd", "") // Remove the day of the week
+        //                .Replace("MMMM", "MMM"); // Replace month with abbreviated month
+        //            break;
+        //        case DateFormat.LONG:
+        //            datePattern = locale.DateTimeFormat.LongDatePattern
+        //                .Replace("dddd,", "").Replace(", dddd", ""); // Remove the day of the week
+        //            break;
+        //        case DateFormat.FULL:
+        //            datePattern = locale.DateTimeFormat.LongDatePattern;
+        //            break;
+        //    }
+
+        //    switch (timeStyle)
+        //    {
+        //        case DateFormat.SHORT:
+        //            timePattern = locale.DateTimeFormat.ShortTimePattern;
+        //            break;
+        //        case DateFormat.MEDIUM:
+        //            timePattern = locale.DateTimeFormat.LongTimePattern;
+        //            break;
+        //        case DateFormat.LONG:
+        //            timePattern = locale.DateTimeFormat.LongTimePattern; // LUCENENET TODO: Time zone info not being added
+        //            break;
+        //        case DateFormat.FULL:
+        //            timePattern = locale.DateTimeFormat.LongTimePattern; // LUCENENET TODO: Time zone info not being added, but Java doc is unclear on what the difference is between this and LONG
+        //            break;
+        //    }
+
+        //    return string.Concat(datePattern, " ", timePattern);
+        //}
+
+        //private string GetNumberFormat()
+        //{
+        //    string integerDigits = string.Join("", Enumerable.Repeat("#", Random().nextInt(20))) + "0";
+        //    string fractionalDigits = "." + string.Join("", Enumerable.Repeat("#", Random().nextInt(21)));
+
+        //    return integerDigits + fractionalDigits;
+        //}
+
+        //private class RandomNumberFormatProvider : IFormatProvider
+        //{
+        //    private readonly CultureInfo locale;
+
+        //    public RandomNumberFormatProvider(CultureInfo locale)
+        //    {
+        //        this.locale = locale;
+        //    }
+
+        //    public object GetFormat(Type formatType)
+        //    {
+        //        if (formatType == typeof(NumberFormatInfo))
+        //            return GetRandomNumberFormat();
+
+        //        return null;
+        //    }
+
+        //    private NumberFormatInfo GetRandomNumberFormat()
+        //    {
+        //        var culture = locale;
+        //        if (culture == null)
+        //            culture = CultureInfo.CurrentCulture;
+
+        //        var NUMBER_FORMAT = (NumberFormatInfo)culture.NumberFormat.Clone();
+        //        NUMBER_FORMAT.NumberDecimalDigits = (Random().nextInt() & 20) + 1;
+        //        NUMBER_FORMAT.CurrencyDecimalDigits = (Random().nextInt() & 20) + 1;
+
+        //        return NUMBER_FORMAT;
+        //    }
+        //}
+
+        //internal class TestFormatProvider : IFormatProvider, ICustomFormatter
+        //{
+        //    private readonly CultureInfo locale;
+
+        //    public string Format(string format, object arg, IFormatProvider formatProvider)
+        //    {
+        //        return "MM/dd/yyyy";
+        //    }
+
+        //    //public RandomNumberFormatProvider(CultureInfo locale)
+        //    //{
+        //    //    this.locale = locale;
+        //    //}
+
+        //    public object GetFormat(Type formatType)
+        //    {
+        //        if (formatType == typeof(NumberFormatInfo))
+        //            //return GetRandomNumberFormat();
+        //            //return "MM/dd/yyyy";
+        //            return this;
+
+        //        return null;
+        //    }
+
+        //    //private NumberFormatInfo GetRandomNumberFormat()
+        //    //{
+        //    //    var culture = locale;
+        //    //    if (culture == null)
+        //    //        culture = CultureInfo.CurrentCulture;
+
+        //    //    var NUMBER_FORMAT = (NumberFormatInfo)culture.NumberFormat.Clone();
+        //    //    NUMBER_FORMAT.NumberDecimalDigits = (Random().nextInt() & 20) + 1;
+        //    //    NUMBER_FORMAT.CurrencyDecimalDigits = (Random().nextInt() & 20) + 1;
+
+        //    //    return NUMBER_FORMAT;
+        //    //}
+
+        //}
+    }
+}


Mime
View raw message