Skip to content

Commit

Permalink
Remove errors when case_insensitive flag set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
markharwood committed Oct 21, 2020
1 parent 265a214 commit 17d3027
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 58 deletions.
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/prefix-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.

`case_insensitive`::
(Optional, boolean) allows ASCII case insensitive matching of the
value with the indexed field values when set to true. Setting to false is disallowed.
value with the indexed field values when set to true.

[[prefix-query-notes]]
==== Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/regexp-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ expression syntax>>.

`case_insensitive`::
(Optional, boolean) allows case insensitive matching of the regular expression
value with the indexed field values when set to true. Setting to false is disallowed.
value with the indexed field values when set to true.

`max_determinized_states`::
+
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/term-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ increases the relevance score.

`case_insensitive`::
(Optional, boolean) allows ASCII case insensitive matching of the
value with the indexed field values when set to true. Setting to false is disallowed.
value with the indexed field values when set to true.

[[term-query-notes]]
==== Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/wildcard-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ increases the relevance score.

`case_insensitive`::
(Optional, boolean) allows case insensitive matching of the
pattern with the indexed field values when set to true. Setting to false is disallowed.
pattern with the indexed field values when set to true.

[[wildcard-query-notes]]
==== Notes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ public String value() {
}

public PrefixQueryBuilder caseInsensitive(boolean caseInsensitive) {
if (caseInsensitive == false) {
throw new IllegalArgumentException("The case insensitive setting cannot be set to false.");
}
this.caseInsensitive = caseInsensitive;
return this;
}
Expand Down Expand Up @@ -175,10 +172,6 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
rewrite = parser.textOrNull();
} else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
caseInsensitive = parser.booleanValue();
if (caseInsensitive == false) {
throw new ParsingException(parser.getTokenLocation(),
"[prefix] query does not support [" + currentFieldName + "] = false");
}
} else {
throw new ParsingException(parser.getTokenLocation(),
"[prefix] query does not support [" + currentFieldName + "]");
Expand All @@ -196,9 +189,7 @@ public static PrefixQueryBuilder fromXContent(XContentParser parser) throws IOEx
.rewrite(rewrite)
.boost(boost)
.queryName(queryName);
if (caseInsensitive) {
result.caseInsensitive(caseInsensitive);
}
result.caseInsensitive(caseInsensitive);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public int flags() {
}

public RegexpQueryBuilder caseInsensitive(boolean caseInsensitive) {
if (caseInsensitive == false) {
throw new IllegalArgumentException("The case insensitive setting cannot be set to false.");
}
this.caseInsensitive = caseInsensitive;
return this;
}
Expand Down Expand Up @@ -240,10 +237,6 @@ public static RegexpQueryBuilder fromXContent(XContentParser parser) throws IOEx
flagsValue = parser.intValue();
} else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
caseInsensitive = parser.booleanValue();
if (caseInsensitive == false) {
throw new ParsingException(parser.getTokenLocation(),
"[regexp] query does not support [" + currentFieldName + "] = false");
}
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
Expand All @@ -265,9 +258,7 @@ public static RegexpQueryBuilder fromXContent(XContentParser parser) throws IOEx
.rewrite(rewrite)
.boost(boost)
.queryName(queryName);
if (caseInsensitive) {
result.caseInsensitive(caseInsensitive);
}
result.caseInsensitive(caseInsensitive);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public TermQueryBuilder(String fieldName, Object value) {
}

public TermQueryBuilder caseInsensitive(boolean caseInsensitive) {
if (caseInsensitive == false) {
throw new IllegalArgumentException("The case insensitive setting cannot be set to false.");
}
this.caseInsensitive = caseInsensitive;
return this;
}
Expand Down Expand Up @@ -143,10 +140,6 @@ public static TermQueryBuilder fromXContent(XContentParser parser) throws IOExce
boost = parser.floatValue();
} else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
caseInsensitive = parser.booleanValue();
if (caseInsensitive == false) {
throw new ParsingException(parser.getTokenLocation(),
"[term] query does not support [" + currentFieldName + "] = false");
}
} else {
throw new ParsingException(parser.getTokenLocation(),
"[term] query does not support [" + currentFieldName + "]");
Expand All @@ -167,9 +160,7 @@ public static TermQueryBuilder fromXContent(XContentParser parser) throws IOExce
if (queryName != null) {
termQuery.queryName(queryName);
}
if (caseInsensitive) {
termQuery.caseInsensitive(caseInsensitive);
}
termQuery.caseInsensitive(caseInsensitive);
return termQuery;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@ public String rewrite() {
}

public WildcardQueryBuilder caseInsensitive(boolean caseInsensitive) {
if (caseInsensitive == false) {
throw new IllegalArgumentException("The case insensitive setting cannot be set to false.");
}
this.caseInsensitive = caseInsensitive;
return this;
}
Expand Down Expand Up @@ -189,10 +186,6 @@ public static WildcardQueryBuilder fromXContent(XContentParser parser) throws IO
rewrite = parser.textOrNull();
} else if (CASE_INSENSITIVE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
caseInsensitive = parser.booleanValue();
if (caseInsensitive == false) {
throw new ParsingException(parser.getTokenLocation(),
"[prefix] query does not support [" + currentFieldName + "] = false");
}
} else if (AbstractQueryBuilder.NAME_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
queryName = parser.text();
} else {
Expand All @@ -212,9 +205,7 @@ public static WildcardQueryBuilder fromXContent(XContentParser parser) throws IO
.rewrite(rewrite)
.boost(boost)
.queryName(queryName);
if (caseInsensitive) {
result.caseInsensitive(caseInsensitive);
}
result.caseInsensitive(caseInsensitive);
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,4 @@ public void testParseFailsWithMultipleFields() throws IOException {
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}

public void testParseFailsWithCaseSensitive() throws IOException {
String json =
"{\n" +
" \"regexp\": {\n" +
" \"user1\": {\n" +
" \"value\": \"k.*y\",\n" +
" \"case_insensitive\": false\n" +
" },\n" +
" }\n" +
"}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[regexp] query does not support [case_insensitive] = false", e.getMessage());
}
}

0 comments on commit 17d3027

Please sign in to comment.