Commits

Matt Chaput committed c6115b2

ArrayUnionMatcher.skip_to() didn't check if submatchers were active.

Comments (0)

Files changed (3)

src/whoosh/matching/combo.py

             self._find_next()
             return
 
-        # Advance all submatchers
+        # Advance all active submatchers
         submatchers = self._submatchers
         active = False
         for subm in submatchers:
-            subm.skip_to(docnum)
-            active = active or subm.is_active()
+            if subm.is_active():
+                subm.skip_to(docnum)
 
-        if active:
+        if any(subm.is_active() for subm in submatchers):
             # Rebuffer
             self._docnum = self._min_id()
             self._read_part()

src/whoosh/matching/mcore.py

     def reset(self):
         self._i = 0
 
+    def skip_to(self, id):
+        if not self.is_active():
+            raise ReadTooFar
+        if id < self.id():
+            return
+
+        while self._i < len(self._ids) and self._ids[self._i] < id:
+            self._i += 1
+
     def term(self):
         return self._term
 

tests/test_matching.py

     assert aum.id() == 50
     aum.skip_to(550)
     assert aum.id() == 600
+
+
+def test_arrayunion2():
+    l1 = matching.ListMatcher([1, 2])
+    l2 = matching.ListMatcher([1, 2, 10, 20])
+    l3 = matching.ListMatcher([1, 5, 10, 50])
+    aum = matching.ArrayUnionMatcher([l1, l2, l3], 51, partsize=2)
+
+    assert aum.id() == 1
+    assert not l1.is_active()
+    aum.skip_to(50)
+    assert aum.id() == 50
+