public virtual void TestFieldCacheRangeFilterFloats() { IndexReader reader = IndexReader.Open((Directory)signedIndex.index, true, null); IndexSearcher Search = new IndexSearcher(reader); int numDocs = reader.NumDocs(); System.Single minIdO = (float)(minId + .5f); System.Single medIdO = (float)((float)minIdO + ((float)(maxId - minId)) / 2.0f); ScoreDoc[] result; Query q = new TermQuery(new Term("body", "body")); result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", minIdO, medIdO, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs / 2, result.Length, "find all"); int count = 0; result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, medIdO, F, T), numDocs, null).ScoreDocs; count += result.Length; result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", medIdO, null, F, F), numDocs, null).ScoreDocs; count += result.Length; Assert.AreEqual(numDocs, count, "sum of two concenatted ranges"); result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, null, T, T), numDocs, null).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); System.Single tempAux = (float)System.Single.PositiveInfinity; result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", tempAux, null, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "infinity special case"); System.Single tempAux2 = (float)System.Single.NegativeInfinity; result = Search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, tempAux2, F, F), numDocs, null).ScoreDocs; Assert.AreEqual(0, result.Length, "infinity special case"); }
public virtual void TestFieldCacheRangeFilterFloats() { IndexReader reader = SignedIndexReader; IndexSearcher search = NewSearcher(reader); int numDocs = reader.NumDocs; float?minIdO = Convert.ToSingle(MinId + .5f); float?medIdO = Convert.ToSingle((float)minIdO + ((MaxId - MinId)) / 2.0f); ScoreDoc[] result; Query q = new TermQuery(new Term("body", "body")); result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", minIdO, medIdO, T, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs / 2, result.Length, "find all"); int count = 0; result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, medIdO, F, T), numDocs).ScoreDocs; count += result.Length; result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", medIdO, null, F, F), numDocs).ScoreDocs; count += result.Length; Assert.AreEqual(numDocs, count, "sum of two concenatted ranges"); result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, null, T, T), numDocs).ScoreDocs; Assert.AreEqual(numDocs, result.Length, "find all"); result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", Convert.ToSingle(float.PositiveInfinity), null, F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "infinity special case"); result = search.Search(q, FieldCacheRangeFilter.NewFloatRange("id", null, Convert.ToSingle(float.NegativeInfinity), F, F), numDocs).ScoreDocs; Assert.AreEqual(0, result.Length, "infinity special case"); }