You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/03/13 10:51:45 UTC

svn commit: r1577078 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/CHANGES.txt lucene/join/ lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java

Author: mikemccand
Date: Thu Mar 13 09:51:44 2014
New Revision: 1577078

URL: http://svn.apache.org/r1577078
Log:
LUCENE-5520: fix AIOOBE from ToChildBlockJoinQuery when a parent has no children

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/join/   (props changed)
    lucene/dev/branches/branch_4x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
    lucene/dev/branches/branch_4x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.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=1577078&r1=1577077&r2=1577078&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Thu Mar 13 09:51:44 2014
@@ -127,6 +127,10 @@ Bug fixes
 * LUCENE-5522: FacetsConfig didn't add drill-down terms for association facet 
   fields labels. (Shai Erera)
 
+* LUCENE-5520: ToChildBlockJoinQuery would hit
+  ArrayIndexOutOfBoundsException if a parent document had no children
+  (Sally Ang via Mike McCandless)
+
 Test Framework
 
 * LUCENE-5449: Rename _TestUtil and _TestHelper to remove the leading _.

Modified: lucene/dev/branches/branch_4x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java?rev=1577078&r1=1577077&r2=1577078&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java (original)
+++ lucene/dev/branches/branch_4x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java Thu Mar 13 09:51:44 2014
@@ -207,7 +207,7 @@ public class ToChildBlockJoinQuery exten
             validateParentDoc();
 
             if (parentDoc == 0) {
-              // Degenerate but allowed: parent has no children
+              // Degenerate but allowed: first parent doc has no children
               // TODO: would be nice to pull initial parent
               // into ctor so we can skip this if... but it's
               // tricky because scorer must return -1 for
@@ -222,8 +222,15 @@ public class ToChildBlockJoinQuery exten
               return childDoc;
             }
 
+            // Go to first child for this next parentDoc:
             childDoc = 1 + parentBits.prevSetBit(parentDoc-1);
 
+            if (childDoc == parentDoc) {
+              // This parent has no children; continue
+              // parent loop so we move to next parent
+              continue;
+            }
+
             if (acceptDocs != null && !acceptDocs.get(childDoc)) {
               continue nextChildDoc;
             }

Modified: lucene/dev/branches/branch_4x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java?rev=1577078&r1=1577077&r2=1577078&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java (original)
+++ lucene/dev/branches/branch_4x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java Thu Mar 13 09:51:44 2014
@@ -1437,4 +1437,48 @@ public class TestBlockJoin extends Lucen
     r.close();
     d.close();
   }
+
+  public void testAdvanceSingleDeletedParentNoChild() throws Exception {
+
+    final Directory dir = newDirectory();
+    final RandomIndexWriter w = new RandomIndexWriter(random(), dir);
+
+    // First doc with 1 children
+    Document parentDoc = new Document();
+    parentDoc.add(newStringField("parent", "1", Field.Store.NO));
+    parentDoc.add(newStringField("isparent", "yes", Field.Store.NO));
+    Document childDoc = new Document();
+    childDoc.add(newStringField("child", "1", Field.Store.NO));
+    w.addDocuments(Arrays.asList(childDoc, parentDoc));
+
+    parentDoc = new Document();
+    parentDoc.add(newStringField("parent", "2", Field.Store.NO));
+    parentDoc.add(newStringField("isparent", "yes", Field.Store.NO));
+    w.addDocuments(Arrays.asList(parentDoc));
+
+    w.deleteDocuments(new Term("parent", "2"));
+
+    parentDoc = new Document();
+    parentDoc.add(newStringField("parent", "2", Field.Store.NO));
+    parentDoc.add(newStringField("isparent", "yes", Field.Store.NO));
+    childDoc = new Document();
+    childDoc.add(newStringField("child", "2", Field.Store.NO));
+    w.addDocuments(Arrays.asList(childDoc, parentDoc));
+
+    IndexReader r = w.getReader();
+    w.close();
+    IndexSearcher s = newSearcher(r);
+
+    // Create a filter that defines "parent" documents in the index - in this case resumes
+    Filter parentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("isparent", "yes"))));
+
+    Query parentQuery = new TermQuery(new Term("parent", "2"));
+
+    ToChildBlockJoinQuery parentJoinQuery = new ToChildBlockJoinQuery(parentQuery, parentsFilter, random().nextBoolean());
+    TopDocs topdocs = s.search(parentJoinQuery, 3);
+    assertEquals(1, topdocs.totalHits);
+    
+    r.close();
+    dir.close();
+  }
 }