1 package org.apache.lucene.search;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.analysis.MockAnalyzer;
21 import org.apache.lucene.document.Document;
22 import org.apache.lucene.document.Field;
23 import org.apache.lucene.document.NumericField;
24 import org.apache.lucene.index.IndexReader;
25 import org.apache.lucene.index.Term;
26 import org.apache.lucene.index.RandomIndexWriter;
27 import org.apache.lucene.store.Directory;
28 import org.apache.lucene.util.LuceneTestCase;
29 import org.apache.lucene.util.NumericUtils;
30 import org.apache.lucene.util.TestNumericUtils; // NaN arrays
31 import org.apache.lucene.util.StringHelper;
32 import org.apache.lucene.util._TestUtil;
34 import org.junit.Test;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
38 public class TestNumericRangeQuery64 extends LuceneTestCase {
39 // distance of entries
40 private static long distance;
41 // shift the starting of the values to the left, to also have negative values:
42 private static final long startOffset = - 1L << 31;
43 // number of docs to generate for testing
44 private static int noDocs;
46 private static Directory directory = null;
47 private static IndexReader reader = null;
48 private static IndexSearcher searcher = null;
51 public static void beforeClass() throws Exception {
52 noDocs = atLeast(4096);
53 distance = (1L << 60) / noDocs;
54 directory = newDirectory();
55 RandomIndexWriter writer = new RandomIndexWriter(random, directory,
56 newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random))
57 .setMaxBufferedDocs(_TestUtil.nextInt(random, 100, 1000))
58 .setMergePolicy(newLogMergePolicy()));
61 field8 = new NumericField("field8", 8, Field.Store.YES, true),
62 field6 = new NumericField("field6", 6, Field.Store.YES, true),
63 field4 = new NumericField("field4", 4, Field.Store.YES, true),
64 field2 = new NumericField("field2", 2, Field.Store.YES, true),
65 fieldNoTrie = new NumericField("field"+Integer.MAX_VALUE, Integer.MAX_VALUE, Field.Store.YES, true),
66 ascfield8 = new NumericField("ascfield8", 8, Field.Store.NO, true),
67 ascfield6 = new NumericField("ascfield6", 6, Field.Store.NO, true),
68 ascfield4 = new NumericField("ascfield4", 4, Field.Store.NO, true),
69 ascfield2 = new NumericField("ascfield2", 2, Field.Store.NO, true);
71 Document doc = new Document();
72 // add fields, that have a distance to test general functionality
73 doc.add(field8); doc.add(field6); doc.add(field4); doc.add(field2); doc.add(fieldNoTrie);
74 // add ascending fields with a distance of 1, beginning at -noDocs/2 to test the correct splitting of range and inclusive/exclusive
75 doc.add(ascfield8); doc.add(ascfield6); doc.add(ascfield4); doc.add(ascfield2);
77 // Add a series of noDocs docs with increasing long values, by updating the fields
78 for (int l=0; l<noDocs; l++) {
79 long val=distance*l+startOffset;
80 field8.setLongValue(val);
81 field6.setLongValue(val);
82 field4.setLongValue(val);
83 field2.setLongValue(val);
84 fieldNoTrie.setLongValue(val);
87 ascfield8.setLongValue(val);
88 ascfield6.setLongValue(val);
89 ascfield4.setLongValue(val);
90 ascfield2.setLongValue(val);
91 writer.addDocument(doc);
94 reader = writer.getReader();
95 searcher=newSearcher(reader);
100 public static void afterClass() throws Exception {
110 public void setUp() throws Exception {
112 // set the theoretical maximum term count for 8bit (see docs for the number)
113 // super.tearDown will restore the default
114 BooleanQuery.setMaxClauseCount(7*255*2 + 255);
117 /** test for constant score + boolean query + filter, the other tests only use the constant score mode */
118 private void testRange(int precisionStep) throws Exception {
119 String field="field"+precisionStep;
121 long lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
122 NumericRangeQuery<Long> q = NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
123 NumericRangeFilter<Long> f = NumericRangeFilter.newLongRange(field, precisionStep, lower, upper, true, true);
124 for (byte i=0; i<3; i++) {
129 type = " (constant score filter rewrite)";
130 q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
131 topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
134 type = " (constant score boolean rewrite)";
135 q.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
136 topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
140 topDocs = searcher.search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER);
145 ScoreDoc[] sd = topDocs.scoreDocs;
147 assertEquals("Score doc count"+type, count, sd.length );
148 Document doc=searcher.doc(sd[0].doc);
149 assertEquals("First doc"+type, 2*distance+startOffset, Long.parseLong(doc.get(field)) );
150 doc=searcher.doc(sd[sd.length-1].doc);
151 assertEquals("Last doc"+type, (1+count)*distance+startOffset, Long.parseLong(doc.get(field)) );
156 public void testRange_8bit() throws Exception {
161 public void testRange_6bit() throws Exception {
166 public void testRange_4bit() throws Exception {
171 public void testRange_2bit() throws Exception {
176 public void testInverseRange() throws Exception {
177 NumericRangeFilter<Long> f = NumericRangeFilter.newLongRange("field8", 8, 1000L, -1000L, true, true);
178 assertSame("A inverse range should return the EMPTY_DOCIDSET instance", DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
179 f = NumericRangeFilter.newLongRange("field8", 8, Long.MAX_VALUE, null, false, false);
180 assertSame("A exclusive range starting with Long.MAX_VALUE should return the EMPTY_DOCIDSET instance",
181 DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
182 f = NumericRangeFilter.newLongRange("field8", 8, null, Long.MIN_VALUE, false, false);
183 assertSame("A exclusive range ending with Long.MIN_VALUE should return the EMPTY_DOCIDSET instance",
184 DocIdSet.EMPTY_DOCIDSET, f.getDocIdSet(searcher.getIndexReader()));
188 public void testOneMatchQuery() throws Exception {
189 NumericRangeQuery<Long> q = NumericRangeQuery.newLongRange("ascfield8", 8, 1000L, 1000L, true, true);
190 assertSame(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE, q.getRewriteMethod());
191 TopDocs topDocs = searcher.search(q, noDocs);
192 ScoreDoc[] sd = topDocs.scoreDocs;
194 assertEquals("Score doc count", 1, sd.length );
197 private void testLeftOpenRange(int precisionStep) throws Exception {
198 String field="field"+precisionStep;
200 long upper=(count-1)*distance + (distance/3) + startOffset;
201 NumericRangeQuery<Long> q=NumericRangeQuery.newLongRange(field, precisionStep, null, upper, true, true);
202 TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
203 ScoreDoc[] sd = topDocs.scoreDocs;
205 assertEquals("Score doc count", count, sd.length );
206 Document doc=searcher.doc(sd[0].doc);
207 assertEquals("First doc", startOffset, Long.parseLong(doc.get(field)) );
208 doc=searcher.doc(sd[sd.length-1].doc);
209 assertEquals("Last doc", (count-1)*distance+startOffset, Long.parseLong(doc.get(field)) );
211 q=NumericRangeQuery.newLongRange(field, precisionStep, null, upper, false, true);
212 topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
213 sd = topDocs.scoreDocs;
215 assertEquals("Score doc count", count, sd.length );
216 doc=searcher.doc(sd[0].doc);
217 assertEquals("First doc", startOffset, Long.parseLong(doc.get(field)) );
218 doc=searcher.doc(sd[sd.length-1].doc);
219 assertEquals("Last doc", (count-1)*distance+startOffset, Long.parseLong(doc.get(field)) );
223 public void testLeftOpenRange_8bit() throws Exception {
224 testLeftOpenRange(8);
228 public void testLeftOpenRange_6bit() throws Exception {
229 testLeftOpenRange(6);
233 public void testLeftOpenRange_4bit() throws Exception {
234 testLeftOpenRange(4);
238 public void testLeftOpenRange_2bit() throws Exception {
239 testLeftOpenRange(2);
242 private void testRightOpenRange(int precisionStep) throws Exception {
243 String field="field"+precisionStep;
245 long lower=(count-1)*distance + (distance/3) +startOffset;
246 NumericRangeQuery<Long> q=NumericRangeQuery.newLongRange(field, precisionStep, lower, null, true, true);
247 TopDocs topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
248 ScoreDoc[] sd = topDocs.scoreDocs;
250 assertEquals("Score doc count", noDocs-count, sd.length );
251 Document doc=searcher.doc(sd[0].doc);
252 assertEquals("First doc", count*distance+startOffset, Long.parseLong(doc.get(field)) );
253 doc=searcher.doc(sd[sd.length-1].doc);
254 assertEquals("Last doc", (noDocs-1)*distance+startOffset, Long.parseLong(doc.get(field)) );
256 q=NumericRangeQuery.newLongRange(field, precisionStep, lower, null, true, false);
257 topDocs = searcher.search(q, null, noDocs, Sort.INDEXORDER);
258 sd = topDocs.scoreDocs;
260 assertEquals("Score doc count", noDocs-count, sd.length );
261 doc=searcher.doc(sd[0].doc);
262 assertEquals("First doc", count*distance+startOffset, Long.parseLong(doc.get(field)) );
263 doc=searcher.doc(sd[sd.length-1].doc);
264 assertEquals("Last doc", (noDocs-1)*distance+startOffset, Long.parseLong(doc.get(field)) );
268 public void testRightOpenRange_8bit() throws Exception {
269 testRightOpenRange(8);
273 public void testRightOpenRange_6bit() throws Exception {
274 testRightOpenRange(6);
278 public void testRightOpenRange_4bit() throws Exception {
279 testRightOpenRange(4);
283 public void testRightOpenRange_2bit() throws Exception {
284 testRightOpenRange(2);
288 public void testInfiniteValues() throws Exception {
289 Directory dir = newDirectory();
290 RandomIndexWriter writer = new RandomIndexWriter(random, dir,
291 newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)));
292 Document doc = new Document();
293 doc.add(new NumericField("double").setDoubleValue(Double.NEGATIVE_INFINITY));
294 doc.add(new NumericField("long").setLongValue(Long.MIN_VALUE));
295 writer.addDocument(doc);
297 doc = new Document();
298 doc.add(new NumericField("double").setDoubleValue(Double.POSITIVE_INFINITY));
299 doc.add(new NumericField("long").setLongValue(Long.MAX_VALUE));
300 writer.addDocument(doc);
302 doc = new Document();
303 doc.add(new NumericField("double").setDoubleValue(0.0));
304 doc.add(new NumericField("long").setLongValue(0L));
305 writer.addDocument(doc);
307 for (double d : TestNumericUtils.DOUBLE_NANs) {
308 doc = new Document();
309 doc.add(new NumericField("double").setDoubleValue(d));
310 writer.addDocument(doc);
315 IndexReader r = IndexReader.open(dir);
316 IndexSearcher s = new IndexSearcher(r);
318 Query q=NumericRangeQuery.newLongRange("long", null, null, true, true);
319 TopDocs topDocs = s.search(q, 10);
320 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
322 q=NumericRangeQuery.newLongRange("long", null, null, false, false);
323 topDocs = s.search(q, 10);
324 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
326 q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, true, true);
327 topDocs = s.search(q, 10);
328 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
330 q=NumericRangeQuery.newLongRange("long", Long.MIN_VALUE, Long.MAX_VALUE, false, false);
331 topDocs = s.search(q, 10);
332 assertEquals("Score doc count", 1, topDocs.scoreDocs.length );
334 q=NumericRangeQuery.newDoubleRange("double", null, null, true, true);
335 topDocs = s.search(q, 10);
336 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
338 q=NumericRangeQuery.newDoubleRange("double", null, null, false, false);
339 topDocs = s.search(q, 10);
340 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
342 q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, true, true);
343 topDocs = s.search(q, 10);
344 assertEquals("Score doc count", 3, topDocs.scoreDocs.length );
346 q=NumericRangeQuery.newDoubleRange("double", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, false, false);
347 topDocs = s.search(q, 10);
348 assertEquals("Score doc count", 1, topDocs.scoreDocs.length );
350 q=NumericRangeQuery.newDoubleRange("double", Double.NaN, Double.NaN, true, true);
351 topDocs = s.search(q, 10);
352 assertEquals("Score doc count", TestNumericUtils.DOUBLE_NANs.length, topDocs.scoreDocs.length );
359 private void testRandomTrieAndClassicRangeQuery(int precisionStep) throws Exception {
360 final String field=StringHelper.intern("field"+precisionStep);
361 int totalTermCountT=0,totalTermCountC=0,termCountT,termCountC;
362 int num = _TestUtil.nextInt(random, 10, 20);
363 for (int i = 0; i < num; i++) {
364 long lower=(long)(random.nextDouble()*noDocs*distance)+startOffset;
365 long upper=(long)(random.nextDouble()*noDocs*distance)+startOffset;
367 long a=lower; lower=upper; upper=a;
369 // test inclusive range
370 NumericRangeQuery<Long> tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
371 TermRangeQuery cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, true);
372 TopDocs tTopDocs = searcher.search(tq, 1);
373 TopDocs cTopDocs = searcher.search(cq, 1);
374 assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
375 totalTermCountT += termCountT = countTerms(tq, field);
376 totalTermCountC += termCountC = countTerms(cq, field);
377 checkTermCounts(precisionStep, termCountT, termCountC);
378 // test exclusive range
379 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false);
380 cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, false);
381 tTopDocs = searcher.search(tq, 1);
382 cTopDocs = searcher.search(cq, 1);
383 assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
384 totalTermCountT += termCountT = countTerms(tq, field);
385 totalTermCountC += termCountC = countTerms(cq, field);
386 checkTermCounts(precisionStep, termCountT, termCountC);
387 // test left exclusive range
388 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true);
389 cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), false, true);
390 tTopDocs = searcher.search(tq, 1);
391 cTopDocs = searcher.search(cq, 1);
392 assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
393 totalTermCountT += termCountT = countTerms(tq, field);
394 totalTermCountC += termCountC = countTerms(cq, field);
395 checkTermCounts(precisionStep, termCountT, termCountC);
396 // test right exclusive range
397 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false);
398 cq=new TermRangeQuery(field, NumericUtils.longToPrefixCoded(lower), NumericUtils.longToPrefixCoded(upper), true, false);
399 tTopDocs = searcher.search(tq, 1);
400 cTopDocs = searcher.search(cq, 1);
401 assertEquals("Returned count for NumericRangeQuery and TermRangeQuery must be equal", cTopDocs.totalHits, tTopDocs.totalHits );
402 totalTermCountT += termCountT = countTerms(tq, field);
403 totalTermCountC += termCountC = countTerms(cq, field);
404 checkTermCounts(precisionStep, termCountT, termCountC);
407 checkTermCounts(precisionStep, totalTermCountT, totalTermCountC);
408 if (VERBOSE && precisionStep != Integer.MAX_VALUE) {
409 System.out.println("Average number of terms during random search on '" + field + "':");
410 System.out.println(" Numeric query: " + (((double)totalTermCountT)/(num * 4)));
411 System.out.println(" Classical query: " + (((double)totalTermCountC)/(num * 4)));
416 public void testEmptyEnums() throws Exception {
418 long lower=(distance*3/2)+startOffset, upper=lower + count*distance + (distance/3);
420 assert lower < upper;
421 assertTrue(0 < countTerms(NumericRangeQuery.newLongRange("field4", 4, lower, upper, true, true), "field4"));
422 assertEquals(0, countTerms(NumericRangeQuery.newLongRange("field4", 4, upper, lower, true, true), "field4"));
423 // test empty enum outside of bounds
424 lower = distance*noDocs+startOffset;
426 assert lower < upper;
427 assertEquals(0, countTerms(NumericRangeQuery.newLongRange("field4", 4, lower, upper, true, true), "field4"));
430 private int countTerms(MultiTermQuery q, String field) throws Exception {
431 FilteredTermEnum termEnum = q.getEnum(reader);
436 final Term cur = termEnum.term();
439 assertSame(field, cur.field());
441 assertTrue(last.text().compareTo(cur.text()) < 0);
445 } while (termEnum.next());
446 assertFalse(termEnum.next());
453 private void checkTermCounts(int precisionStep, int termCountT, int termCountC) {
454 if (precisionStep == Integer.MAX_VALUE) {
455 assertEquals("Number of terms should be equal for unlimited precStep", termCountC, termCountT);
457 assertTrue("Number of terms for NRQ should be <= compared to classical TRQ", termCountT <= termCountC);
462 public void testRandomTrieAndClassicRangeQuery_8bit() throws Exception {
463 testRandomTrieAndClassicRangeQuery(8);
467 public void testRandomTrieAndClassicRangeQuery_6bit() throws Exception {
468 testRandomTrieAndClassicRangeQuery(6);
472 public void testRandomTrieAndClassicRangeQuery_4bit() throws Exception {
473 testRandomTrieAndClassicRangeQuery(4);
477 public void testRandomTrieAndClassicRangeQuery_2bit() throws Exception {
478 testRandomTrieAndClassicRangeQuery(2);
482 public void testRandomTrieAndClassicRangeQuery_NoTrie() throws Exception {
483 testRandomTrieAndClassicRangeQuery(Integer.MAX_VALUE);
486 private void testRangeSplit(int precisionStep) throws Exception {
487 String field="ascfield"+precisionStep;
489 int num = _TestUtil.nextInt(random, 10, 20);
490 for (int i = 0; i < num; i++) {
491 long lower=(long)(random.nextDouble()*noDocs - noDocs/2);
492 long upper=(long)(random.nextDouble()*noDocs - noDocs/2);
494 long a=lower; lower=upper; upper=a;
496 // test inclusive range
497 Query tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
498 TopDocs tTopDocs = searcher.search(tq, 1);
499 assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits );
500 // test exclusive range
501 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, false);
502 tTopDocs = searcher.search(tq, 1);
503 assertEquals("Returned count of range query must be equal to exclusive range length", Math.max(upper-lower-1, 0), tTopDocs.totalHits );
504 // test left exclusive range
505 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, false, true);
506 tTopDocs = searcher.search(tq, 1);
507 assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits );
508 // test right exclusive range
509 tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, false);
510 tTopDocs = searcher.search(tq, 1);
511 assertEquals("Returned count of range query must be equal to half exclusive range length", upper-lower, tTopDocs.totalHits );
516 public void testRangeSplit_8bit() throws Exception {
521 public void testRangeSplit_6bit() throws Exception {
526 public void testRangeSplit_4bit() throws Exception {
531 public void testRangeSplit_2bit() throws Exception {
535 /** we fake a double test using long2double conversion of NumericUtils */
536 private void testDoubleRange(int precisionStep) throws Exception {
537 final String field="ascfield"+precisionStep;
538 final long lower=-1000L, upper=+2000L;
540 Query tq=NumericRangeQuery.newDoubleRange(field, precisionStep,
541 NumericUtils.sortableLongToDouble(lower), NumericUtils.sortableLongToDouble(upper), true, true);
542 TopDocs tTopDocs = searcher.search(tq, 1);
543 assertEquals("Returned count of range query must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits );
545 Filter tf=NumericRangeFilter.newDoubleRange(field, precisionStep,
546 NumericUtils.sortableLongToDouble(lower), NumericUtils.sortableLongToDouble(upper), true, true);
547 tTopDocs = searcher.search(new MatchAllDocsQuery(), tf, 1);
548 assertEquals("Returned count of range filter must be equal to inclusive range length", upper-lower+1, tTopDocs.totalHits );
552 public void testDoubleRange_8bit() throws Exception {
557 public void testDoubleRange_6bit() throws Exception {
562 public void testDoubleRange_4bit() throws Exception {
567 public void testDoubleRange_2bit() throws Exception {
571 private void testSorting(int precisionStep) throws Exception {
572 String field="field"+precisionStep;
573 // 10 random tests, the index order is ascending,
574 // so using a reverse sort field should retun descending documents
575 int num = _TestUtil.nextInt(random, 10, 20);
576 for (int i = 0; i < num; i++) {
577 long lower=(long)(random.nextDouble()*noDocs*distance)+startOffset;
578 long upper=(long)(random.nextDouble()*noDocs*distance)+startOffset;
580 long a=lower; lower=upper; upper=a;
582 Query tq=NumericRangeQuery.newLongRange(field, precisionStep, lower, upper, true, true);
583 TopDocs topDocs = searcher.search(tq, null, noDocs, new Sort(new SortField(field, SortField.LONG, true)));
584 if (topDocs.totalHits==0) continue;
585 ScoreDoc[] sd = topDocs.scoreDocs;
587 long last=Long.parseLong(searcher.doc(sd[0].doc).get(field));
588 for (int j=1; j<sd.length; j++) {
589 long act=Long.parseLong(searcher.doc(sd[j].doc).get(field));
590 assertTrue("Docs should be sorted backwards", last>act );
597 public void testSorting_8bit() throws Exception {
602 public void testSorting_6bit() throws Exception {
607 public void testSorting_4bit() throws Exception {
612 public void testSorting_2bit() throws Exception {
617 public void testEqualsAndHash() throws Exception {
618 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test1", 4, 10L, 20L, true, true));
619 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test2", 4, 10L, 20L, false, true));
620 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test3", 4, 10L, 20L, true, false));
621 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test4", 4, 10L, 20L, false, false));
622 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test5", 4, 10L, null, true, true));
623 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test6", 4, null, 20L, true, true));
624 QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test7", 4, null, null, true, true));
625 QueryUtils.checkEqual(
626 NumericRangeQuery.newLongRange("test8", 4, 10L, 20L, true, true),
627 NumericRangeQuery.newLongRange("test8", 4, 10L, 20L, true, true)
629 QueryUtils.checkUnequal(
630 NumericRangeQuery.newLongRange("test9", 4, 10L, 20L, true, true),
631 NumericRangeQuery.newLongRange("test9", 8, 10L, 20L, true, true)
633 QueryUtils.checkUnequal(
634 NumericRangeQuery.newLongRange("test10a", 4, 10L, 20L, true, true),
635 NumericRangeQuery.newLongRange("test10b", 4, 10L, 20L, true, true)
637 QueryUtils.checkUnequal(
638 NumericRangeQuery.newLongRange("test11", 4, 10L, 20L, true, true),
639 NumericRangeQuery.newLongRange("test11", 4, 20L, 10L, true, true)
641 QueryUtils.checkUnequal(
642 NumericRangeQuery.newLongRange("test12", 4, 10L, 20L, true, true),
643 NumericRangeQuery.newLongRange("test12", 4, 10L, 20L, false, true)
645 QueryUtils.checkUnequal(
646 NumericRangeQuery.newLongRange("test13", 4, 10L, 20L, true, true),
647 NumericRangeQuery.newFloatRange("test13", 4, 10f, 20f, true, true)
649 // difference to int range is tested in TestNumericRangeQuery32