Skip to content

Commit bbe2956

Browse files
Address code review feedback
1 parent 94443e5 commit bbe2956

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

server/src/main/java/org/elasticsearch/index/query/AutomatonQueryBuilder.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424

2525
/**
2626
* Implements an Automaton query, which matches documents based on a Lucene Automaton.
27-
* It does not support serialization or XContent representation,
27+
* It does not support serialization or XContent representation.
2828
*/
2929
public class AutomatonQueryBuilder extends AbstractQueryBuilder<AutomatonQueryBuilder> implements MultiTermQueryBuilder {
3030
private final String fieldName;
3131
private final Automaton automaton;
3232
private final String description;
3333

3434
public AutomatonQueryBuilder(String fieldName, Automaton automaton, String description) {
35-
this.description = description;
3635
if (Strings.isEmpty(fieldName)) {
3736
throw new IllegalArgumentException("field name is null or empty");
3837
}
@@ -41,6 +40,7 @@ public AutomatonQueryBuilder(String fieldName, Automaton automaton, String descr
4140
}
4241
this.fieldName = fieldName;
4342
this.automaton = automaton;
43+
this.description = description;
4444
}
4545

4646
@Override
@@ -70,12 +70,14 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {
7070

7171
@Override
7272
protected int doHashCode() {
73-
return Objects.hash(fieldName, automaton);
73+
return Objects.hash(fieldName, automaton, description);
7474
}
7575

7676
@Override
7777
protected boolean doEquals(AutomatonQueryBuilder other) {
78-
return Objects.equals(fieldName, other.fieldName) && Objects.equals(automaton, other.automaton);
78+
return Objects.equals(fieldName, other.fieldName)
79+
&& Objects.equals(automaton, other.automaton)
80+
&& Objects.equals(description, other.description);
7981
}
8082

8183
@Override
@@ -93,10 +95,10 @@ static class AutomatonQueryWithDescription extends AutomatonQuery {
9395

9496
@Override
9597
public String toString(String field) {
96-
if (description.isEmpty()) {
97-
return super.toString(field);
98+
if (this.field.equals(field)) {
99+
return description;
98100
}
99-
return description;
101+
return this.field + ":" + description;
100102
}
101103
}
102104
}

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/PushQueriesIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void testLikeList() throws IOException {
266266
String luceneQuery = switch (type) {
267267
case CONSTANT_KEYWORD, MATCH_ONLY_TEXT_WITH_KEYWORD, AUTO, TEXT_WITH_KEYWORD -> "*:*";
268268
case SEMANTIC_TEXT_WITH_KEYWORD -> "FieldExistsQuery [field=_primary_term]";
269-
case KEYWORD -> "Automaton for test LIKE (\"%value*\", \"abc*\"), caseInsensitive=false";
269+
case KEYWORD -> "test:LIKE(\"%value*\", \"abc*\"), caseInsensitive=false";
270270
};
271271
ComputeSignature dataNodeSignature = switch (type) {
272272
case CONSTANT_KEYWORD, KEYWORD -> ComputeSignature.FILTER_IN_QUERY;

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/string/regex/WildcardLikeList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,6 @@ private Query translateField(String targetFieldName) {
123123
private String getAutomatonDescription(String targetFieldName) {
124124
// we use all the information used the create the automaton to describe the query here
125125
String patternDesc = pattern().patternList().stream().map(WildcardPattern::pattern).collect(Collectors.joining("\", \""));
126-
return "Automaton for " + targetFieldName + " LIKE (\"" + patternDesc + "\"), caseInsensitive=" + caseInsensitive();
126+
return "LIKE(\"" + patternDesc + "\"), caseInsensitive=" + caseInsensitive();
127127
}
128128
}

0 commit comments

Comments
 (0)