Matt Chaput avatar Matt Chaput committed e949504

Was calling a.max_quality() even though a might have just been replaced with NullMatcher(). Fixes issue #181.
Best solution might have been to just add implement max_quality() on NullMatcher,
which I've added here, but I also tried to make the logic clearer/more robust in
IntersectionMatcher.replace().

Comments (0)

Files changed (1)

src/whoosh/matching.py

     def copy(self):
         return self
 
+    def max_quality(self):
+        return 0
+
 
 class ListMatcher(Matcher):
     """Synthetic matcher backed by a list of IDs.
         if not (a_active and b_active):
             # Intersection matcher requires that both sub-matchers be active
             return NullMatcher()
-        elif minquality and a.max_quality() + b.max_quality() < minquality:
-            # If the combined quality of the sub-matchers can't contribute,
-            # return an inactive matcher
-            return NullMatcher()
 
-        a = a.replace(minquality - b.max_quality() if minquality else 0)
-        b = b.replace(minquality - a.max_quality() if minquality else 0)
+        if minquality:
+            a_max = a.max_quality()
+            b_max = b.max_quality()
+            if minquality and a_max + b_max < minquality:
+                # If the combined quality of the sub-matchers can't contribute,
+                # return an inactive matcher
+                return NullMatcher()
+            # Require that the replacements be able to contribute results
+            # higher than the minquality
+            a_min = minquality - b_max
+            b_min = minquality - a_max
+        else:
+            a_min = b_min = 0
+
+        a = a.replace(a_min)
+        b = b.replace(b_min)
         a_active = a.is_active()
         b_active = b.is_active()
         if not (a_active or b_active):
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.