Matt Chaput avatar Matt Chaput committed c4ff3ea

Fixed error in score() on a MultiMatcher, where the Scorer object was global but called with a per-segment matcher.
This error wasn't showing up in practice because per-segment searching means MultiMatcher is not usually used.

Comments (0)

Files changed (2)


     """Serializes the results of a list of sub-matchers.
-    def __init__(self, matchers, idoffsets, current=0):
+    def __init__(self, matchers, idoffsets, scorer=None, current=0):
         :param matchers: a list of Matcher objects.
         :param idoffsets: a list of offsets corresponding to items in the
         self.matchers = matchers
         self.offsets = idoffsets
+        self.scorer = scorer
         self.current = current
             # contribute
             while (m.is_active()
                    and m.matchers[m.current].max_quality() < minquality):
-                m = self.__class__(self.matchers, self.offsets, m.current + 1)
+                m = self.__class__(self.matchers, self.offsets, self.scorer,
+                                   m.current + 1)
         if not m.is_active():
         return self.matchers[self.current].weight()
     def score(self):
-        return self.matchers[self.current].score()
+        return self.scorer.score(self)
 def ExcludeMatcher(child, excluded, boost=1.0):


         assert r.matched_terms() == set([('content', b('ipfstd1'))])
+def test_score_length():
+    schema = fields.Schema(a=fields.TEXT, b=fields.TEXT)
+    ix = RamStorage().create_index(schema)
+    with ix.writer() as w:
+        w.add_document(a=u("alfa bravo charlie"))
+        w.add_document(b=u("delta echo foxtrot"))
+        w.add_document(a=u("golf hotel india"))
+    with ix.writer() as w:
+        w.merge = False
+        w.add_document(b=u("juliet kilo lima"))
+        # In the second segment, there is an "a" field here, but in the
+        # corresponding document in the first segment, the field doesn't exist,
+        # so if the scorer is getting segment offsets wrong, scoring this
+        # document will error
+        w.add_document(a=u("mike november oskar"))
+        w.add_document(b=u("papa quebec romeo"))
+    with ix.searcher() as s:
+        assert not s.is_atomic()
+        p = s.postings("a", "mike")
+        while p.is_active():
+            docnum =
+            score = p.score()
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
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.