lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [13/58] lucenenet git commit: Getting TestNumericQueryParser closer to compiling
Date Tue, 06 Dec 2016 15:11:48 GMT
Getting TestNumericQueryParser closer to compiling


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

Branch: refs/heads/master
Commit: 01233db7c2d91a4812f423876276dd7f4b42f6ce
Parents: 94f22c1
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Nov 29 09:55:22 2016 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Nov 29 09:55:22 2016 +0700

----------------------------------------------------------------------
 .../JavaCompatibility/LuceneTestCase.cs         |  12 +
 .../JavaCompatibility/RandomHelpers.cs          |  18 +
 .../Flexible/Standard/TestNumericQueryParser.cs | 898 ++++++++++---------
 3 files changed, 500 insertions(+), 428 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/01233db7/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
index f0dc587..88f8f9b 100644
--- a/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/JavaCompatibility/LuceneTestCase.cs
@@ -4,6 +4,8 @@ using System.Collections.Generic;
 using System.Linq;
 using NUnit.Framework;
 using System.Diagnostics;
+using System.Globalization;
+using Lucene.Net.Randomized.Generators;
 
 namespace Lucene.Net.Util
 {
@@ -241,5 +243,15 @@ namespace Lucene.Net.Util
                 return v1 * multiplier;
             }
         }
+
+        protected virtual CultureInfo randomLocale(Random random)
+        {
+            return RandomInts.RandomFrom(random, CultureInfo.GetCultures(CultureTypes.AllCultures));
+        }
+
+        protected virtual TimeZoneInfo randomTimeZone(Random random)
+        {
+            return RandomInts.RandomFrom(random, TimeZoneInfo.GetSystemTimeZones());
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/01233db7/src/Lucene.Net.TestFramework/JavaCompatibility/RandomHelpers.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/JavaCompatibility/RandomHelpers.cs b/src/Lucene.Net.TestFramework/JavaCompatibility/RandomHelpers.cs
index 5a66516..09d9b96 100644
--- a/src/Lucene.Net.TestFramework/JavaCompatibility/RandomHelpers.cs
+++ b/src/Lucene.Net.TestFramework/JavaCompatibility/RandomHelpers.cs
@@ -9,9 +9,27 @@ namespace Lucene.Net
             return random.Next(maxValue);
         }
 
+        public static int nextInt(this Random random)
+        {
+            return random.Next();
+        }
+
         public static bool nextBoolean(this Random random)
         {
             return (random.Next(1, 100) > 50);
         }
+
+        // http://stackoverflow.com/a/6651656
+        public static long nextLong(this Random random)
+        {
+            byte[] buffer = new byte[8];
+            random.NextBytes(buffer);
+            return BitConverter.ToInt64(buffer, 0);
+        }
+
+        public static float nextFloat(this Random random)
+        {
+            return (float)random.NextDouble();
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/01233db7/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 04ac847..29f6031 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
@@ -1,15 +1,18 @@
-// LUCENENET TODO: Complete implementation
-
-//using Lucene.Net;
+//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;
@@ -18,506 +21,545 @@
 //{
 //    public class TestNumericQueryParser : LuceneTestCase
 //    {
-//        private static enum NumberType
+//        public enum NumberType
 //        {
-//            NEGATIVE, ZERO, POSITIVE;
+//            NEGATIVE, ZERO, POSITIVE
 //        }
 
-//        private readonly static int[] DATE_STYLES = {DateFormat.FULL, DateFormat.LONG,
-//      DateFormat.MEDIUM, DateFormat.SHORT};
+//        /// <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 Locale LOCALE;
-//        private static TimeZone TIMEZONE;
-//        private static Map<String, Number> RANDOM_NUMBER_MAP;
-//        private readonly static EscapeQuerySyntax ESCAPER = new EscapeQuerySyntaxImpl();
+//        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 NUMBER_FORMAT;
+//        private static /*NumberFormat*/ string NUMBER_FORMAT;
 
 //        private static StandardQueryParser qp;
 
-//        private static NumberDateFormat DATE_FORMAT;
+//        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 dateFormat, long date)
+//        private static bool checkDateFormatSanity(/*DateFormat*/string dateFormat, long
date)
 //        {
-//            try
-//            {
-//                return date == dateFormat.parse(dateFormat.format(new DateTime(date)))
-//                  .getTime();
-//            }
-//            catch (ParseException e)
-//            {
-//                return false;
-//            }
+//            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 static void beforeClass() 
+//        public void BeforeClass()
 //        {
 //            ANALYZER = new MockAnalyzer(Random());
-    
-//    qp = new StandardQueryParser(ANALYZER);
-
-//        HashMap<String, Number> randomNumberMap = new HashMap<>();
-
-//        SimpleDateFormat 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 = normalizeNumber(Math.abs(Random().nextLong()))
-//        .longValue()) == 0L)
-//      ;
-//    while ((randomDouble = normalizeNumber(Math.abs(Random().nextDouble()))
-//        .doubleValue()) == 0.0)
-//      ;
-//    while ((randomFloat = normalizeNumber(Math.abs(Random().nextFloat()))
-//        .floatValue()) == 0.0f)
-//      ;
-//    while ((randomInt = normalizeNumber(Math.abs(Random().nextInt())).intValue()) == 0)
-//      ;
-    
-//    randomNumberMap.put(NumericType.LONG.name(), randomLong);
-//    randomNumberMap.put(NumericType.INT.name(), randomInt);
-//    randomNumberMap.put(NumericType.FLOAT.name(), randomFloat);
-//    randomNumberMap.put(NumericType.DOUBLE.name(), 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<>();
-//HashMap<String, Field> numericFieldMap = new HashMap<>();
-//qp.setNumericConfigMap(numericConfigMap);
-    
-//    for (NumericType type : NumericType.values()) {
-//      numericConfigMap.put(type.name(), new NumericConfig(PRECISION_STEP,
-//          NUMBER_FORMAT, type));
-
-//      FieldType ft = new FieldType(IntField.TYPE_NOT_STORED);
-//ft.setNumericType(type);
-//      ft.setStored(true);
-//      ft.setNumericPrecisionStep(PRECISION_STEP);
-//      ft.freeze();
-//      final Field field;
-
-//      switch(type) {
-//      case INT:
-//        field = new IntField(type.name(), 0, ft);
-//        break;
-//      case FLOAT:
-//        field = new FloatField(type.name(), 0.0f, ft);
-//        break;
-//      case LONG:
-//        field = new LongField(type.name(), 0l, ft);
-//        break;
-//      case DOUBLE:
-//        field = new DoubleField(type.name(), 0.0, ft);
-//        break;
-//      default:
-//        fail();
-//field = null;
-//      }
-//      numericFieldMap.put(type.name(), field);
-//      doc.add(field);
-//    }
-    
-//    numericConfigMap.put(DATE_FIELD_NAME, new NumericConfig(PRECISION_STEP,
-//        DATE_FORMAT, NumericType.LONG));
-//    FieldType ft = new FieldType(LongField.TYPE_NOT_STORED);
-//ft.setStored(true);
-//    ft.setNumericPrecisionStep(PRECISION_STEP);
-//    LongField dateField = new LongField(DATE_FIELD_NAME, 0l, ft);
-//numericFieldMap.put(DATE_FIELD_NAME, dateField);
-//    doc.add(dateField);
-    
-//    for (NumberType numberType : NumberType.values()) {
-//      setFieldValues(numberType, numericFieldMap);
-//      if (VERBOSE) System.out.println("Indexing document: " + doc);
-//writer.addDocument(doc);
-//    }
-    
-//    reader = writer.getReader();
-//    searcher = newSearcher(reader);
-//writer.close();
-    
-//  }
-  
-//  private static Number getNumberType(NumberType numberType, String fieldName)
-//{
+//            qp = new StandardQueryParser(ANALYZER);
 
-//    if (numberType == null)
-//    {
-//        return null;
-//    }
+//            HashMap<String, /*Number*/object> randomNumberMap = new HashMap<string,
object>();
 
-//    switch (numberType)
-//    {
-
-//        case POSITIVE:
-//            return RANDOM_NUMBER_MAP.get(fieldName);
+//            /*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);
+//            }
 
-//        case NEGATIVE:
-//            Number number = RANDOM_NUMBER_MAP.get(fieldName);
+//            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);
 
-//            if (NumericType.LONG.name().equals(fieldName)
-//                || DATE_FIELD_NAME.equals(fieldName))
+//            foreach (NumberType numberType in Enum.GetValues(typeof(NumberType)))
 //            {
-//                number = -number.longValue();
+//                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;
 //            }
-//            else if (NumericType.DOUBLE.name().equals(fieldName))
+
+//            switch (numberType)
 //            {
-//                number = -number.doubleValue();
+
+//                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;
 
 //            }
-//            else if (NumericType.FLOAT.name().equals(fieldName))
+
+//        }
+
+//        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)))
 //            {
-//                number = -number.floatValue();
+//                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(' ');
 //            }
-//            else if (NumericType.INT.name().equals(fieldName))
+
+//            /*Number*/
+//            object lowerDateNumber = getNumberType(lowerType, DATE_FIELD_NAME);
+//            /*Number*/
+//            object upperDateNumber = getNumberType(upperType, DATE_FIELD_NAME);
+//            String lowerDateStr;
+//            String upperDateStr;
+
+//            if (lowerDateNumber != null)
 //            {
-//                number = -number.intValue();
+//                lowerDateStr = ESCAPER.Escape(
+//                    DATE_FORMAT.format(new DateTime(lowerDateNumber.longValue())), LOCALE,
+//                    EscapeQuerySyntax.Type.STRING).toString();
 
 //            }
 //            else
 //            {
-//                throw new IllegalArgumentException("field name not found: "
-//                    + fieldName);
+//                lowerDateStr = "*";
 //            }
 
-//            return number;
-
-//        default:
-//            return 0;
-
-//    }
-
-//}
-
-//private static void setFieldValues(NumberType numberType,
-//    HashMap<String, Field> numericFieldMap)
-//{
-
-//    Number number = getNumberType(numberType, NumericType.DOUBLE
-//        .name());
-//    numericFieldMap.get(NumericType.DOUBLE.name()).setDoubleValue(
-//        number.doubleValue());
+//            if (upperDateNumber != null)
+//            {
+//                upperDateStr = ESCAPER.Escape(
+//                      DATE_FORMAT.format(new DateTime(upperDateNumber.longValue())), LOCALE,
+//                      EscapeQuerySyntax.Type.STRING).toString();
 
-//    number = getNumberType(numberType, NumericType.INT.name());
-//    numericFieldMap.get(NumericType.INT.name()).setIntValue(
-//        number.intValue());
+//            }
+//            else
+//            {
+//                upperDateStr = "*";
+//            }
 
-//    number = getNumberType(numberType, NumericType.LONG.name());
-//    numericFieldMap.get(NumericType.LONG.name()).setLongValue(
-//        number.longValue());
+//            sb.append("+").append(DATE_FIELD_NAME).append(':')
+//                .append(lowerInclusiveStr).append('"').append(lowerDateStr).append(
+//                    "\" TO \"").append(upperDateStr).append('"').append(
+//                    upperInclusiveStr);
 
-//    number = getNumberType(numberType, NumericType.FLOAT.name());
-//    numericFieldMap.get(NumericType.FLOAT.name()).setFloatValue(
-//        number.floatValue());
 
-//    number = getNumberType(numberType, DATE_FIELD_NAME);
-//    numericFieldMap.get(DATE_FIELD_NAME).setLongValue(number.longValue());
-//}
+//            testQuery(sb.toString(), expectedDocCount);
 
-//private static int randomDateStyle(Random random)
-//{
-//    return DATE_STYLES[random.nextInt(DATE_STYLES.length)];
-//}
+//        }
 
-//@Test
-//  public void testInclusiveNumericRange() throws Exception
-//{
-//    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);
-//}
+//        public void assertOpenRangeQuery(NumberType boundType, String @operator, int expectedDocCount)
+//        {
 
-//@Test
-//  // test disabled since standard syntax parser does not work with inclusive and
-//  // exclusive at the same time
-//  public void testInclusiveLowerNumericRange() throws Exception
-//{
-//    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);
-//}
+//            StringBuilder sb = new StringBuilder();
 
-//@Test
-//  // test disabled since standard syntax parser does not work with inclusive and
-//  // exclusive at the same time
-//  public void testInclusiveUpperNumericRange() throws Exception
-//{
-//    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);
-//}
+//            foreach (FieldType.NumericType type in Enum.GetValues(typeof(FieldType.NumericType)))
+//            {
+//                String boundStr = numberToString(getNumberType(boundType, type.ToString()));
 
-//@Test
-//  public void testExclusiveNumericRange() throws Exception
-//{
-//    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);
-//}
+//                sb.append("+").append(type.ToString()).append(@operator).append('"').append(boundStr).append('"').append('
');
+//            }
 
-//@Test
-//  public void testOpenRangeNumericQuery() throws Exception
-//{
-//    assertOpenRangeQuery(NumberType.ZERO, "<", 1);
-//    assertOpenRangeQuery(NumberType.POSITIVE, "<", 2);
-//    assertOpenRangeQuery(NumberType.NEGATIVE, "<", 0);
+//            String boundDateStr = ESCAPER.Escape(
+//                DATE_FORMAT.format(new Date(getNumberType(boundType, DATE_FIELD_NAME)
+//                    .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
 
-//    assertOpenRangeQuery(NumberType.ZERO, "<=", 2);
-//    assertOpenRangeQuery(NumberType.POSITIVE, "<=", 3);
-//    assertOpenRangeQuery(NumberType.NEGATIVE, "<=", 1);
+//            sb.append("+").append(DATE_FIELD_NAME).append(@operator).append('"').append(boundDateStr).append('"');
 
-//    assertOpenRangeQuery(NumberType.ZERO, ">", 1);
-//    assertOpenRangeQuery(NumberType.POSITIVE, ">", 0);
-//    assertOpenRangeQuery(NumberType.NEGATIVE, ">", 2);
 
-//    assertOpenRangeQuery(NumberType.ZERO, ">=", 2);
-//    assertOpenRangeQuery(NumberType.POSITIVE, ">=", 1);
-//    assertOpenRangeQuery(NumberType.NEGATIVE, ">=", 3);
+//            testQuery(sb.toString(), expectedDocCount);
+//        }
 
-//    assertOpenRangeQuery(NumberType.NEGATIVE, "=", 1);
-//    assertOpenRangeQuery(NumberType.ZERO, "=", 1);
-//    assertOpenRangeQuery(NumberType.POSITIVE, "=", 1);
+//        public void assertSimpleQuery(NumberType numberType, int expectedDocCount)
+//        {
+//            StringBuilder sb = new StringBuilder();
 
-//    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);
+//            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("\" ");
+//            }
 
-//    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);
+//            String dateStr = ESCAPER.Escape(
+//                DATE_FORMAT.format(new DateTime(getNumberType(numberType, DATE_FIELD_NAME)
+//                    .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
 
-//    assertRangeQuery(null, null, false, false, 3);
-//    assertRangeQuery(null, null, true, true, 3);
+//            sb.append('+').append(DATE_FIELD_NAME).append(":\"").append(dateStr)
+//                    .append('"');
 
-//}
 
-//@Test
-//  public void testSimpleNumericQuery() throws Exception
-//{
-//    assertSimpleQuery(NumberType.ZERO, 1);
-//    assertSimpleQuery(NumberType.POSITIVE, 1);
-//    assertSimpleQuery(NumberType.NEGATIVE, 1);
-//}
+//            testQuery(sb.toString(), expectedDocCount);
 
-//public void assertRangeQuery(NumberType lowerType, NumberType upperType,
-//    boolean lowerInclusive, boolean upperInclusive, int expectedDocCount)
-//      throws QueryNodeException, IOException {
-    
-//    StringBuilder sb = new StringBuilder();
-
-//String lowerInclusiveStr = (lowerInclusive ? "[" : "{");
-//String upperInclusiveStr = (upperInclusive ? "]" : "}");
-    
-//    for (NumericType type : NumericType.values()) {
-//      String lowerStr = numberToString(getNumberType(lowerType, type.name()));
-//String upperStr = numberToString(getNumberType(upperType, type.name()));
-
-//sb.append("+").append(type.name()).append(':').append(lowerInclusiveStr)
-//          .append('"').append(lowerStr).append("\" TO \"").append(upperStr)
-//          .append('"').append(upperInclusiveStr).append(' ');
-//    }
-    
-//    Number lowerDateNumber = getNumberType(lowerType, DATE_FIELD_NAME);
-//Number upperDateNumber = getNumberType(upperType, DATE_FIELD_NAME);
-//String lowerDateStr;
-//String upperDateStr;
-    
-//    if (lowerDateNumber != null) {
-//      lowerDateStr = ESCAPER.escape(
-//          DATE_FORMAT.format(new Date(lowerDateNumber.longValue())), LOCALE,
-//          EscapeQuerySyntax.Type.STRING).toString();
-      
-//    } else {
-//      lowerDateStr = "*";
-//    }
-    
-//    if (upperDateNumber != null) {
-//    upperDateStr = ESCAPER.escape(
-//          DATE_FORMAT.format(new Date(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);
-    
-//  }
-  
-//  public void assertOpenRangeQuery(NumberType boundType, String operator, int expectedDocCount)
-//      throws QueryNodeException, IOException {
-
-//    StringBuilder sb = new StringBuilder();
-    
-//    for (NumericType type : NumericType.values()) {
-//      String boundStr = numberToString(getNumberType(boundType, type.name()));
-
-//sb.append("+").append(type.name()).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)
-//      throws QueryNodeException, IOException {
-//    StringBuilder sb = new StringBuilder();
-    
-//    for (NumericType type : NumericType.values()) {
-//      String numberStr = numberToString(getNumberType(numberType, type.name()));
-//sb.append('+').append(type.name()).append(":\"").append(numberStr)
-//          .append("\" ");
-//    }
-    
-//    String dateStr = ESCAPER.escape(
-//        DATE_FORMAT.format(new Date(getNumberType(numberType, DATE_FIELD_NAME)
-//            .longValue())), LOCALE, EscapeQuerySyntax.Type.STRING).toString();
+//        }
 
-//sb.append('+').append(DATE_FIELD_NAME).append(":\"").append(dateStr)
-//        .append('"');
+//        [Test]
+//        private void testQuery(String queryStr, int expectedDocCount)
+//        {
+//            if (VERBOSE) Console.WriteLine("Parsing: " + queryStr);
 
+//            Query query = (Query)qp.Parse(queryStr, FIELD_NAME);
+//            if (VERBOSE) Console.WriteLine("Querying: " + query);
+//            TopDocs topDocs = searcher.Search(query, 1000);
 
-//    testQuery(sb.toString(), expectedDocCount);
-    
-//  }
-  
-//  private void testQuery(String queryStr, int expectedDocCount)
-//      throws QueryNodeException, IOException {
-//    if (VERBOSE) System.out.println("Parsing: " + queryStr);
+//            String msg = "Query <" + queryStr + "> retrieved " + topDocs.TotalHits
+//                + " document(s), " + expectedDocCount + " document(s) expected.";
 
-//Query query = qp.parse(queryStr, FIELD_NAME);
-//    if (VERBOSE) System.out.println("Querying: " + query);
-//TopDocs topDocs = searcher.search(query, 1000);
+//            if (VERBOSE) Console.WriteLine(msg);
 
-//String msg = "Query <" + queryStr + "> retrieved " + topDocs.totalHits
-//    + " document(s), " + expectedDocCount + " document(s) expected.";
-    
-//    if (VERBOSE) System.out.println(msg);
 
+//            assertEquals(msg, expectedDocCount, topDocs.TotalHits);
+//        }
 
-//    assertEquals(msg, expectedDocCount, topDocs.totalHits);
-//  }
-  
-//  private static String numberToString(Number number)
-//{
-//    return number == null ? "*" : ESCAPER.escape(NUMBER_FORMAT.format(number),
-//        LOCALE, EscapeQuerySyntax.Type.STRING).toString();
-//}
+//        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 normalizeNumber(Number number) throws ParseException
-//{
-//    return NUMBER_FORMAT.parse(NUMBER_FORMAT.format(number));
-//}
+//        private static /*Number*/ object normalizeNumber(/*Number*/ object number)
+//        {
+//            return decimal.Parse(string.Format(NUMBER_FORMAT, number));
+//            //return NUMBER_FORMAT.parse(NUMBER_FORMAT.format(number));
+//        }
 
-//@AfterClass
-//  public static void afterClass() throws Exception
-//{
-//    searcher = null;
-//    reader.close();
-//    reader = null;
-//    directory.close();
-//    directory = null;
-//    qp = null;
-//}
+//        [TestFixtureTearDown]
+//        public static void afterClass()
+//        {
+//            searcher = null;
+//            reader.Dispose();
+//            reader = null;
+//            directory.Dispose();
+//            directory = null;
+//            qp = null;
+//        }
 //    }
 //}


Mime
View raw message