diff --git a/src/java/org/apache/lucene/search/regex/RegexTermEnum.java b/src/java/org/apache/lucene/search/regex/RegexTermEnum.java index bfef444d75f..528e6212f92 100644 --- a/src/java/org/apache/lucene/search/regex/RegexTermEnum.java +++ b/src/java/org/apache/lucene/search/regex/RegexTermEnum.java @@ -26,9 +26,7 @@ public class RegexTermEnum extends FilteredTermEnum { while (index < text.length()) { char c = text.charAt(index); - // TODO: improve the logic here. There are other types of patterns - // that could break this, such as "\d*" and "\*abc" - if (c == '*' || c == '[' || c == '?' || c == '.') break; + if (!Character.isLetterOrDigit(c)) break; index++; } diff --git a/src/test/org/apache/lucene/search/regex/TestRegexQuery.java b/src/test/org/apache/lucene/search/regex/TestRegexQuery.java index 6ba55329640..caa9e326e00 100644 --- a/src/test/org/apache/lucene/search/regex/TestRegexQuery.java +++ b/src/test/org/apache/lucene/search/regex/TestRegexQuery.java @@ -89,5 +89,12 @@ public class TestRegexQuery extends TestCase { public void testSpanRegex2() throws Exception { assertEquals(0, spanRegexQueryNrHits("q.[aeiou]c.*", "dog", 5, true)); } + +// public void testPrefix() throws Exception { + // This test currently fails because RegexTermEnum picks "r" as the prefix + // but the following "?" makes the "r" optional and should be a hit for the + // document matching "over". +// assertEquals(1, regexQueryNrHits("r?over")); +// } }