Commits

Matt Chaput committed 642b325

Fixed MultifieldPlugin to recurse inside groups.

Comments (0)

Files changed (2)

src/whoosh/qparser/plugins.py

     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])
             newstream.append(t)

tests/test_parsing.py

 from nose.tools 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")
 
+    
 
+
+
+
+