Skip to content

Apache Lucene open-source search software

fix to prevent that queries like 'ca??' match a term like 'cat'. Terms with the correct length should be returned only. See Bug#LUCENE-306

Bernhard Messer34e42624f6fd
diff --git a/src/java/org/apache/lucene/search/WildcardTermEnum.java b/src/java/org/apache/lucene/search/WildcardTermEnum.java
index d2fcf33caf9..610a033c9df 100644
--- a/src/java/org/apache/lucene/search/WildcardTermEnum.java
+++ b/src/java/org/apache/lucene/search/WildcardTermEnum.java
@@ -125,15 +125,20 @@ public class WildcardTermEnum extends FilteredTermEnum {
{
// Check the character at the current position
char wildchar = pattern.charAt(wildcardSearchPos);
+
// If it's not a wildcard character, then there is more
// pattern information after this/these wildcards.
-
if (wildchar != WILDCARD_CHAR && wildchar != WILDCARD_STRING)
{
justWildcardsLeft = false;
}
else
{
+ // to prevent "cat" matches "ca??"
+ if (wildchar == WILDCARD_CHAR) {
+ return false;
+ }
+
// Look at the next character
wildcardSearchPos++;
}