mirror of https://github.com/apache/lucene.git
fix empty string corner cases
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671497 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bb29c9cd2a
commit
86fe84c1ee
|
@ -233,25 +233,27 @@ final public class Automata {
|
||||||
throw new IllegalArgumentException("maxInclusive must be true when max is null (open ended)");
|
throw new IllegalArgumentException("maxInclusive must be true when max is null (open ended)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min != null && min.length == 0 && minInclusive == true) {
|
|
||||||
// Silly empty string corner case:
|
|
||||||
min = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (min == null) {
|
if (min == null) {
|
||||||
if (max == null) {
|
|
||||||
// Accepts all terms:
|
|
||||||
return makeAnyBinary();
|
|
||||||
}
|
|
||||||
min = new BytesRef();
|
min = new BytesRef();
|
||||||
minInclusive = true;
|
minInclusive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty string corner case:
|
||||||
|
if (max != null && maxInclusive == false && max.length == 1 && max.bytes[max.offset] == 0) {
|
||||||
|
max = new BytesRef();
|
||||||
|
maxInclusive = true;
|
||||||
|
}
|
||||||
|
|
||||||
int cmp;
|
int cmp;
|
||||||
if (max != null) {
|
if (max != null) {
|
||||||
cmp = min.compareTo(max);
|
cmp = min.compareTo(max);
|
||||||
} else {
|
} else {
|
||||||
cmp = -1;
|
cmp = -1;
|
||||||
|
if (min.length == 0 && minInclusive) {
|
||||||
|
return makeAnyBinary();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmp == 0) {
|
if (cmp == 0) {
|
||||||
if (minInclusive == false || maxInclusive == false) {
|
if (minInclusive == false || maxInclusive == false) {
|
||||||
return makeEmpty();
|
return makeEmpty();
|
||||||
|
|
|
@ -1125,6 +1125,8 @@ public class TestAutomaton extends LuceneTestCase {
|
||||||
System.out.println("Original was not minimal:");
|
System.out.println("Original was not minimal:");
|
||||||
System.out.println("Original:\n" + a.toDot());
|
System.out.println("Original:\n" + a.toDot());
|
||||||
System.out.println("Minimized:\n" + minA.toDot());
|
System.out.println("Minimized:\n" + minA.toDot());
|
||||||
|
System.out.println("minTerm=" + minTerm + " minInclusive=" + minInclusive);
|
||||||
|
System.out.println("maxTerm=" + maxTerm + " maxInclusive=" + maxInclusive);
|
||||||
fail("auotmaton was not minimal");
|
fail("auotmaton was not minimal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1233,7 +1235,6 @@ public class TestAutomaton extends LuceneTestCase {
|
||||||
|
|
||||||
public void testAcceptAllEmptyStringMin() throws Exception {
|
public void testAcceptAllEmptyStringMin() throws Exception {
|
||||||
Automaton a = Automata.makeBinaryInterval(new BytesRef(), true, null, true);
|
Automaton a = Automata.makeBinaryInterval(new BytesRef(), true, null, true);
|
||||||
System.out.println("HERE: " + a.toDot());
|
|
||||||
assertTrue(Operations.sameLanguage(Automata.makeAnyBinary(), a));
|
assertTrue(Operations.sameLanguage(Automata.makeAnyBinary(), a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue