/** we fake a double test using long2double conversion of LegacyNumericUtils */ private void testDoubleRange(int precisionStep) throws Exception { final String field = "ascfield" + precisionStep; final long lower = -1000L, upper = +2000L; Query tq = LegacyNumericRangeQuery.newDoubleRange( field, precisionStep, NumericUtils.sortableLongToDouble(lower), NumericUtils.sortableLongToDouble(upper), true, true); TopDocs tTopDocs = searcher.search(tq, 1); assertEquals( "Returned count of range query must be equal to inclusive range length", upper - lower + 1, tTopDocs.totalHits); }
@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 LegacyDoubleField("double", Double.NEGATIVE_INFINITY, Field.Store.NO)); doc.add(new LegacyLongField("long", Long.MIN_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyDoubleField("double", Double.POSITIVE_INFINITY, Field.Store.NO)); doc.add(new LegacyLongField("long", Long.MAX_VALUE, Field.Store.NO)); writer.addDocument(doc); doc = new Document(); doc.add(new LegacyDoubleField("double", 0.0, Field.Store.NO)); doc.add(new LegacyLongField("long", 0L, Field.Store.NO)); writer.addDocument(doc); for (double d : TestLegacyNumericUtils.DOUBLE_NANs) { doc = new Document(); doc.add(new LegacyDoubleField("double", d, Field.Store.NO)); writer.addDocument(doc); } writer.close(); IndexReader r = DirectoryReader.open(dir); IndexSearcher s = newSearcher(r); Query q = LegacyNumericRangeQuery.newLongRange("long", null, null, true, true); TopDocs topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newLongRange("long", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newDoubleRange("double", null, null, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newDoubleRange("double", null, null, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newDoubleRange( "double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true, true); topDocs = s.search(q, 10); assertEquals("Score doc count", 3, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newDoubleRange( "double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false); topDocs = s.search(q, 10); assertEquals("Score doc count", 1, topDocs.scoreDocs.length); q = LegacyNumericRangeQuery.newDoubleRange("double", Double.NaN, Double.NaN, true, true); topDocs = s.search(q, 10); assertEquals( "Score doc count", TestLegacyNumericUtils.DOUBLE_NANs.length, topDocs.scoreDocs.length); r.close(); dir.close(); }