Matt Chaput  committed 642b325

Fixed MultifieldPlugin to recurse inside groups.

  • Participants
  • Parent commits d2b12d8

Comments (0)

Files changed (2)

File src/whoosh/qparser/

     def do_multifield(self, parser, stream):
         newstream = stream.empty()
         for t in stream:
-            if isinstance(t, BasicSyntax) and t.fieldname is None:
+            if isinstance(t, Group):
+                t = self.do_multifield(parser, t)
+            elif isinstance(t, BasicSyntax) and t.fieldname is None:
                 t = OrGroup([t.set_fieldname(fn).set_boost(self.boosts.get(fn, 1.0))
                              for fn in self.fieldnames])

File tests/

 from import assert_equal
 from whoosh import analysis, fields, qparser, query
+from whoosh.qparser import dateparse
 def test_empty_querystring():
     assert_equal(q.__class__, query.Term)
     assert_equal(q.fieldname, "title")
     assert_equal(q.text, "test")
+def test_multifield():
+    schema = fields.Schema(content=fields.TEXT, title=fields.TEXT,
+                           cat=fields.KEYWORD, date=fields.DATETIME)
+    qs = u"time (cinema muza cat:place) OR (cinema muza cat:event)"
+    qp = qparser.MultifieldParser(['content', 'title'], schema)
+    q = qp.parse(qs)
+    assert_equal(unicode(q), "((content:time OR title:time) AND (((content:cinema OR title:cinema) AND (content:muza OR title:muza) AND cat:place) OR ((content:cinema OR title:cinema) AND (content:muza OR title:muza) AND cat:event)))")
 def test_fieldname_chars():
     s = fields.Schema(abc123=fields.TEXT, nisbah=fields.KEYWORD)
     assert_equal(q[0].text, "*john*")
     assert_equal(q[1].text, "blog")