Commits

Matt Chaput committed c7ff919

Fixed bug in ArrayUnionMatcher, added "scored" arguement, added unit test.
Added __repr__ to NullMatcher.

Comments (0)

Files changed (3)

src/whoosh/matching/combo.py

     current document, just an array of scores.
     """
 
-    def __init__(self, submatchers, doccount, boost=1.0, partsize=1024):
+    def __init__(self, submatchers, doccount, boost=1.0, scored=True,
+                 partsize=256):
         CombinationMatcher.__init__(self, submatchers, boost=boost)
+        self._scored = scored
         self._doccount = doccount
         self._partsize = partsize
 
-        self._a = array("f", (0.0 for _ in xrange(self._partsize)))
+        self._a = array("f", (0 for _ in xrange(self._partsize)))
         self._docnum = 0
         self._offset = 0
         self._limit = 0
         self._read_part()
         self._find_next()
 
+    def __repr__(self):
+        return ("%s(%r, boost=%f, scored=%r, partsize=%d)"
+                % (self.__class__.__name__, self._submatchers, self._boost,
+                   self._scored, self._partsize))
+
     def _read_part(self):
+        scored = self._scored
         boost = self._boost
         limit = min(self._limit + self._partsize, self._doccount)
         offset = self._limit
         a = self._a
+
+        # Clear the array
         for i in xrange(self._partsize):
-            a[i] = 0.0
+            a[i] = 0
 
+        # Add the scores from the submatchers into the array
         for m in self._submatchers:
             while m.is_active() and m.id() < limit:
-                a[m.id() - offset] = m.score() * boost
+                i = m.id() - offset
+                if scored:
+                    a[i] += m.score() * boost
+                else:
+                    a[i] = 1
                 m.next()
 
         self._offset = offset

src/whoosh/matching/mcore.py

     def __call__(self):
         return self
 
+    def __repr__(self):
+        return "<NullMatcher>"
+
     def supports_block_quality(self):
         return True
 

tests/test_searching.py

     _run_query(query.Or([]), [])
 
 
+def test_ors():
+    domain = u("alfa bravo charlie delta echo foxtrot").split()
+    s = fields.Schema(num=fields.STORED, text=fields.TEXT)
+    st = RamStorage()
+    ix = st.create_index(s)
+    with ix.writer() as w:
+        for i, ls in enumerate(permutations(domain)):
+            w.add_document(num=i, text=" ".join(ls))
+
+    with ix.searcher() as s:
+        qs = [query.Term("text", word) for word in domain]
+        for i in xrange(1, len(domain)):
+            q = query.Or(qs[:i])
+            r1 = [(hit.docnum, hit.score) for hit in s.search(q, limit=None)]
+
+            q.binary_matcher = True
+            r2 = [(hit.docnum, hit.score) for hit in s.search(q, limit=None)]
+
+            assert_equal(r1, r2)
+
+
 def test_not():
     _run_query(query.Or([query.Term("value", u("red")),
                          query.Term("name", u("yellow")),
         assert_equal([hit["id"] for hit in r], [4, 5, 3, 6, 1, 8, 2, 7])
 
 
+def test_version_field():
+    pass
 
 
-
-