Skip to content

Commit

Permalink
fix format error
Browse files Browse the repository at this point in the history
Signed-off-by: gesong.samuel <[email protected]>
  • Loading branch information
gesong.samuel committed Sep 5, 2024
1 parent e32c7e5 commit fbcd5de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.lucene.util.automaton.RegExp;
import org.opensearch.common.lucene.BytesRefs;
import org.opensearch.common.lucene.Lucene;
import org.opensearch.common.regex.Regex;
import org.opensearch.common.unit.Fuzziness;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.analysis.IndexAnalyzers;
Expand Down Expand Up @@ -486,9 +485,9 @@ static Set<String> getRequiredNGrams(String value) {
rawSequence = getNonWildcardSequence(value, 0);
currentSequence = performEscape(rawSequence);
if (currentSequence.length() == 1) {
terms.add(new String(new char[]{0, currentSequence.charAt(0)}));
terms.add(new String(new char[] { 0, currentSequence.charAt(0) }));
} else {
terms.add(new String(new char[]{0, currentSequence.charAt(0), currentSequence.charAt(1)}));
terms.add(new String(new char[] { 0, currentSequence.charAt(0), currentSequence.charAt(1) }));
}
} else {
pos = findNonWildcardSequence(value, pos);
Expand All @@ -508,11 +507,11 @@ static Set<String> getRequiredNGrams(String value) {
if (isEndOfValue) {
// This is the end of the input. We can attach a suffix anchor.
if (currentSequence.length() == 1) {
terms.add(new String(new char[]{currentSequence.charAt(0), 0}));
terms.add(new String(new char[] { currentSequence.charAt(0), 0 }));
} else {
char a = currentSequence.charAt(currentSequence.length() - 2);
char b = currentSequence.charAt(currentSequence.length() - 1);
terms.add(new String(new char[]{a, b, 0}));
terms.add(new String(new char[] { a, b, 0 }));
}
}
pos = findNonWildcardSequence(value, pos + rawSequence.length());
Expand All @@ -524,8 +523,7 @@ static Set<String> getRequiredNGrams(String value) {
private static String getNonWildcardSequence(String value, int startFrom) {
for (int i = startFrom; i < value.length(); i++) {
char c = value.charAt(i);
if ((c == '?' || c == '*') &&
(i == 0 || value.charAt(i - 1) != '\\')) {
if ((c == '?' || c == '*') && (i == 0 || value.charAt(i - 1) != '\\')) {
return value.substring(startFrom, i);
}
}
Expand Down Expand Up @@ -646,10 +644,10 @@ private static Query regexpToQuery(String fieldName, RegExp regExp) {
query = builder.build();
} else if ((regExp.kind == RegExp.Kind.REGEXP_REPEAT_MIN || regExp.kind == RegExp.Kind.REGEXP_REPEAT_MINMAX)
&& regExp.min > 0) {
return regexpToQuery(fieldName, regExp.exp1);
} else {
return new MatchAllDocsQuery();
}
return regexpToQuery(fieldName, regExp.exp1);
} else {
return new MatchAllDocsQuery();
}
if (query.clauses().size() == 1) {
return query.iterator().next().getQuery();
} else if (query.clauses().size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,14 @@ public void testEscapedWildcardQuery() {
ft.wildcardQuery("\\**\\*", null, null)
);

assertEquals(
new WildcardFieldMapper.WildcardMatchingQuery("field", builder.build(), "\\*"),
ft.wildcardQuery("\\*", null, null)
);
assertEquals(new WildcardFieldMapper.WildcardMatchingQuery("field", builder.build(), "\\*"), ft.wildcardQuery("\\*", null, null));

expectedTerms.remove(suffixAnchored("*"));
builder = new BooleanQuery.Builder();
for (String term : expectedTerms) {
builder.add(new TermQuery(new Term("field", term)), BooleanClause.Occur.FILTER);
}
assertEquals(
new WildcardFieldMapper.WildcardMatchingQuery("field", builder.build(), "\\**"),
ft.wildcardQuery("\\**", null, null)
);
assertEquals(new WildcardFieldMapper.WildcardMatchingQuery("field", builder.build(), "\\**"), ft.wildcardQuery("\\**", null, null));
}

public void testMultipleWildcardsInQuery() {
Expand Down

0 comments on commit fbcd5de

Please sign in to comment.