Commits

Matt Chaput committed 18cf204

Fixed bug in parser when a field's multitoken_query is phrase. Fixes issue #159.

Comments (0)

Files changed (2)

src/whoosh/qparser/default.py

     And([Term("content", u"hello"), Term("content", u"there")])
     """
     
-    _multitoken_query_map = {"and": query.And, "or": query.Or,
-                             "phrase": query.Phrase}
+    _multitoken_query_map = {"and": query.And, "or": query.Or}
     
     def __init__(self, fieldname, schema, plugins=None, termclass=query.Term,
                  phraseclass=query.Phrase, group=syntax.AndGroup):
         return [item for item, _ in items_and_priorities]
     
     def multitoken_query(self, name, texts, fieldname, termclass, boost):
-        qclass = self._multitoken_query_map.get(name.lower())
-        if qclass:
-            return qclass([termclass(fieldname, t, boost=boost)
-                           for t in texts])
+        name = name.lower()
+        if name == "phrase":
+            return self.phraseclass(fieldname, texts, boost=boost)
+        else:
+            qclass = self._multitoken_query_map.get(name)
+            if qclass:
+                return qclass([termclass(fieldname, t, boost=boost)
+                               for t in texts])
     
     def term_query(self, fieldname, text, termclass, boost=1.0, tokenize=True,
                    removestops=True):

tests/test_parsing.py

     assert_equal(q[1].__class__, query.Term)
     assert_equal(q[1].text, "bacon")
 
+def test_multitoken_phrase():
+    textfield = fields.TEXT()
+    textfield.multitoken_query = "phrase"
+    schema = fields.Schema(text=textfield)
+    parser = default.QueryParser("text", schema)
+    qstring = u("chaw-bacon")
+    
+    texts = list(schema["text"].process_text(qstring))
+    assert_equal(texts, ["chaw", "bacon"])
+    
+    q = parser.parse(qstring)
+    assert_equal(q.__class__, query.Phrase)
+
 def test_operator_queries():
     qp = default.QueryParser("f", None)
     
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 ProjectModifiedEvent.java.
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.