lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r713687 - in /lucene/java/trunk/src: java/org/apache/lucene/search/RangeQuery.java test/org/apache/lucene/search/TestRangeQuery.java
Date Thu, 13 Nov 2008 09:31:20 GMT
Author: mikemccand
Date: Thu Nov 13 01:31:20 2008
New Revision: 713687

URL: http://svn.apache.org/viewvc?rev=713687&view=rev
Log:
LUCENE-1424: correctly handle null lower or upper term in RangeQuery.getEnum

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestRangeQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java?rev=713687&r1=713686&r2=713687&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/RangeQuery.java Thu Nov 13 01:31:20
2008
@@ -171,8 +171,9 @@
   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. */

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestRangeQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestRangeQuery.java?rev=713687&r1=713686&r2=713687&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestRangeQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestRangeQuery.java Thu Nov 13 01:31:20
2008
@@ -21,6 +21,7 @@
 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 @@
     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);



Mime
View raw message