Commits

Matt Chaput committed 5882c9f

Fixed off-by-one error in FuzzyTermPlugin.

Comments (0)

Files changed (2)

src/whoosh/qparser/plugins.py

     def do_fuzzyterms(self, parser, group):
         newgroup = group.empty_copy()
         for i, node in enumerate(group):
-            if i < len(group) - 2 and isinstance(node, syntax.WordNode):
+            if i < len(group) - 1 and isinstance(node, syntax.WordNode):
                 nextnode = group[i + 1]
                 if isinstance(nextnode, self.FuzzinessNode):
                     node = self.FuzzyTermNode(node, nextnode.maxdist)

tests/test_parsing.py

     qp = default.QueryParser("f", schema)
     qp.add_plugin(plugins.FuzzyTermPlugin())
 
+    q = qp.parse("bob~")
+    assert_equal(q.__class__, query.FuzzyTerm)
+    assert_equal(q.fieldname, "f")
+    assert_equal(q.text, "bob")
+    assert_equal(q.maxdist, 1)
+
     q = qp.parse("Alfa Bravo~ Charlie")
-    print q
     assert_equal(q.__class__, query.And)
     assert_equal(q[0].__class__, query.Term)
     assert_equal(q[0].text, "alfa")
     assert_equal(q[2].text, "charlie")
 
     q = qp.parse("Alfa Bravo~2 Charlie")
-    print q
     assert_equal(q.__class__, query.And)
     assert_equal(q[0].__class__, query.Term)
     assert_equal(q[0].text, "alfa")
     assert_equal(q[2].__class__, query.Term)
     assert_equal(q[2].text, "charlie")
 
+    qp = default.QueryParser("f", None)
+    q = qp.parse("'bob~'")
+    assert_equal(q.__class__, query.Term)
+    assert_equal(q.fieldname, "f")
+    assert_equal(q.text, "bob~")
+
 
 def test_function_plugin():
     class FakeQuery(query.Query):