Commits

Matt Chaput committed f0d48bd

Fixed copy-paste error in _and_query() method of Sequence query.

  • Participants
  • Parent commits 7c5bb4a

Comments (0)

Files changed (3)

File src/whoosh/query/positional.py

                               self.slop, self.ordered, self.boost)
 
     def _and_query(self):
-        return compound.And([terms.Term(self.fieldname, word)
-                             for word in self.words])
+        return compound.And(self.subqueries)
 
     def estimate_size(self, ixreader):
         return self._and_query().estimate_size(ixreader)

File tests/test_parsing.py

     q = parser.parse(u"num:1")
 
     _ = text_type(q)
+
+
+def test_phrase_andmaybe():
+    qp = default.QueryParser("f", None)
+
+    q = qp.parse(u('Dahmen ANDMAYBE "Besov Spaces"'))
+    assert isinstance(q, query.AndMaybe)
+    assert q[0] == query.Term("f", u("Dahmen"))
+    assert q[1] == query.Phrase("f", [u("Besov"), u("Spaces")])

File tests/test_queries.py

 
         assert r1 == r2 == r3 == []
 
+
+def test_sequence():
+    schema = fields.Schema(id=fields.STORED, text=fields.TEXT)
+    ix = RamStorage().create_index(schema)
+    with ix.writer() as w:
+        w.add_document(id=0, text=u("alfa bravo charlie delta echo"))
+        w.add_document(id=1, text=u("bravo charlie delta echo alfa"))
+        w.add_document(id=2, text=u("charlie delta echo bravo"))
+        w.add_document(id=3, text=u("delta echo charlie"))
+        w.add_document(id=4, text=u("echo delta"))
+
+    with ix.searcher() as s:
+        seq = query.Sequence([query.Term("text", u("echo")),
+                              query.Term("text", u("alfa"))])
+        q = query.And([query.Term("text", "bravo"), seq])
+
+        r = s.search(q, limit=4)
+        assert len(r) == 1
+        assert r[0]["id"] == 1
+
+