Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9098 Use multibyte code-points for complex fuzzy query (#1194)

Mikeec6a9aab0956
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
index f882ee75446..78c5daf6f28 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestFuzzyQuery.java
@@ -499,21 +499,31 @@ public class TestFuzzyQuery extends LuceneTestCase {
assertTrue(expected.getMessage().contains("maxExpansions must be positive"));
}
+ private String randomRealisticMultiByteUnicode(int length) {
+ while (true) {
+ // There is 1 single-byte unicode block, and 194 multi-byte blocks
+ String value = RandomizedTest.randomRealisticUnicodeOfCodepointLength(length);
+ if (value.charAt(0) > Byte.MAX_VALUE) {
+ return value;
+ }
+ }
+ }
+
public void testErrorMessage() {
// 45 states per vector from Lev2TParametricDescription
- int length = (Operations.DEFAULT_MAX_DETERMINIZED_STATES / 45) + 10;
+ final int length = (Operations.DEFAULT_MAX_DETERMINIZED_STATES / 45) + 10;
+ final String value = randomRealisticMultiByteUnicode(length);
- String value = RandomizedTest.randomRealisticUnicodeOfCodepointLength(length);
FuzzyTermsEnum.FuzzyTermsException expected = expectThrows(FuzzyTermsEnum.FuzzyTermsException.class, () -> {
new FuzzyQuery(new Term("field", value)).getTermsEnum(new Terms() {
@Override
public TermsEnum iterator() {
- throw new UnsupportedOperationException();
+ return TermsEnum.EMPTY;
}
@Override
public long size() {
- throw new UnsupportedOperationException();
+ return 0;
}
@Override