示例#1
0
            internal NumericRangeTermEnum(NumericRangeQuery enclosingInstance, IndexReader reader)
            {
                InitBlock(enclosingInstance);
                this.reader = reader;

                switch (Enclosing_Instance.valSize)
                {

                    case 64:  {
                            // lower
                            long minBound = System.Int64.MinValue;
                            if (Enclosing_Instance.min is System.Int64)
                            {
                                minBound = System.Convert.ToInt64(Enclosing_Instance.min);
                            }
                            else if (Enclosing_Instance.min is System.Double)
                            {
                                minBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.min));
                            }
                            if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                            {
                                if (minBound == System.Int64.MaxValue)
                                    break;
                                minBound++;
                            }

                            // upper
                            long maxBound = System.Int64.MaxValue;
                            if (Enclosing_Instance.max is System.Int64)
                            {
                                maxBound = System.Convert.ToInt64(Enclosing_Instance.max);
                            }
                            else if (Enclosing_Instance.max is System.Double)
                            {
                                maxBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.max));
                            }
                            if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                            {
                                if (maxBound == System.Int64.MinValue)
                                    break;
                                maxBound--;
                            }

                            NumericUtils.SplitLongRange(new AnonymousClassLongRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                            break;
                        }

                    case 32:  {
                            // lower
                            int minBound = System.Int32.MinValue;
                            if (Enclosing_Instance.min is System.Int32)
                            {
                                minBound = System.Convert.ToInt32(Enclosing_Instance.min);
                            }
                            else if (Enclosing_Instance.min is System.Single)
                            {
                                minBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.min));
                            }
                            if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                            {
                                if (minBound == System.Int32.MaxValue)
                                    break;
                                minBound++;
                            }

                            // upper
                            int maxBound = System.Int32.MaxValue;
                            if (Enclosing_Instance.max is System.Int32)
                            {
                                maxBound = System.Convert.ToInt32(Enclosing_Instance.max);
                            }
                            else if (Enclosing_Instance.max is System.Single)
                            {
                                maxBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.max));
                            }
                            if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                            {
                                if (maxBound == System.Int32.MinValue)
                                    break;
                                maxBound--;
                            }

                            NumericUtils.SplitIntRange(new AnonymousClassIntRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                            break;
                        }

                    default:
                        // should never happen
                        throw new System.ArgumentException("valSize must be 32 or 64");

                }

                // seek to first term
                Next();
            }
示例#2
0
 public override Query VisitNumericRangeQuery(NumericRangeQuery numericRangeq)
 {
     var q = (NumericRangeQuery)base.VisitNumericRangeQuery(numericRangeq);
     CompileRange(q.GetField(), q.GetMin().ToString(), q.GetMax().ToString(), q.IncludesMin(), q.IncludesMax());
     return q;
 }
        public virtual void TestInfiniteValues()
        {
            Directory         dir    = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random, dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random)));
            Document          doc    = new Document();

            doc.Add(new DoubleField("double", double.NegativeInfinity, Field.Store.NO));
            doc.Add(new Int64Field("long", long.MinValue, Field.Store.NO));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new DoubleField("double", double.PositiveInfinity, Field.Store.NO));
            doc.Add(new Int64Field("long", long.MaxValue, Field.Store.NO));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new DoubleField("double", 0.0, Field.Store.NO));
            doc.Add(new Int64Field("long", 0L, Field.Store.NO));
            writer.AddDocument(doc);

            foreach (double d in TestNumericUtils.DOUBLE_NANs)
            {
                doc = new Document();
                doc.Add(new DoubleField("double", d, Field.Store.NO));
                writer.AddDocument(doc);
            }

            writer.Dispose();

            IndexReader   r = DirectoryReader.Open(dir);
            IndexSearcher s = NewSearcher(r);

            Query   q       = NumericRangeQuery.NewInt64Range("long", null, null, true, true);
            TopDocs topDocs = s.Search(q, 10);

            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewInt64Range("long", null, null, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewInt64Range("long", long.MinValue, long.MaxValue, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewInt64Range("long", long.MinValue, long.MaxValue, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(1, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewDoubleRange("double", null, null, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewDoubleRange("double", null, null, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewDoubleRange("double", double.NegativeInfinity, double.PositiveInfinity, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewDoubleRange("double", double.NegativeInfinity, double.PositiveInfinity, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(1, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewDoubleRange("double", double.NaN, double.NaN, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(TestNumericUtils.DOUBLE_NANs.Length, topDocs.ScoreDocs.Length, "Score doc count");

            r.Dispose();
            dir.Dispose();
        }
示例#4
0
            internal NumericRangeTermsEnum(NumericRangeQuery <T> outerInstance, TermsEnum tenum)
                : base(tenum)
            {
                this.outerInstance = outerInstance;
                switch (this.outerInstance.dataType)
                {
                case NumericType.INT64:
                case NumericType.DOUBLE:
                {
                    // lower
                    long minBound;
                    if (this.outerInstance.dataType == NumericType.INT64)
                    {
                        minBound = (this.outerInstance.min == null) ? long.MinValue : Convert.ToInt64(this.outerInstance.min.Value, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(this.outerInstance.dataType == NumericType.DOUBLE);
                        }
                        minBound = (this.outerInstance.min == null) ? INT64_NEGATIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.min.Value, CultureInfo.InvariantCulture));
                    }
                    if (!this.outerInstance.minInclusive && this.outerInstance.min != null)
                    {
                        if (minBound == long.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound;
                    if (this.outerInstance.dataType == NumericType.INT64)
                    {
                        maxBound = (this.outerInstance.max == null) ? long.MaxValue : Convert.ToInt64(this.outerInstance.max, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(this.outerInstance.dataType == NumericType.DOUBLE);
                        }
                        maxBound = (this.outerInstance.max == null) ? INT64_POSITIVE_INFINITY : NumericUtils.DoubleToSortableInt64(Convert.ToDouble(this.outerInstance.max, CultureInfo.InvariantCulture));
                    }
                    if (!this.outerInstance.maxInclusive && this.outerInstance.max != null)
                    {
                        if (maxBound == long.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitInt64Range(new Int64RangeBuilderAnonymousInnerClassHelper(this), this.outerInstance.precisionStep, minBound, maxBound);
                    break;
                }

                case NumericType.INT32:
                case NumericType.SINGLE:
                {
                    // lower
                    int minBound;
                    if (this.outerInstance.dataType == NumericType.INT32)
                    {
                        minBound = (this.outerInstance.min == null) ? int.MinValue : Convert.ToInt32(this.outerInstance.min, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(this.outerInstance.dataType == NumericType.SINGLE);
                        }
                        minBound = (this.outerInstance.min == null) ? INT32_NEGATIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.min, CultureInfo.InvariantCulture));
                    }
                    if (!this.outerInstance.minInclusive && this.outerInstance.min != null)
                    {
                        if (minBound == int.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound;
                    if (this.outerInstance.dataType == NumericType.INT32)
                    {
                        maxBound = (this.outerInstance.max == null) ? int.MaxValue : Convert.ToInt32(this.outerInstance.max, CultureInfo.InvariantCulture);
                    }
                    else
                    {
                        if (Debugging.AssertsEnabled)
                        {
                            Debugging.Assert(this.outerInstance.dataType == NumericType.SINGLE);
                        }
                        maxBound = (this.outerInstance.max == null) ? INT32_POSITIVE_INFINITY : NumericUtils.SingleToSortableInt32(Convert.ToSingle(this.outerInstance.max, CultureInfo.InvariantCulture));
                    }
                    if (!this.outerInstance.maxInclusive && this.outerInstance.max != null)
                    {
                        if (maxBound == int.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitInt32Range(new Int32RangeBuilderAnonymousInnerClassHelper(this), this.outerInstance.precisionStep, minBound, maxBound);
                    break;
                }

                default:
                    // should never happen
                    throw new ArgumentException("Invalid NumericType");
                }

                termComp = Comparer;
            }
        private void TestRandomTrieAndClassicRangeQuery(int precisionStep)
        {
            string field = "field" + precisionStep;
            int    totalTermCountT = 0, totalTermCountC = 0, termCountT, termCountC;
            int    num = TestUtil.NextInt(Random(), 10, 20);

            for (int i = 0; i < num; i++)
            {
                int lower = (int)(Random().NextDouble() * NoDocs * Distance) + StartOffset;
                int upper = (int)(Random().NextDouble() * NoDocs * Distance) + StartOffset;
                if (lower > upper)
                {
                    int a = lower;
                    lower = upper;
                    upper = a;
                }
                BytesRef lowerBytes = new BytesRef(NumericUtils.BUF_SIZE_INT), upperBytes = new BytesRef(NumericUtils.BUF_SIZE_INT);
                NumericUtils.IntToPrefixCodedBytes(lower, 0, lowerBytes);
                NumericUtils.IntToPrefixCodedBytes(upper, 0, upperBytes);

                // test inclusive range
                NumericRangeQuery <int> tq = NumericRangeQuery.NewIntRange(field, precisionStep, lower, upper, true, true);
                TermRangeQuery          cq = new TermRangeQuery(field, lowerBytes, upperBytes, true, true);
                TopDocs tTopDocs           = Searcher.Search(tq, 1);
                TopDocs cTopDocs           = Searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                totalTermCountT += termCountT = CountTerms(tq);
                totalTermCountC += termCountC = CountTerms(cq);
                CheckTermCounts(precisionStep, termCountT, termCountC);
                // test exclusive range
                tq       = NumericRangeQuery.NewIntRange(field, precisionStep, lower, upper, false, false);
                cq       = new TermRangeQuery(field, lowerBytes, upperBytes, false, false);
                tTopDocs = Searcher.Search(tq, 1);
                cTopDocs = Searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                totalTermCountT += termCountT = CountTerms(tq);
                totalTermCountC += termCountC = CountTerms(cq);
                CheckTermCounts(precisionStep, termCountT, termCountC);
                // test left exclusive range
                tq       = NumericRangeQuery.NewIntRange(field, precisionStep, lower, upper, false, true);
                cq       = new TermRangeQuery(field, lowerBytes, upperBytes, false, true);
                tTopDocs = Searcher.Search(tq, 1);
                cTopDocs = Searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                totalTermCountT += termCountT = CountTerms(tq);
                totalTermCountC += termCountC = CountTerms(cq);
                CheckTermCounts(precisionStep, termCountT, termCountC);
                // test right exclusive range
                tq       = NumericRangeQuery.NewIntRange(field, precisionStep, lower, upper, true, false);
                cq       = new TermRangeQuery(field, lowerBytes, upperBytes, true, false);
                tTopDocs = Searcher.Search(tq, 1);
                cTopDocs = Searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.TotalHits, tTopDocs.TotalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                totalTermCountT += termCountT = CountTerms(tq);
                totalTermCountC += termCountC = CountTerms(cq);
                CheckTermCounts(precisionStep, termCountT, termCountC);
            }

            CheckTermCounts(precisionStep, totalTermCountT, totalTermCountC);
            if (VERBOSE && precisionStep != int.MaxValue)
            {
                Console.WriteLine("Average number of terms during random search on '" + field + "':");
                Console.WriteLine(" Numeric query: " + (((double)totalTermCountT) / (num * 4)));
                Console.WriteLine(" Classical query: " + (((double)totalTermCountC) / (num * 4)));
            }
        }
示例#6
0
            internal NumericRangeTermsEnum(NumericRangeQuery <T> outerInstance, TermsEnum tenum)
                : base(tenum)
            {
                this.OuterInstance = outerInstance;
                switch (OuterInstance.DataType)
                {
                case NumericType.LONG:
                case NumericType.DOUBLE:
                {
                    // lower
                    long minBound;
                    if (OuterInstance.DataType == NumericType.LONG)
                    {
                        minBound = (OuterInstance.min == null) ? long.MinValue : Convert.ToInt64(OuterInstance.min.Value);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.DOUBLE);
                        minBound = (OuterInstance.min == null) ? LONG_NEGATIVE_INFINITY : NumericUtils.DoubleToSortableLong(Convert.ToDouble(OuterInstance.min.Value));
                    }
                    if (!OuterInstance.MinInclusive && OuterInstance.min != null)
                    {
                        if (minBound == long.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound;
                    if (OuterInstance.DataType == NumericType.LONG)
                    {
                        maxBound = (OuterInstance.max == null) ? long.MaxValue : Convert.ToInt64(OuterInstance.max);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.DOUBLE);
                        maxBound = (OuterInstance.max == null) ? LONG_POSITIVE_INFINITY : NumericUtils.DoubleToSortableLong(Convert.ToDouble(OuterInstance.max));
                    }
                    if (!OuterInstance.MaxInclusive && OuterInstance.max != null)
                    {
                        if (maxBound == long.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitLongRange(new LongRangeBuilderAnonymousInnerClassHelper(this), OuterInstance.precisionStep, minBound, maxBound);
                    break;
                }

                case NumericType.INT:
                case NumericType.FLOAT:
                {
                    // lower
                    int minBound;
                    if (OuterInstance.DataType == NumericType.INT)
                    {
                        minBound = (OuterInstance.min == null) ? int.MinValue : Convert.ToInt32(OuterInstance.min);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.FLOAT);
                        minBound = (OuterInstance.min == null) ? INT_NEGATIVE_INFINITY : NumericUtils.FloatToSortableInt(Convert.ToSingle(OuterInstance.min));
                    }
                    if (!OuterInstance.MinInclusive && OuterInstance.min != null)
                    {
                        if (minBound == int.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound;
                    if (OuterInstance.DataType == NumericType.INT)
                    {
                        maxBound = (OuterInstance.max == null) ? int.MaxValue : Convert.ToInt32(OuterInstance.max);
                    }
                    else
                    {
                        Debug.Assert(OuterInstance.DataType == NumericType.FLOAT);
                        maxBound = (OuterInstance.max == null) ? INT_POSITIVE_INFINITY : NumericUtils.FloatToSortableInt(Convert.ToSingle(OuterInstance.max));
                    }
                    if (!OuterInstance.MaxInclusive && OuterInstance.max != null)
                    {
                        if (maxBound == int.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitIntRange(new IntRangeBuilderAnonymousInnerClassHelper(this), OuterInstance.precisionStep, minBound, maxBound);
                    break;
                }

                default:
                    // should never happen
                    throw new System.ArgumentException("Invalid NumericType");
                }

                TermComp = Comparator;
            }
            internal NumericRangeTermEnum(NumericRangeQuery <T> enclosingInstance, IndexReader reader)
            {
                InitBlock(enclosingInstance);
                this.reader = reader;

                Type rangeType = Nullable.GetUnderlyingType(typeof(T?));

                switch (Enclosing_Instance.valSize)
                {
                case 64:  {
                    // lower
                    long minBound = long.MinValue;
                    if (rangeType == typeof(long))
                    {
                        // added in these checks to emulate java.  passing null give it no type (in old code),
                        // but .net can identifies it with generics and sets the bounds to 0, causing tests to fail
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = System.Convert.ToInt64(Enclosing_Instance.min);
                        }
                    }
                    else if (rangeType == typeof(double))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.min));
                        }
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == long.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound = long.MaxValue;
                    if (rangeType == typeof(long))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = System.Convert.ToInt64(Enclosing_Instance.max);
                        }
                    }
                    else if (rangeType == typeof(double))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.max));
                        }
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == long.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitLongRange(new AnonymousClassLongRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                case 32:  {
                    // lower
                    int minBound = int.MinValue;
                    if (rangeType == typeof(int))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = System.Convert.ToInt32(Enclosing_Instance.min);
                        }
                    }
                    else if (rangeType == typeof(float))
                    {
                        if (Enclosing_Instance.min != null)
                        {
                            minBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.min));
                        }
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == int.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound = int.MaxValue;
                    if (rangeType == typeof(int))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = System.Convert.ToInt32(Enclosing_Instance.max);
                        }
                    }
                    else if (rangeType == typeof(float))
                    {
                        if (Enclosing_Instance.max != null)
                        {
                            maxBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.max));
                        }
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == int.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitIntRange(new AnonymousClassIntRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                default:
                    // should never happen
                    throw new System.ArgumentException("valSize must be 32 or 64");
                }

                // seek to first term
                Next();
            }
示例#8
0
 /// <summary> Factory that creates a <code>NumericRangeFilter</code>, that filters a <code>long</code>
 /// range using the given <a href="NumericRangeQuery.html#precisionStepDesc"><code>precisionStep</code></a>.
 /// You can have half-open ranges (which are in fact &lt;/&#8804; or &gt;/&#8805; queries)
 /// by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
 /// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
 /// </summary>
 public static NumericRangeFilter NewLongRange(System.String field, int precisionStep, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
 {
     return(new NumericRangeFilter(NumericRangeQuery.NewLongRange(field, precisionStep, min, max, minInclusive, maxInclusive)));
 }
示例#9
0
 /// <summary> Factory that creates a <code>NumericRangeFilter</code>, that queries a <code>int</code>
 /// range using the default <code>precisionStep</code> {@link NumericUtils#PRECISION_STEP_DEFAULT} (4).
 /// You can have half-open ranges (which are in fact &lt;/&#8804; or &gt;/&#8805; queries)
 /// by setting the min or max value to <code>null</code>. By setting inclusive to false, it will
 /// match all documents excluding the bounds, with inclusive on, the boundaries are hits, too.
 /// </summary>
 public static NumericRangeFilter NewIntRange(System.String field, System.ValueType min, System.ValueType max, bool minInclusive, bool maxInclusive)
 {
     return(new NumericRangeFilter(NumericRangeQuery.NewIntRange(field, min, max, minInclusive, maxInclusive)));
 }
示例#10
0
		private NumericRangeFilter(NumericRangeQuery query):base(query)
		{
		}
示例#11
0
 private NumericRangeFilter(NumericRangeQuery query) : base(query)
 {
 }
示例#12
0
        public virtual void  TestEqualsAndHash()
        {
            System.Int32 tempAux  = 10;
            System.Int32 tempAux2 = 20;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test1", 4, tempAux, tempAux2, true, true));
            System.Int32 tempAux3 = 10;
            System.Int32 tempAux4 = 20;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test2", 4, tempAux3, tempAux4, false, true));
            System.Int32 tempAux5 = 10;
            System.Int32 tempAux6 = 20;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test3", 4, tempAux5, tempAux6, true, false));
            System.Int32 tempAux7 = 10;
            System.Int32 tempAux8 = 20;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test4", 4, tempAux7, tempAux8, false, false));
            //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int32 tempAux9 = 10;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test5", 4, tempAux9, null, true, true));
            //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int32 tempAux10 = 20;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test6", 4, null, tempAux10, true, true));
            //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test7", 4, null, null, true, true));
            System.Int32 tempAux11 = 10;
            System.Int32 tempAux12 = 20;
            System.Int32 tempAux13 = 10;
            System.Int32 tempAux14 = 20;
            QueryUtils.CheckEqual(NumericRangeQuery.NewIntRange("test8", 4, tempAux11, tempAux12, true, true), NumericRangeQuery.NewIntRange("test8", 4, tempAux13, tempAux14, true, true));
            System.Int32 tempAux15 = 10;
            System.Int32 tempAux16 = 20;
            System.Int32 tempAux17 = 10;
            System.Int32 tempAux18 = 20;
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test9", 4, tempAux15, tempAux16, true, true), NumericRangeQuery.NewIntRange("test9", 8, tempAux17, tempAux18, true, true));
            System.Int32 tempAux19 = 10;
            System.Int32 tempAux20 = 20;
            System.Int32 tempAux21 = 10;
            System.Int32 tempAux22 = 20;
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test10a", 4, tempAux19, tempAux20, true, true), NumericRangeQuery.NewIntRange("test10b", 4, tempAux21, tempAux22, true, true));
            System.Int32 tempAux23 = 10;
            System.Int32 tempAux24 = 20;
            System.Int32 tempAux25 = 20;
            System.Int32 tempAux26 = 10;
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test11", 4, tempAux23, tempAux24, true, true), NumericRangeQuery.NewIntRange("test11", 4, tempAux25, tempAux26, true, true));
            System.Int32 tempAux27 = 10;
            System.Int32 tempAux28 = 20;
            System.Int32 tempAux29 = 10;
            System.Int32 tempAux30 = 20;
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test12", 4, tempAux27, tempAux28, true, true), NumericRangeQuery.NewIntRange("test12", 4, tempAux29, tempAux30, false, true));
            System.Int32  tempAux31 = 10;
            System.Int32  tempAux32 = 20;
            System.Single tempAux33 = (float)10f;
            System.Single tempAux34 = (float)20f;
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test13", 4, tempAux31, tempAux32, true, true), NumericRangeQuery.NewFloatRange("test13", 4, tempAux33, tempAux34, true, true));
            // the following produces a hash collision, because Long and Integer have the same hashcode, so only test equality:
            System.Int32 tempAux35 = 10;
            System.Int32 tempAux36 = 20;
            Query        q1        = NumericRangeQuery.NewIntRange("test14", 4, tempAux35, tempAux36, true, true);

            System.Int64 tempAux37 = 10L;
            System.Int64 tempAux38 = 20L;
            Query        q2        = NumericRangeQuery.NewLongRange("test14", 4, tempAux37, tempAux38, true, true);

            Assert.IsFalse(q1.Equals(q2));
            Assert.IsFalse(q2.Equals(q1));
        }
示例#13
0
        public override Query VisitNumericRangeQuery(NumericRangeQuery numericRangeq)
        {
            var field = numericRangeq.GetField();
            var min = numericRangeq.GetMin();
            var max = numericRangeq.GetMax();
            var includesMin = numericRangeq.IncludesMin();
            var includesMax = numericRangeq.IncludesMax();
            ValueType oneValue = null;

            _text.Append(field);
            _text.Append(":");

            string op = null;
            if (min == null)
            {
                op = includesMax ? "<=" : "<";
                oneValue = max;
            }
            if (max == null)
            {
                op = includesMin ? ">=" : ">";
                oneValue = min;
            }

            if (op == null)
            {
                _text.Append(includesMin ? '[' : '{');
                _text.Append(Convert.ToString(min, CultureInfo.InvariantCulture));
                _text.Append(" TO ");
                _text.Append(Convert.ToString(max, CultureInfo.InvariantCulture));
                _text.Append(includesMax ? ']' : '}');
            }
            else
            {
                _text.Append(op).Append(oneValue);
            }

            _text.Append(BoostToString(numericRangeq.GetBoost()));

            return base.VisitNumericRangeQuery(numericRangeq);
        }
示例#14
0
        public virtual Query VisitNumericRangeQuery(NumericRangeQuery numericRangeq)
        {
            var field = numericRangeq.GetField();
            var visitedField = VisitField(field);
            if (field == visitedField)
                return numericRangeq;

            var min = numericRangeq.GetMin();
            if (min is Int32)
                return NumericRangeQuery.NewIntRange(visitedField, numericRangeq.GetMin(), numericRangeq.GetMax(), numericRangeq.IncludesMin(), numericRangeq.IncludesMax());
            if (min is Int64)
                return NumericRangeQuery.NewLongRange(visitedField, numericRangeq.GetMin(), numericRangeq.GetMax(), numericRangeq.IncludesMin(), numericRangeq.IncludesMax());
            if (min is Single)
                return NumericRangeQuery.NewFloatRange(visitedField, (Single)numericRangeq.GetMin(), (Single)numericRangeq.GetMax(), numericRangeq.IncludesMin(), numericRangeq.IncludesMax());
            if (min is Double)
                return NumericRangeQuery.NewDoubleRange(visitedField, (Double)numericRangeq.GetMin(), (Double)numericRangeq.GetMax(), numericRangeq.IncludesMin(), numericRangeq.IncludesMax());

            throw new NotImplementedException(String.Format("VisitNumericRangeQuery with {0} minvalue is not implemented.", min.GetType().Name));
        }
示例#15
0
 private void InitBlock(NumericRangeQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
示例#16
0
 private void  InitBlock(NumericRangeQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
示例#17
0
 internal NumericRangeFilter(NumericRangeQuery <T> query)
     : base(query)
 {
 }
示例#18
0
            internal NumericRangeTermEnum(NumericRangeQuery enclosingInstance, IndexReader reader)
            {
                InitBlock(enclosingInstance);
                this.reader = reader;

                switch (Enclosing_Instance.valSize)
                {
                case 64:  {
                    // lower
                    long minBound = System.Int64.MinValue;
                    if (Enclosing_Instance.min is System.Int64)
                    {
                        minBound = System.Convert.ToInt64(Enclosing_Instance.min);
                    }
                    else if (Enclosing_Instance.min is System.Double)
                    {
                        minBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.min));
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == System.Int64.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    long maxBound = System.Int64.MaxValue;
                    if (Enclosing_Instance.max is System.Int64)
                    {
                        maxBound = System.Convert.ToInt64(Enclosing_Instance.max);
                    }
                    else if (Enclosing_Instance.max is System.Double)
                    {
                        maxBound = NumericUtils.DoubleToSortableLong(System.Convert.ToDouble(Enclosing_Instance.max));
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == System.Int64.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitLongRange(new AnonymousClassLongRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                case 32:  {
                    // lower
                    int minBound = System.Int32.MinValue;
                    if (Enclosing_Instance.min is System.Int32)
                    {
                        minBound = System.Convert.ToInt32(Enclosing_Instance.min);
                    }
                    else if (Enclosing_Instance.min is System.Single)
                    {
                        minBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.min));
                    }
                    if (!Enclosing_Instance.minInclusive && Enclosing_Instance.min != null)
                    {
                        if (minBound == System.Int32.MaxValue)
                        {
                            break;
                        }
                        minBound++;
                    }

                    // upper
                    int maxBound = System.Int32.MaxValue;
                    if (Enclosing_Instance.max is System.Int32)
                    {
                        maxBound = System.Convert.ToInt32(Enclosing_Instance.max);
                    }
                    else if (Enclosing_Instance.max is System.Single)
                    {
                        maxBound = NumericUtils.FloatToSortableInt(System.Convert.ToSingle(Enclosing_Instance.max));
                    }
                    if (!Enclosing_Instance.maxInclusive && Enclosing_Instance.max != null)
                    {
                        if (maxBound == System.Int32.MinValue)
                        {
                            break;
                        }
                        maxBound--;
                    }

                    NumericUtils.SplitIntRange(new AnonymousClassIntRangeBuilder(this), Enclosing_Instance.precisionStep, minBound, maxBound);
                    break;
                }


                default:
                    // should never happen
                    throw new System.ArgumentException("valSize must be 32 or 64");
                }

                // seek to first term
                Next();
            }
 private void  InitBlock(NumericRangeQuery <T> enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
     termTemplate           = new Term(Enclosing_Instance.field);
 }
        private void  TestRandomTrieAndClassicRangeQuery(int precisionStep)
        {
            System.Random rnd = NewRandom();
            System.String field = "field" + precisionStep;
            int           termCountT = 0, termCountC = 0;

            for (int i = 0; i < 50; i++)
            {
                long lower = (long)(rnd.NextDouble() * noDocs * distance) + startOffset;
                long upper = (long)(rnd.NextDouble() * noDocs * distance) + startOffset;
                if (lower > upper)
                {
                    long a = lower; lower = upper; upper = a;
                }
                // test inclusive range
                System.Int64      tempAux  = (long)lower;
                System.Int64      tempAux2 = (long)upper;
                NumericRangeQuery tq       = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);
                TermRangeQuery    cq       = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, true);
                TopDocs           tTopDocs = searcher.Search(tq, 1);
                TopDocs           cTopDocs = searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.totalHits, tTopDocs.totalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                termCountT += tq.GetTotalNumberOfTerms();
                termCountC += cq.GetTotalNumberOfTerms();
                // test exclusive range
                System.Int64 tempAux3 = (long)lower;
                System.Int64 tempAux4 = (long)upper;
                tq       = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux3, tempAux4, false, false);
                cq       = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, false);
                tTopDocs = searcher.Search(tq, 1);
                cTopDocs = searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.totalHits, tTopDocs.totalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                termCountT += tq.GetTotalNumberOfTerms();
                termCountC += cq.GetTotalNumberOfTerms();
                // test left exclusive range
                System.Int64 tempAux5 = (long)lower;
                System.Int64 tempAux6 = (long)upper;
                tq       = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux5, tempAux6, false, true);
                cq       = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), false, true);
                tTopDocs = searcher.Search(tq, 1);
                cTopDocs = searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.totalHits, tTopDocs.totalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                termCountT += tq.GetTotalNumberOfTerms();
                termCountC += cq.GetTotalNumberOfTerms();
                // test right exclusive range
                System.Int64 tempAux7 = (long)lower;
                System.Int64 tempAux8 = (long)upper;
                tq       = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux7, tempAux8, true, false);
                cq       = new TermRangeQuery(field, NumericUtils.LongToPrefixCoded(lower), NumericUtils.LongToPrefixCoded(upper), true, false);
                tTopDocs = searcher.Search(tq, 1);
                cTopDocs = searcher.Search(cq, 1);
                Assert.AreEqual(cTopDocs.totalHits, tTopDocs.totalHits, "Returned count for NumericRangeQuery and TermRangeQuery must be equal");
                termCountT += tq.GetTotalNumberOfTerms();
                termCountC += cq.GetTotalNumberOfTerms();
            }
            if (precisionStep == System.Int32.MaxValue)
            {
                Assert.AreEqual(termCountT, termCountC, "Total number of terms should be equal for unlimited precStep");
            }
            else
            {
                System.Console.Out.WriteLine("Average number of terms during random search on '" + field + "':");
                System.Console.Out.WriteLine(" Trie query: " + (((double)termCountT) / (50 * 4)));
                System.Console.Out.WriteLine(" Classical query: " + (((double)termCountC) / (50 * 4)));
            }
        }
示例#21
0
 public virtual void TestEqualsAndHash()
 {
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test1", 4, 10L, 20L, true, true));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test2", 4, 10L, 20L, false, true));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test3", 4, 10L, 20L, true, false));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test4", 4, 10L, 20L, false, false));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test5", 4, 10L, null, true, true));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test6", 4, null, 20L, true, true));
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewInt64Range("test7", 4, null, null, true, true));
     QueryUtils.CheckEqual(NumericRangeQuery.NewInt64Range("test8", 4, 10L, 20L, true, true), NumericRangeQuery.NewInt64Range("test8", 4, 10L, 20L, true, true));
     QueryUtils.CheckUnequal(NumericRangeQuery.NewInt64Range("test9", 4, 10L, 20L, true, true), NumericRangeQuery.NewInt64Range("test9", 8, 10L, 20L, true, true));
     QueryUtils.CheckUnequal(NumericRangeQuery.NewInt64Range("test10a", 4, 10L, 20L, true, true), NumericRangeQuery.NewInt64Range("test10b", 4, 10L, 20L, true, true));
     QueryUtils.CheckUnequal(NumericRangeQuery.NewInt64Range("test11", 4, 10L, 20L, true, true), NumericRangeQuery.NewInt64Range("test11", 4, 20L, 10L, true, true));
     QueryUtils.CheckUnequal(NumericRangeQuery.NewInt64Range("test12", 4, 10L, 20L, true, true), NumericRangeQuery.NewInt64Range("test12", 4, 10L, 20L, false, true));
     QueryUtils.CheckUnequal(NumericRangeQuery.NewInt64Range("test13", 4, 10L, 20L, true, true), NumericRangeQuery.NewSingleRange("test13", 4, 10f, 20f, true, true));
     // difference to int range is tested in TestNumericRangeQuery32
 }
        /// <summary>test for constant score + boolean query + filter, the other tests only use the constant score mode </summary>
        private void  TestRange(int precisionStep)
        {
            System.String field = "field" + precisionStep;
            int           count = 3000;
            long          lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);

            System.Int64      tempAux  = (long)lower;
            System.Int64      tempAux2 = (long)upper;
            NumericRangeQuery q        = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);

            System.Int64       tempAux3 = (long)lower;
            System.Int64       tempAux4 = (long)upper;
            NumericRangeFilter f        = NumericRangeFilter.NewLongRange(field, precisionStep, tempAux3, tempAux4, true, true);
            int lastTerms = 0;

            for (sbyte i = 0; i < 3; i++)
            {
                TopDocs       topDocs;
                int           terms;
                System.String type;
                q.ClearTotalNumberOfTerms();
                f.ClearTotalNumberOfTerms();
                switch (i)
                {
                case 0:
                    type = " (constant score filter rewrite)";
                    q.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
                    topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
                    terms   = q.GetTotalNumberOfTerms();
                    break;

                case 1:
                    type = " (constant score boolean rewrite)";
                    q.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
                    topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
                    terms   = q.GetTotalNumberOfTerms();
                    break;

                case 2:
                    type    = " (filter)";
                    topDocs = searcher.Search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER);
                    terms   = f.GetTotalNumberOfTerms();
                    break;

                default:
                    return;
                }
                System.Console.Out.WriteLine("Found " + terms + " distinct terms in range for field '" + field + "'" + type + ".");
                ScoreDoc[] sd = topDocs.scoreDocs;
                Assert.IsNotNull(sd);
                Assert.AreEqual(count, sd.Length, "Score doc count" + type);
                Document doc = searcher.Doc(sd[0].doc);
                Assert.AreEqual(2 * distance + startOffset, System.Int64.Parse(doc.Get(field)), "First doc" + type);
                doc = searcher.Doc(sd[sd.Length - 1].doc);
                Assert.AreEqual((1 + count) * distance + startOffset, System.Int64.Parse(doc.Get(field)), "Last doc" + type);
                if (i > 0)
                {
                    Assert.AreEqual(lastTerms, terms, "Distinct term number is equal for all query types");
                }
                lastTerms = terms;
            }
        }
示例#23
0
        public virtual void TestInfiniteValues()
        {
            Directory         dir    = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            Document          doc    = new Document();

            doc.Add(new FloatField("float", float.NegativeInfinity, Field.Store.NO));
            doc.Add(new IntField("int", int.MinValue, Field.Store.NO));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new FloatField("float", float.PositiveInfinity, Field.Store.NO));
            doc.Add(new IntField("int", int.MaxValue, Field.Store.NO));
            writer.AddDocument(doc);

            doc = new Document();
            doc.Add(new FloatField("float", 0.0f, Field.Store.NO));
            doc.Add(new IntField("int", 0, Field.Store.NO));
            writer.AddDocument(doc);

            foreach (float f in TestNumericUtils.FLOAT_NANs)
            {
                doc = new Document();
                doc.Add(new FloatField("float", f, Field.Store.NO));
                writer.AddDocument(doc);
            }

            writer.Dispose();

            IndexReader   r = DirectoryReader.Open(dir);
            IndexSearcher s = NewSearcher(r);

            Query   q       = NumericRangeQuery.NewIntRange("int", null, null, true, true);
            TopDocs topDocs = s.Search(q, 10);

            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewIntRange("int", null, null, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewIntRange("int", int.MinValue, int.MaxValue, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewIntRange("int", int.MinValue, int.MaxValue, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(1, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewFloatRange("float", null, null, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewFloatRange("float", null, null, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewFloatRange("float", float.NegativeInfinity, float.PositiveInfinity, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(3, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewFloatRange("float", float.NegativeInfinity, float.PositiveInfinity, false, false);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(1, topDocs.ScoreDocs.Length, "Score doc count");

            q       = NumericRangeQuery.NewFloatRange("float", float.NaN, float.NaN, true, true);
            topDocs = s.Search(q, 10);
            Assert.AreEqual(TestNumericUtils.FLOAT_NANs.Length, topDocs.ScoreDocs.Length, "Score doc count");

            r.Dispose();
            dir.Dispose();
        }
 public virtual void  TestEqualsAndHash()
 {
     System.Int64 tempAux  = 10L;
     System.Int64 tempAux2 = 20L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test1", 4, tempAux, tempAux2, true, true));
     System.Int64 tempAux3 = 10L;
     System.Int64 tempAux4 = 20L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test2", 4, tempAux3, tempAux4, false, true));
     System.Int64 tempAux5 = 10L;
     System.Int64 tempAux6 = 20L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test3", 4, tempAux5, tempAux6, true, false));
     System.Int64 tempAux7 = 10L;
     System.Int64 tempAux8 = 20L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test4", 4, tempAux7, tempAux8, false, false));
     //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
     System.Int64 tempAux9 = 10L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test5", 4, tempAux9, null, true, true));
     //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
     System.Int64 tempAux10 = 20L;
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test6", 4, null, tempAux10, true, true));
     //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
     QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test7", 4, null, null, true, true));
     System.Int64 tempAux11 = 10L;
     System.Int64 tempAux12 = 20L;
     System.Int64 tempAux13 = 10L;
     System.Int64 tempAux14 = 20L;
     QueryUtils.CheckEqual(NumericRangeQuery.NewLongRange("test8", 4, tempAux11, tempAux12, true, true), NumericRangeQuery.NewLongRange("test8", 4, tempAux13, tempAux14, true, true));
     System.Int64 tempAux15 = 10L;
     System.Int64 tempAux16 = 20L;
     System.Int64 tempAux17 = 10L;
     System.Int64 tempAux18 = 20L;
     QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test9", 4, tempAux15, tempAux16, true, true), NumericRangeQuery.NewLongRange("test9", 8, tempAux17, tempAux18, true, true));
     System.Int64 tempAux19 = 10L;
     System.Int64 tempAux20 = 20L;
     System.Int64 tempAux21 = 10L;
     System.Int64 tempAux22 = 20L;
     QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test10a", 4, tempAux19, tempAux20, true, true), NumericRangeQuery.NewLongRange("test10b", 4, tempAux21, tempAux22, true, true));
     System.Int64 tempAux23 = 10L;
     System.Int64 tempAux24 = 20L;
     System.Int64 tempAux25 = 20L;
     System.Int64 tempAux26 = 10L;
     QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test11", 4, tempAux23, tempAux24, true, true), NumericRangeQuery.NewLongRange("test11", 4, tempAux25, tempAux26, true, true));
     System.Int64 tempAux27 = 10L;
     System.Int64 tempAux28 = 20L;
     System.Int64 tempAux29 = 10L;
     System.Int64 tempAux30 = 20L;
     QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test12", 4, tempAux27, tempAux28, true, true), NumericRangeQuery.NewLongRange("test12", 4, tempAux29, tempAux30, false, true));
     System.Int64  tempAux31 = 10L;
     System.Int64  tempAux32 = 20L;
     System.Single tempAux33 = (float)10f;
     System.Single tempAux34 = (float)20f;
     QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test13", 4, tempAux31, tempAux32, true, true), NumericRangeQuery.NewFloatRange("test13", 4, tempAux33, tempAux34, true, true));
     // difference to int range is tested in TestNumericRangeQuery32
 }
示例#25
0
        public virtual void TestEqualsAndHash()
        {
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test1", 4, 10, 20, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test2", 4, 10, 20, false, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test3", 4, 10, 20, true, false));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test4", 4, 10, 20, false, false));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test5", 4, 10, null, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test6", 4, null, 20, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewIntRange("test7", 4, null, null, true, true));
            QueryUtils.CheckEqual(NumericRangeQuery.NewIntRange("test8", 4, 10, 20, true, true), NumericRangeQuery.NewIntRange("test8", 4, 10, 20, true, true));
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test9", 4, 10, 20, true, true), NumericRangeQuery.NewIntRange("test9", 8, 10, 20, true, true));
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test10a", 4, 10, 20, true, true), NumericRangeQuery.NewIntRange("test10b", 4, 10, 20, true, true));
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test11", 4, 10, 20, true, true), NumericRangeQuery.NewIntRange("test11", 4, 20, 10, true, true));
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test12", 4, 10, 20, true, true), NumericRangeQuery.NewIntRange("test12", 4, 10, 20, false, true));
            QueryUtils.CheckUnequal(NumericRangeQuery.NewIntRange("test13", 4, 10, 20, true, true), NumericRangeQuery.NewFloatRange("test13", 4, 10f, 20f, true, true));
            // the following produces a hash collision, because Long and Integer have the same hashcode, so only test equality:
            Query q1 = NumericRangeQuery.NewIntRange("test14", 4, 10, 20, true, true);
            Query q2 = NumericRangeQuery.NewLongRange("test14", 4, 10L, 20L, true, true);

            Assert.IsFalse(q1.Equals(q2));
            Assert.IsFalse(q2.Equals(q1));
        }
示例#26
0
 public override Query VisitNumericRangeQuery(NumericRangeQuery numericRangeq)
 {
     var q = (NumericRangeQuery)base.VisitNumericRangeQuery(numericRangeq);
     _dump.AppendFormat("NumericRangeQ({0}:{1}{2} TO {3}{4}{5})",
         q.GetField(), q.IncludesMin() ? "[" : "{",
         q.GetMin(), q.GetMax(), q.IncludesMax() ? "]" : "}", BoostToString(q));
     return q;
 }