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));
        }
        public virtual void  TestEqualsAndHash()
        {
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test1", 4, 10L, 20L, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test2", 4, 10L, 20L, false, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test3", 4, 10L, 20L, true, false));
            System.Int64 tempAux7 = 10L;
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test4", 4, 10L, 20L, false, false));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test5", 4, 10L, null, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test6", 4, null, 20L, true, true));
            QueryUtils.CheckHashEquals(NumericRangeQuery.NewLongRange("test7", 4, null, null, true, true));
            QueryUtils.CheckEqual(NumericRangeQuery.NewLongRange("test8", 4, 10L, 20L, true, true),
                                  NumericRangeQuery.NewLongRange("test8", 4, 10L, 20L, true, true));

            QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test9", 4, 10L, 20L, true, true),
                                    NumericRangeQuery.NewLongRange("test9", 8, 10L, 20L, true, true));

            QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test10a", 4, 10L, 20L, true, true),
                                    NumericRangeQuery.NewLongRange("test10b", 4, 10L, 20L, true, true));

            QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test11", 4, 10L, 20L, true, true),
                                    NumericRangeQuery.NewLongRange("test11", 4, 20L, 10L, true, true));

            QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test12", 4, 10L, 20L, true, true),
                                    NumericRangeQuery.NewLongRange("test12", 4, 10L, 20L, false, true));

            QueryUtils.CheckUnequal(NumericRangeQuery.NewLongRange("test13", 4, 10L, 20L, true, true),
                                    NumericRangeQuery.NewFloatRange("test13", 4, 10f, 20f, true, true));
            // difference to int range is tested in TestNumericRangeQuery32
        }
        /// <summary>
        /// we fake a float test using int2float conversion of NumericUtils </summary>
        private void TestFloatRange(int precisionStep)
        {
            string    field = "ascfield" + precisionStep;
            const int lower = -1000, upper = +2000;

            Query   tq       = NumericRangeQuery.NewFloatRange(field, precisionStep, NumericUtils.SortableIntToFloat(lower), NumericUtils.SortableIntToFloat(upper), true, true);
            TopDocs tTopDocs = Searcher.Search(tq, 1);

            Assert.AreEqual(upper - lower + 1, tTopDocs.TotalHits, "Returned count of range query must be equal to inclusive range length");

            Filter tf = NumericRangeFilter.NewFloatRange(field, precisionStep, NumericUtils.SortableIntToFloat(lower), NumericUtils.SortableIntToFloat(upper), true, true);

            tTopDocs = Searcher.Search(new MatchAllDocsQuery(), tf, 1);
            Assert.AreEqual(upper - lower + 1, tTopDocs.TotalHits, "Returned count of range filter must be equal to inclusive range length");
        }
        /// <summary>we fake a float test using int2float conversion of NumericUtils </summary>
        private void  TestFloatRange(int precisionStep)
        {
            System.String field = "ascfield" + precisionStep;
            int           lower = -1000;
            int           upper = +2000;

            System.Single tempAux  = (float)NumericUtils.SortableIntToFloat(lower);
            System.Single tempAux2 = (float)NumericUtils.SortableIntToFloat(upper);
            Query         tq       = NumericRangeQuery.NewFloatRange(field, precisionStep, tempAux, tempAux2, true, true);
            TopDocs       tTopDocs = searcher.Search(tq, 1, null);

            Assert.AreEqual(upper - lower + 1, tTopDocs.TotalHits, "Returned count of range query must be equal to inclusive range length");

            System.Single tempAux3 = (float)NumericUtils.SortableIntToFloat(lower);
            System.Single tempAux4 = (float)NumericUtils.SortableIntToFloat(upper);
            Filter        tf       = NumericRangeFilter.NewFloatRange(field, precisionStep, tempAux3, tempAux4, true, true);

            tTopDocs = searcher.Search((Query) new MatchAllDocsQuery(), tf, (int)1, (IState)null);
            Assert.AreEqual(upper - lower + 1, tTopDocs.TotalHits, "Returned count of range filter must be equal to inclusive range length");
        }
        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
 }
 /// <summary> Factory that creates a <code>NumericRangeFilter</code>, that queries a <code>float</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 NewFloatRange(System.String field, System.Single min, System.Single max, bool minInclusive, bool maxInclusive)
 {
     return(new NumericRangeFilter(NumericRangeQuery.NewFloatRange(field, min, max, minInclusive, maxInclusive)));
 }
Exemple #8
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));
        }