lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r788802 - in /lucene/java/trunk/src: java/org/apache/lucene/search/BooleanQuery.java java/org/apache/lucene/search/DisjunctionMaxQuery.java java/org/apache/lucene/search/IndexSearcher.java test/org/apache/lucene/search/TestBooleanQuery.java
Date Fri, 26 Jun 2009 18:14:48 GMT
Author: mikemccand
Date: Fri Jun 26 18:14:48 2009
New Revision: 788802

URL: http://svn.apache.org/viewvc?rev=788802&view=rev
Log:
LUCENE-1630: fix NPEs

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
    lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java?rev=788802&r1=788801&r2=788802&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/BooleanQuery.java Fri Jun 26 18:14:48
2009
@@ -294,7 +294,9 @@
         BooleanClause c = (BooleanClause) cIter.next();
         Scorer subScorer = w.scorer(reader, true, false);
         if (subScorer == null) {
-          return null;
+          if (c.isRequired()) {
+            return null;
+          }
         } else if (c.isRequired()) {
           required.add(subScorer);
         } else if (c.isProhibited()) {

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java?rev=788802&r1=788801&r2=788802&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/DisjunctionMaxQuery.java Fri Jun 26
18:14:48 2009
@@ -134,9 +134,7 @@
       for (Iterator iter = weights.iterator(); iter.hasNext();) {
         QueryWeight w = (QueryWeight) iter.next();
         Scorer subScorer = w.scorer(reader, true, false);
-        if (subScorer == null) {
-          return null;
-        } else if (subScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+        if (subScorer != null && subScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS)
{
           scorers[idx++] = subScorer;
         }
       }

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java?rev=788802&r1=788801&r2=788802&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/IndexSearcher.java Fri Jun 26 18:14:48
2009
@@ -219,7 +219,9 @@
       hcw.setNextReader(reader, 0);
       if (filter == null) {
         Scorer scorer = weight.scorer(reader, true, true);
-        scorer.score(hcw);
+        if (scorer != null) {
+          scorer.score(hcw);
+        }
       } else {
         searchWithFilter(reader, weight, filter, hcw);
       }
@@ -239,7 +241,9 @@
       for (int i = 0; i < subReaders.length; i++) { // search each subreader
         collector.setNextReader(subReaders[i], docStarts[i]);
         Scorer scorer = weight.scorer(subReaders[i], !collector.acceptsDocsOutOfOrder(),
true);
-        scorer.score(collector);
+        if (scorer != null) {
+          scorer.score(collector);
+        }
       }
     } else {
       for (int i = 0; i < subReaders.length; i++) { // search each subreader

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=788802&r1=788801&r2=788802&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestBooleanQuery.java Fri Jun 26 18:14:48
2009
@@ -16,7 +16,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
+import org.apache.lucene.store.MockRAMDirectory;
+import org.apache.lucene.store.Directory;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.index.Term;
 
@@ -50,5 +56,32 @@
       // okay
     }
   }
+
+  // LUCENE-1630
+  public void testNullOrSubScorer() throws Throwable {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter w = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    Document doc = new Document();
+    doc.add(new Field("field", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
+    w.addDocument(doc);
+    IndexReader r = w.getReader();
+    IndexSearcher s = new IndexSearcher(r);
+    BooleanQuery q = new BooleanQuery();
+    q.add(new TermQuery(new Term("field", "a")), BooleanClause.Occur.SHOULD);
+
+    // PhraseQuery w/ no terms added returns a null scorer
+    PhraseQuery pq = new PhraseQuery();
+    q.add(pq, BooleanClause.Occur.SHOULD);
+    assertEquals(1, s.search(q, 10).totalHits);
+
+    DisjunctionMaxQuery dmq = new DisjunctionMaxQuery(1.0f);
+    dmq.add(new TermQuery(new Term("field", "a")));
+    dmq.add(pq);
+    assertEquals(1, s.search(dmq, 10).totalHits);
+    
+    r.close();
+    w.close();
+    dir.close();
+  }
   
 }



Mime
View raw message