Revert revision 788295 (reenable support for null as both ends in NumericRangeQuery) and add support for this in FieldCacheRangeFilter, too. See discussion in SOLR-940.

The strange handling of null terms (which lead me to the change) in RangeQuery will be fixed together with LUCENE-1713.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@789692 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-06-30 12:27:50 +00:00
parent 9995a84698
commit 5fd0be7226
5 changed files with 18 additions and 4 deletions

View File

@ -61,8 +61,6 @@ public abstract class FieldCacheRangeFilter extends Filter {
final boolean includeUpper;
private FieldCacheRangeFilter(String field, FieldCache.Parser parser, Object lowerVal, Object upperVal, boolean includeLower, boolean includeUpper) {
if (lowerVal == null && upperVal == null)
throw new IllegalArgumentException("At least one value must be non-null");
this.field = field;
this.parser = parser;
this.lowerVal = lowerVal;

View File

@ -127,8 +127,6 @@ public final class NumericRangeQuery extends MultiTermQuery {
Number min, Number max, final boolean minInclusive, final boolean maxInclusive
) {
assert (valSize == 32 || valSize == 64);
if (min == null && max == null)
throw new IllegalArgumentException("At least one value must be non-null");
if (precisionStep < 1 || precisionStep > valSize)
throw new IllegalArgumentException("precisionStep may only be 1.."+valSize);
this.field = field.intern();

View File

@ -87,6 +87,9 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
// unbounded id
result = search.search(q,FieldCacheRangeFilter.newStringRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newStringRange("id",minIP,null,T,F), numDocs).scoreDocs;
assertEquals("min and up", numDocs, result.length);
@ -230,6 +233,9 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
// unbounded id
result = search.search(q,FieldCacheRangeFilter.newShortRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newShortRange("id",minIdO,null,T,F), numDocs).scoreDocs;
assertEquals("min and up", numDocs, result.length);
@ -317,6 +323,9 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
// unbounded id
result = search.search(q,FieldCacheRangeFilter.newIntRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newIntRange("id",minIdO,null,T,F), numDocs).scoreDocs;
assertEquals("min and up", numDocs, result.length);
@ -404,6 +413,9 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
// unbounded id
result = search.search(q,FieldCacheRangeFilter.newLongRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newLongRange("id",minIdO,null,T,F), numDocs).scoreDocs;
assertEquals("min and up", numDocs, result.length);
@ -475,6 +487,8 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
result = search.search(q,FieldCacheRangeFilter.newFloatRange("id",medIdO,null,F,F), numDocs).scoreDocs;
count += result.length;
assertEquals("sum of two concenatted ranges", numDocs, count);
result = search.search(q,FieldCacheRangeFilter.newFloatRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newFloatRange("id",new Float(Float.POSITIVE_INFINITY),null,F,F), numDocs).scoreDocs;
assertEquals("infinity special case", 0, result.length);
result = search.search(q,FieldCacheRangeFilter.newFloatRange("id",null,new Float(Float.NEGATIVE_INFINITY),F,F), numDocs).scoreDocs;
@ -501,6 +515,8 @@ public class TestFieldCacheRangeFilter extends BaseTestRangeFilter {
result = search.search(q,FieldCacheRangeFilter.newDoubleRange("id",medIdO,null,F,F), numDocs).scoreDocs;
count += result.length;
assertEquals("sum of two concenatted ranges", numDocs, count);
result = search.search(q,FieldCacheRangeFilter.newDoubleRange("id",null,null,T,T), numDocs).scoreDocs;
assertEquals("find all", numDocs, result.length);
result = search.search(q,FieldCacheRangeFilter.newDoubleRange("id",new Double(Double.POSITIVE_INFINITY),null,F,F), numDocs).scoreDocs;
assertEquals("infinity special case", 0, result.length);
result = search.search(q,FieldCacheRangeFilter.newDoubleRange("id",null, new Double(Double.NEGATIVE_INFINITY),F,F), numDocs).scoreDocs;

View File

@ -391,6 +391,7 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
QueryUtils.checkHashEquals(NumericRangeQuery.newIntRange("test4", 4, new Integer(10), new Integer(20), false, false));
QueryUtils.checkHashEquals(NumericRangeQuery.newIntRange("test5", 4, new Integer(10), null, true, true));
QueryUtils.checkHashEquals(NumericRangeQuery.newIntRange("test6", 4, null, new Integer(20), true, true));
QueryUtils.checkHashEquals(NumericRangeQuery.newIntRange("test7", 4, null, null, true, true));
QueryUtils.checkEqual(
NumericRangeQuery.newIntRange("test8", 4, new Integer(10), new Integer(20), true, true),
NumericRangeQuery.newIntRange("test8", 4, new Integer(10), new Integer(20), true, true)

View File

@ -391,6 +391,7 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test4", 4, new Long(10L), new Long(20L), false, false));
QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test5", 4, new Long(10L), null, true, true));
QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test6", 4, null, new Long(20L), true, true));
QueryUtils.checkHashEquals(NumericRangeQuery.newLongRange("test7", 4, null, null, true, true));
QueryUtils.checkEqual(
NumericRangeQuery.newLongRange("test8", 4, new Long(10L), new Long(20L), true, true),
NumericRangeQuery.newLongRange("test8", 4, new Long(10L), new Long(20L), true, true)