@Test public void testInfiniteValues() throws Exception { Directory dir = newDirectory(); RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc = new Document(); doc.add(new FloatField("float", Float.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatField("float", Float.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MAX_VALUE, 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); for (float f : TestNumericUtils.FLOAT_NANs) { doc = new Document(); doc.add(new FloatField("float", f, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); Query q=NumericRangeQuery.newIntRange("int", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NaN, Float.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.FLOAT_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }
@Test public void testInfiniteValues() throws Exception { Directory dir = newDirectory(); RandomIndexWriter writer = new RandomIndexWriter(random(), dir, newIndexWriterConfig(new MockAnalyzer(random()))); Document doc = new Document(); doc.add(new DoubleField("double", Double.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", Double.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MAX_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", 0.0, Field.Store.NO)); doc.add(new LongField("long", 0L, Field.Store.NO)); writer.addDocument(doc); for (double d : TestNumericUtils.DOUBLE_NANs) { doc = new Document(); doc.add(new DoubleField("double", d, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); Query q=NumericRangeQuery.newLongRange("long", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NaN, Double.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.DOUBLE_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }
@Test public void testInfiniteValues() throws Exception { 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.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatField("float", Float.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MAX_VALUE, 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); for (float f : TestNumericUtils.FLOAT_NANs) { doc = new Document(); doc.add(new FloatField("float", f, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = new IndexSearcher(r); Query q=NumericRangeQuery.newIntRange("int", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NaN, Float.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.FLOAT_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }
@Test public void testInfiniteValues() throws Exception { 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.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", Double.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MAX_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", 0.0, Field.Store.NO)); doc.add(new LongField("long", 0L, Field.Store.NO)); writer.addDocument(doc); for (double d : TestNumericUtils.DOUBLE_NANs) { doc = new Document(); doc.add(new DoubleField("double", d, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = new IndexSearcher(r); Query q=NumericRangeQuery.newLongRange("long", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NaN, Double.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.DOUBLE_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }
@Test public void testInfiniteValues() throws Exception { 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.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new FloatField("float", Float.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new IntField("int", Integer.MAX_VALUE, 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); for (float f : TestNumericUtils.FLOAT_NANs) { doc = new Document(); doc.add(new FloatField("float", f, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); Query q=NumericRangeQuery.newIntRange("int", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newIntRange("int", Integer.MIN_VALUE, Integer.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newFloatRange("float", Float.NaN, Float.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.FLOAT_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }
@Test public void testInfiniteValues() throws Exception { 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.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", Double.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new LongField("long", Long.MAX_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("double", 0.0, Field.Store.NO)); doc.add(new LongField("long", 0L, Field.Store.NO)); writer.addDocument(doc); for (double d : TestNumericUtils.DOUBLE_NANs) { doc = new Document(); doc.add(new DoubleField("double", d, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); Query q=NumericRangeQuery.newLongRange("long", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length ); q=NumericRangeQuery.newDoubleRange("double", Double.NaN, Double.NaN, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", TestNumericUtils.DOUBLE_NANs.length, topDocs.scoreDocs.length ); r.close(); dir.close(); }