From 854cae6c3590356d01e6f9023caba1855ba96dfb Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Thu, 13 Nov 2008 09:31:20 +0000 Subject: [PATCH] LUCENE-1424: correctly handle null lower or upper term in RangeQuery.getEnum git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@713687 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/search/RangeQuery.java | 5 +++-- .../apache/lucene/search/TestRangeQuery.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/lucene/search/RangeQuery.java b/src/java/org/apache/lucene/search/RangeQuery.java index 4a55b5b8456..877f0af62eb 100644 --- a/src/java/org/apache/lucene/search/RangeQuery.java +++ b/src/java/org/apache/lucene/search/RangeQuery.java @@ -171,8 +171,9 @@ public class RangeQuery extends MultiTermQuery { public Collator getCollator() { return collator; } protected FilteredTermEnum getEnum(IndexReader reader) throws IOException { - return new RangeTermEnum(reader, collator, getField(), lowerTerm.text(), - upperTerm.text(), includeLower, includeUpper); + //TODO: when the deprecated 'Term' constructors are removed we can remove these null checks + return new RangeTermEnum(reader, collator, getField(), lowerTerm == null ? null : lowerTerm.text(), + upperTerm == null ? null : upperTerm.text(), includeLower, includeUpper); } /** Prints a user-readable version of this query. */ diff --git a/src/test/org/apache/lucene/search/TestRangeQuery.java b/src/test/org/apache/lucene/search/TestRangeQuery.java index e4194b0ad45..974a0630410 100644 --- a/src/test/org/apache/lucene/search/TestRangeQuery.java +++ b/src/test/org/apache/lucene/search/TestRangeQuery.java @@ -21,6 +21,7 @@ import org.apache.lucene.analysis.WhitespaceAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.Term; import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.LuceneTestCase; @@ -59,6 +60,23 @@ public class TestRangeQuery extends LuceneTestCase { assertEquals("C added, still only B in range", 1, hits.length); searcher.close(); } + + //TODO: remove in Lucene 3.0 + public void testDeprecatedCstrctors() throws IOException { + Query query = new RangeQuery(null, new Term("content","C"), false); + initializeIndex(new String[] {"A", "B", "C", "D"}); + IndexSearcher searcher = new IndexSearcher(dir); + ScoreDoc[] hits = searcher.search(query, null, 1000).scoreDocs; + assertEquals("A,B,C,D, only B in range", 2, hits.length); + searcher.close(); + + query = new RangeQuery(new Term("content","C"),null, false); + initializeIndex(new String[] {"A", "B", "C", "D"}); + searcher = new IndexSearcher(dir); + hits = searcher.search(query, null, 1000).scoreDocs; + assertEquals("A,B,C,D, only B in range", 1, hits.length); + searcher.close(); + } public void testInclusive() throws Exception { Query query = new RangeQuery("content", "A", "C", true, true);