Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Aug 19, 2024
1 parent 437e1fe commit 1a27ec3
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i

private static final ParseField REWRITE_OVERRIDE = new ParseField("rewrite_override");

private String rewrite_override;
private String rewriteOverride;

private final String fieldName;

Expand Down Expand Up @@ -186,8 +186,8 @@ public FuzzyQueryBuilder(StreamInput in) throws IOException {
maxExpansions = in.readVInt();
transpositions = in.readBoolean();
rewrite = in.readOptionalString();
if (in.getVersion().after(Version.V_2_16_0)) {
rewrite_override = in.readOptionalString();
if (in.getVersion().onOrAfter(Version.V_2_17_0)) {
rewriteOverride = in.readOptionalString();
}
}

Expand All @@ -200,8 +200,8 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeVInt(this.maxExpansions);
out.writeBoolean(this.transpositions);
out.writeOptionalString(this.rewrite);
if (out.getVersion().after(Version.V_2_16_0)) {
out.writeOptionalString(rewrite_override);
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
out.writeOptionalString(rewriteOverride);
}
}

Expand Down Expand Up @@ -259,8 +259,8 @@ public String rewrite() {
return this.rewrite;
}

private FuzzyQueryBuilder rewrite_override(String rewrite_override) {
this.rewrite_override = rewrite_override;
private FuzzyQueryBuilder rewriteOverride(String rewriteOverride) {
this.rewriteOverride = rewriteOverride;
return this;
}

Expand All @@ -277,8 +277,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field(REWRITE_FIELD.getPreferredName(), rewrite);
}
printBoostAndQueryName(builder);
if (rewrite_override != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewrite_override);
if (rewriteOverride != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewriteOverride);
}
builder.endObject();
builder.endObject();
Expand All @@ -292,7 +292,7 @@ public static FuzzyQueryBuilder fromXContent(XContentParser parser) throws IOExc
int maxExpansions = FuzzyQueryBuilder.DEFAULT_MAX_EXPANSIONS;
boolean transpositions = FuzzyQueryBuilder.DEFAULT_TRANSPOSITIONS;
String rewrite = null;
String rewrite_override = null;
String rewriteOverride = null;
String queryName = null;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
String currentFieldName = null;
Expand Down Expand Up @@ -324,7 +324,7 @@ public static FuzzyQueryBuilder fromXContent(XContentParser parser) throws IOExc
} else if (REWRITE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
rewrite = parser.textOrNull();
} else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) {
rewrite_override = parser.textOrNull();
rewriteOverride = parser.textOrNull();
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
Expand Down Expand Up @@ -353,7 +353,7 @@ public static FuzzyQueryBuilder fromXContent(XContentParser parser) throws IOExc
.rewrite(rewrite)
.boost(boost)
.queryName(queryName)
.rewrite_override(rewrite_override);
.rewriteOverride(rewriteOverride);
}

@Override
Expand All @@ -380,12 +380,21 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
throw new IllegalStateException("Rewrite first");
}
String rewrite = this.rewrite;
QueryShardContext.RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
QueryShardContext.RewriteOverride rewriteOverrideMethod = QueryParsers.parseRewriteOverride(
rewriteOverride,
QueryShardContext.RewriteOverride.INDEX_OR_DOC_VALUES,
LoggingDeprecationHandler.INSTANCE
);
Query query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions, null, rewriteOverride, context);
Query query = fieldType.fuzzyQuery(
value,
fuzziness,
prefixLength,
maxExpansions,
transpositions,
null,
rewriteOverrideMethod,
context
);
if (query instanceof MultiTermQuery) {
MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(rewrite, null, LoggingDeprecationHandler.INSTANCE);
query = fieldType.fuzzyQuery(
Expand All @@ -395,7 +404,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
maxExpansions,
transpositions,
rewriteMethod,
rewriteOverride,
rewriteOverrideMethod,
context
);
}
Expand All @@ -404,7 +413,7 @@ protected Query doToQuery(QueryShardContext context) throws IOException {

@Override
protected int doHashCode() {
return Objects.hash(fieldName, value, fuzziness, prefixLength, maxExpansions, transpositions, rewrite, rewrite_override);
return Objects.hash(fieldName, value, fuzziness, prefixLength, maxExpansions, transpositions, rewrite, rewriteOverride);
}

@Override
Expand All @@ -416,6 +425,6 @@ protected boolean doEquals(FuzzyQueryBuilder other) {
&& Objects.equals(maxExpansions, other.maxExpansions)
&& Objects.equals(transpositions, other.transpositions)
&& Objects.equals(rewrite, other.rewrite)
&& Objects.equals(rewrite_override, other.rewrite_override);
&& Objects.equals(rewriteOverride, other.rewriteOverride);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder>

private static final ParseField REWRITE_OVERRIDE = new ParseField("rewrite_override");

private String rewrite_override;
private String rewriteOverride;

private final String fieldName;

Expand Down Expand Up @@ -103,8 +103,8 @@ public PrefixQueryBuilder(StreamInput in) throws IOException {
value = in.readString();
rewrite = in.readOptionalString();
caseInsensitive = in.readBoolean();
if (in.getVersion().after(Version.V_2_16_0)) {
rewrite_override = in.readOptionalString();
if (in.getVersion().onOrAfter(Version.V_2_17_0)) {
rewriteOverride = in.readOptionalString();
}
}

Expand All @@ -114,8 +114,8 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeString(value);
out.writeOptionalString(rewrite);
out.writeBoolean(caseInsensitive);
if (out.getVersion().after(Version.V_2_16_0)) {
out.writeOptionalString(rewrite_override);
if (out.getVersion().onOrAfter(Version.V_2_17_0)) {
out.writeOptionalString(rewriteOverride);
}
}

Expand All @@ -142,8 +142,8 @@ public PrefixQueryBuilder rewrite(String rewrite) {
return this;
}

public PrefixQueryBuilder rewrite_override(String rewrite_override) {
this.rewrite_override = rewrite_override;
public PrefixQueryBuilder rewriteOverride(String rewriteOverride) {
this.rewriteOverride = rewriteOverride;
return this;
}

Expand All @@ -163,8 +163,8 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
builder.field(CASE_INSENSITIVE_FIELD.getPreferredName(), caseInsensitive);
}
printBoostAndQueryName(builder);
if (rewrite_override != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewrite_override);
if (rewriteOverride != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewriteOverride);
}
builder.endObject();
builder.endObject();
Expand All @@ -174,7 +174,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
String fieldName = null;
String value = null;
String rewrite = null;
String rewrite_override = null;
String rewriteOverride = null;

String queryName = null;
float boost = AbstractQueryBuilder.DEFAULT_BOOST;
Expand Down Expand Up @@ -202,7 +202,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
} else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
caseInsensitive = parser.booleanValue();
} else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) {
rewrite_override = parser.textOrNull();
rewriteOverride = parser.textOrNull();
} else {
throw new ParsingException(
parser.getTokenLocation(),
Expand All @@ -222,7 +222,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
.boost(boost)
.queryName(queryName)
.caseInsensitive(caseInsensitive)
.rewrite_override(rewrite_override);
.rewriteOverride(rewriteOverride);
}

@Override
Expand All @@ -242,7 +242,7 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
// fields we also have the guarantee that it doesn't perform I/O, which is important
// since rewrites might happen on a network thread.
QueryShardContext.RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
rewriteOverride,
QueryShardContext.RewriteOverride.INDEX_OR_DOC_VALUES,
LoggingDeprecationHandler.INSTANCE
);
Expand All @@ -269,25 +269,25 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
if (fieldType == null) {
throw new IllegalStateException("Rewrite first");
}
QueryShardContext.RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
QueryShardContext.RewriteOverride rewriteOverrideMethod = QueryParsers.parseRewriteOverride(
rewriteOverride,
QueryShardContext.RewriteOverride.INDEX_OR_DOC_VALUES,
LoggingDeprecationHandler.INSTANCE
);
return fieldType.prefixQuery(value, method, rewriteOverride, caseInsensitive, context);
return fieldType.prefixQuery(value, method, rewriteOverrideMethod, caseInsensitive, context);
}

@Override
protected final int doHashCode() {
return Objects.hash(fieldName, value, rewrite, caseInsensitive, rewrite_override);
return Objects.hash(fieldName, value, rewrite, caseInsensitive, rewriteOverride);
}

@Override
protected boolean doEquals(PrefixQueryBuilder other) {
return Objects.equals(fieldName, other.fieldName)
&& Objects.equals(value, other.value)
&& Objects.equals(rewrite, other.rewrite)
&& Objects.equals(rewrite_override, other.rewrite_override)
&& Objects.equals(rewriteOverride, other.rewriteOverride)
&& Objects.equals(caseInsensitive, other.caseInsensitive);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
private String format;
private ShapeRelation relation;

private String rewrite_override;
private String rewriteOverride;

/**
* A Query that matches documents within an range of terms.
Expand Down Expand Up @@ -122,8 +122,8 @@ public RangeQueryBuilder(StreamInput in) throws IOException {
throw new IllegalArgumentException("[range] query does not support relation [" + relationString + "]");
}
}
if (in.getVersion().after(Version.V_2_16_0)) {
rewrite_override = in.readOptionalString();
if (in.getVersion().after(Version.V_2_17_0)) {
rewriteOverride = in.readOptionalString();
}
}

Expand All @@ -145,8 +145,8 @@ protected void doWriteTo(StreamOutput out) throws IOException {
relationString = this.relation.getRelationName();
}
out.writeOptionalString(relationString);
if (out.getVersion().after(Version.V_2_16_0)) {
out.writeOptionalString(rewrite_override);
if (out.getVersion().after(Version.V_2_17_0)) {
out.writeOptionalString(rewriteOverride);
}
}

Expand Down Expand Up @@ -283,8 +283,8 @@ public RangeQueryBuilder timeZone(String timeZone) {
return this;
}

public RangeQueryBuilder rewrite_override(String rewrite_override) {
this.rewrite_override = rewrite_override;
public RangeQueryBuilder rewriteOverride(String rewriteOverride) {
this.rewriteOverride = rewriteOverride;
return this;
}

Expand Down Expand Up @@ -362,8 +362,8 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
builder.field(RELATION_FIELD.getPreferredName(), relation.getRelationName());
}
printBoostAndQueryName(builder);
if (rewrite_override != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewrite_override);
if (rewriteOverride != null) {
builder.field(REWRITE_OVERRIDE.getPreferredName(), rewriteOverride);
}
builder.endObject();
builder.endObject();
Expand All @@ -380,7 +380,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc
String queryName = null;
String format = null;
String relation = null;
String rewrite_override = null;
String rewriteOverride = null;

String currentFieldName = null;
XContentParser.Token token;
Expand Down Expand Up @@ -425,7 +425,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else if (REWRITE_OVERRIDE.match(currentFieldName, parser.getDeprecationHandler())) {
rewrite_override = parser.textOrNull();
rewriteOverride = parser.textOrNull();
} else {
throw new ParsingException(
parser.getTokenLocation(),
Expand Down Expand Up @@ -455,7 +455,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc
if (relation != null) {
rangeQuery.relation(relation);
}
rangeQuery.rewrite_override(rewrite_override);
rangeQuery.rewriteOverride(rewriteOverride);
return rangeQuery;
}

Expand Down Expand Up @@ -548,17 +548,27 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
throw new IllegalStateException("Rewrite first");
}
DateMathParser forcedDateParser = getForceDateParser();
QueryShardContext.RewriteOverride rewriteOverride = QueryParsers.parseRewriteOverride(
rewrite_override,
QueryShardContext.RewriteOverride rewriteOverrideMethod = QueryParsers.parseRewriteOverride(
rewriteOverride,
QueryShardContext.RewriteOverride.INDEX_OR_DOC_VALUES,
LoggingDeprecationHandler.INSTANCE
);
return mapper.rangeQuery(from, to, includeLower, includeUpper, relation, timeZone, forcedDateParser, rewriteOverride, context);
return mapper.rangeQuery(
from,
to,
includeLower,
includeUpper,
relation,
timeZone,
forcedDateParser,
rewriteOverrideMethod,
context
);
}

@Override
protected int doHashCode() {
return Objects.hash(fieldName, from, to, timeZone, includeLower, includeUpper, format, rewrite_override);
return Objects.hash(fieldName, from, to, timeZone, includeLower, includeUpper, format, rewriteOverride);
}

@Override
Expand All @@ -570,6 +580,6 @@ protected boolean doEquals(RangeQueryBuilder other) {
&& Objects.equals(includeLower, other.includeLower)
&& Objects.equals(includeUpper, other.includeUpper)
&& Objects.equals(format, other.format)
&& Objects.equals(rewrite_override, other.rewrite_override);
&& Objects.equals(rewriteOverride, other.rewriteOverride);
}
}
Loading

0 comments on commit 1a27ec3

Please sign in to comment.