mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
076fb9b323
commit
854cae6c35
|
@ -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. */
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue