lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject svn commit: r1596009 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/core/ lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
Date Mon, 19 May 2014 19:50:05 GMT
Author: jbernste
Date: Mon May 19 19:50:04 2014
New Revision: 1596009

URL: http://svn.apache.org/r1596009
Log:
LUCENE-5682: NPE in QueryRescorer when Scorer is null

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/core/   (props changed)
    lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
    lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1596009&r1=1596008&r2=1596009&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Mon May 19 19:50:04 2014
@@ -93,6 +93,9 @@ Bug fixes
   rethrown with more useful information about the problem, omitting the
   incorrect OutOfMemoryError.  (Robert Muir, Uwe Schindler)
 
+* LUCENE-5682: NPE in QueryRescorer when Scorer is null
+  (Joel Bernstein, Mike McCandless)
+
 Test Framework
 
 * LUCENE-5622: Fail tests if they print over the given limit of bytes to 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java?rev=1596009&r1=1596008&r2=1596009&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
Mon May 19 19:50:04 2014
@@ -85,18 +85,23 @@ public abstract class QueryRescorer exte
         scorer = weight.scorer(readerContext, null);
       }
 
-      int targetDoc = docID - docBase;
-      int actualDoc = scorer.docID();
-      if (actualDoc < targetDoc) {
-        actualDoc = scorer.advance(targetDoc);
-      }
+      if(scorer != null) {
+        int targetDoc = docID - docBase;
+        int actualDoc = scorer.docID();
+        if (actualDoc < targetDoc) {
+          actualDoc = scorer.advance(targetDoc);
+        }
 
-      if (actualDoc == targetDoc) {
-        // Query did match this doc:
-        hit.score = combine(hit.score, true, scorer.score());
+        if (actualDoc == targetDoc) {
+          // Query did match this doc:
+          hit.score = combine(hit.score, true, scorer.score());
+        } else {
+          // Query did not match this doc:
+          assert actualDoc > targetDoc;
+          hit.score = combine(hit.score, false, 0.0f);
+        }
       } else {
         // Query did not match this doc:
-        assert actualDoc > targetDoc;
         hit.score = combine(hit.score, false, 0.0f);
       }
 

Modified: lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java?rev=1596009&r1=1596008&r2=1596009&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
(original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
Mon May 19 19:50:04 2014
@@ -109,6 +109,46 @@ public class TestQueryRescorer extends L
     dir.close();
   }
 
+  // Test LUCENE-5682
+  public void testNullScorerTermQuery() throws Exception {
+    Directory dir = newDirectory();
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+
+    Document doc = new Document();
+    doc.add(newStringField("id", "0", Field.Store.YES));
+    doc.add(newTextField("field", "wizard the the the the the oz", Field.Store.NO));
+    w.addDocument(doc);
+    doc = new Document();
+    doc.add(newStringField("id", "1", Field.Store.YES));
+    // 1 extra token, but wizard and oz are close;
+    doc.add(newTextField("field", "wizard oz the the the the the the", Field.Store.NO));
+    w.addDocument(doc);
+    IndexReader r = w.getReader();
+    w.close();
+
+    // Do ordinary BooleanQuery:
+    BooleanQuery bq = new BooleanQuery();
+    bq.add(new TermQuery(new Term("field", "wizard")), Occur.SHOULD);
+    bq.add(new TermQuery(new Term("field", "oz")), Occur.SHOULD);
+    IndexSearcher searcher = getSearcher(r);
+    searcher.setSimilarity(new DefaultSimilarity());
+
+    TopDocs hits = searcher.search(bq, 10);
+    assertEquals(2, hits.totalHits);
+    assertEquals("0", searcher.doc(hits.scoreDocs[0].doc).get("id"));
+    assertEquals("1", searcher.doc(hits.scoreDocs[1].doc).get("id"));
+
+    // Now, resort using TermQuery on term that does not exist.
+    TermQuery tq = new TermQuery(new Term("field", "gold"));
+    TopDocs hits2 = QueryRescorer.rescore(searcher, hits, tq, 2.0, 10);
+
+    // Just testing that null scorer is handled.
+    assertEquals(2, hits2.totalHits);
+
+    r.close();
+    dir.close();
+  }
+
   public void testCustomCombine() throws Exception {
     Directory dir = newDirectory();
     RandomIndexWriter w = new RandomIndexWriter(random(), dir);



Mime
View raw message