From 036029a3702f8e4bd5ab446d28f41d841afbf99e Mon Sep 17 00:00:00 2001 From: yogev mets Date: Sun, 24 Jul 2022 10:55:51 +0300 Subject: [PATCH] pr changes Signed-off-by: yogev mets --- .../index/search/QueryStringQueryParser.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/opensearch/index/search/QueryStringQueryParser.java b/server/src/main/java/org/opensearch/index/search/QueryStringQueryParser.java index 854116490a2a7..d2e1979e76985 100644 --- a/server/src/main/java/org/opensearch/index/search/QueryStringQueryParser.java +++ b/server/src/main/java/org/opensearch/index/search/QueryStringQueryParser.java @@ -721,15 +721,10 @@ private Query getWildcardQuerySingle(String field, String termStr) throws ParseE try { MappedFieldType currentFieldType = queryBuilder.context.fieldMapper(field); if (currentFieldType != null) { - // return newUnmappedFieldQuery(field); - setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); + setAnalyzer(getSearchAnalyzer(currentFieldType)); indexedNameField = currentFieldType.name(); } - // if (forceAnalyzer != null && (analyzeWildcard || currentFieldType.getTextSearchInfo().isTokenized())) { - // setAnalyzer(forceAnalyzer); - // return super.getWildcardQuery(currentFieldType.name(), termStr); - // } if (getAllowLeadingWildcard() == false && (termStr.startsWith("*") || termStr.startsWith("?"))) { throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery"); } @@ -745,6 +740,13 @@ private Query getWildcardQuerySingle(String field, String termStr) throws ParseE } } + private Analyzer getSearchAnalyzer(MappedFieldType currentFieldType) { + if (forceAnalyzer == null) { + return queryBuilder.context.getSearchAnalyzer(currentFieldType); + } + return forceAnalyzer; + } + @Override protected Query getRegexpQuery(String field, String termStr) throws ParseException { final int maxAllowedRegexLength = context.getIndexSettings().getMaxRegexLength(); @@ -785,14 +787,10 @@ private Query getRegexpQuerySingle(String field, String termStr) throws ParseExc if (currentFieldType == null) { return newUnmappedFieldQuery(field); } - setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); + setAnalyzer(getSearchAnalyzer(currentFieldType)); return super.getRegexpQuery(field, termStr); - // if (forceAnalyzer != null) { - // setAnalyzer(forceAnalyzer); - // return super.getRegexpQuery(field, termStr); - // } - // return currentFieldType.regexpQuery(termStr, RegExp.ALL, 0, getDeterminizeWorkLimit(), getMultiTermRewriteMethod(), context); - } catch (RuntimeException e) { + + } catch (RuntimeException e) { if (lenient) { return newLenientFieldQuery(field, e); }