From 73c6c2b49b7cda1ad3a021752057e4f5e0ac6c97 Mon Sep 17 00:00:00 2001 From: Aurelien FOUCRET Date: Mon, 4 Nov 2024 15:44:56 +0100 Subject: [PATCH] Use a module for the KQL plugin. --- .../esql/core/querydsl/query/QueryStringQuery.java | 2 ++ x-pack/plugin/kql/src/main/java/module-info.java | 12 ++++++++++++ .../elasticsearch/xpack/kql/parser/ParserUtils.java | 10 +++++----- 3 files changed, 19 insertions(+), 5 deletions(-) create mode 100644 x-pack/plugin/kql/src/main/java/module-info.java diff --git a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/QueryStringQuery.java b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/QueryStringQuery.java index 8ac90e6314174..839f70341b06a 100644 --- a/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/QueryStringQuery.java +++ b/x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/querydsl/query/QueryStringQuery.java @@ -16,6 +16,7 @@ import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.xpack.esql.core.expression.predicate.fulltext.StringQueryPredicate; import org.elasticsearch.xpack.esql.core.tree.Source; +import org.elasticsearch.xpack.kql.parser.KqlParser; import java.util.Collections; import java.util.Map; @@ -73,6 +74,7 @@ public QueryStringQuery(Source source, String query, Map fields, @Override public QueryBuilder asBuilder() { + KqlParser kqlQueryBuilder = new KqlParser(); final QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(query); queryBuilder.fields(fields); options.forEach((k, v) -> { diff --git a/x-pack/plugin/kql/src/main/java/module-info.java b/x-pack/plugin/kql/src/main/java/module-info.java new file mode 100644 index 0000000000000..11aef059bbac2 --- /dev/null +++ b/x-pack/plugin/kql/src/main/java/module-info.java @@ -0,0 +1,12 @@ +module org.elasticsearch.kql { + requires org.elasticsearch.server; + requires org.elasticsearch.xcontent; + requires org.antlr.antlr4.runtime; + requires org.elasticsearch.base; + requires org.apache.lucene.queryparser; + requires org.elasticsearch.logging; + requires org.apache.lucene.core; + + exports org.elasticsearch.xpack.kql; + exports org.elasticsearch.xpack.kql.parser; +} diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java index f996a953ea7f7..3319d920a88ee 100644 --- a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java @@ -12,11 +12,11 @@ import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTreeVisitor; import org.antlr.v4.runtime.tree.TerminalNode; -import org.apache.logging.log4j.util.Strings; import org.apache.lucene.queryparser.classic.QueryParser; import java.util.ArrayList; import java.util.List; +import java.util.Locale; /** * Utility class for parsing and processing KQL expressions. @@ -211,15 +211,15 @@ private static boolean isEscapedKeywordSequence(String input, int startIndex) { if (startIndex + 1 >= input.length()) { return false; } - String remaining = Strings.toRootLowerCase(input.substring(startIndex)); + String remaining = input.substring(startIndex).toLowerCase(Locale.ROOT); return remaining.startsWith("and") || remaining.startsWith("or") || remaining.startsWith("not"); } private static String handleKeywordSequence(String input, int startIndex) { String remaining = input.substring(startIndex); - if (Strings.toRootLowerCase(remaining).startsWith("and")) return remaining.substring(0, 3); - if (Strings.toRootLowerCase(remaining).startsWith("or")) return remaining.substring(0, 2); - if (Strings.toRootLowerCase(remaining).startsWith("not")) return remaining.substring(0, 3); + if (remaining.toLowerCase(Locale.ROOT).startsWith("and")) return remaining.substring(0, 3); + if (remaining.toLowerCase(Locale.ROOT).startsWith("or")) return remaining.substring(0, 2); + if (remaining.toLowerCase(Locale.ROOT).startsWith("not")) return remaining.substring(0, 3); return ""; }