Commits

Matt Chaput  committed ed21316 Merge
  • Participants
  • Parent commits 4b31859, f87b710

Comments (0)

Files changed (2)

File src/whoosh/query/terms.py

         elif text.startswith("\\A"):
             text = text[2:]
 
-        return PatternQuery._find_prefix(self, text)
+        prefix = PatternQuery._find_prefix(self, text)
+
+        lp = len(prefix)
+        if lp < len(text) and text[lp] in "*?":
+            # we stripped something starting from * or ? - they both MAY mean
+            # "0 times". As we had stripped starting from FIRST special char,
+            # that implies there were only ordinary chars left of it. Thus,
+            # the very last of them is not part of the real prefix:
+            prefix = prefix[:-1]
+        return prefix
 
     # _words() implemented in PatternQuery
 

File tests/test_queries.py

         assert_equal(q.simplify(r).__unicode__(), "(word:able OR word:ago)")
         assert_equal(q._find_prefix(q.text), "")
 
+        # special case: ? may mean "zero occurences"
+        q = query.Regex("word", "ah?i")
+        assert_equal(q.simplify(r).__unicode__(), "(word:ahi OR word:aim)")
+        assert_equal(q._find_prefix(q.text), "a")
 
+        # special case: * may mean "zero occurences"
+        q = query.Regex("word", "ah*i")
+        assert_equal(q.simplify(r).__unicode__(), "(word:ahi OR word:aim)")
+        assert_equal(q._find_prefix(q.text), "a")
 
-
-
-
-
-
-
-
-
-