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
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.