diff --git a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/analysis-common/40_token_filters.yml b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/analysis-common/40_token_filters.yml index a446cec03c23e..802c79c780689 100644 --- a/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/analysis-common/40_token_filters.yml +++ b/modules/analysis-common/src/yamlRestTest/resources/rest-api-spec/test/analysis-common/40_token_filters.yml @@ -156,6 +156,7 @@ - type: word_delimiter split_on_numerics: false type_table: + - "# This is a comment" - "# => ALPHANUM" - length: { tokens: 2 } - match: { tokens.0.token: text1 } @@ -176,6 +177,7 @@ - type: word_delimiter split_on_numerics: false type_table: + - "# This is a comment" - "# => ALPHANUM" - "@ => ALPHANUM" - length: { tokens: 2 } @@ -321,6 +323,7 @@ - type: word_delimiter_graph split_on_numerics: false type_table: + - "# This is a comment" - "# => ALPHANUM" - length: { tokens: 2 } - match: { tokens.0.token: text1 } @@ -341,6 +344,7 @@ - type: word_delimiter_graph split_on_numerics: false type_table: + - "# This is a comment" - "# => ALPHANUM" - "@ => ALPHANUM" - length: { tokens: 2 } diff --git a/server/src/main/java/org/opensearch/index/analysis/Analysis.java b/server/src/main/java/org/opensearch/index/analysis/Analysis.java index 26e26325904e0..b9a219057f326 100644 --- a/server/src/main/java/org/opensearch/index/analysis/Analysis.java +++ b/server/src/main/java/org/opensearch/index/analysis/Analysis.java @@ -100,7 +100,7 @@ public class Analysis { private static final Logger LOGGER = LogManager.getLogger(Analysis.class); // Regular expression to support hashtag tokenization - private static Pattern hashTagRulePattern = Pattern.compile("^\\s*#\\s*=>"); + private static final Pattern HASH_TAG_RULE_PATTERN = Pattern.compile("^\\s*#\\s*=>"); public static CharArraySet parseStemExclusion(Settings settings, CharArraySet defaultStemExclusion) { String value = settings.get("stem_exclusion"); @@ -249,7 +249,7 @@ public static List parseWordList( int lineNum = 0; for (String word : words) { lineNum++; - if (word.startsWith("#") == false || hashTagRulePattern.matcher(word).find()) { + if (word.startsWith("#") == false || HASH_TAG_RULE_PATTERN.matcher(word).find() == true) { try { rules.add(parser.apply(word)); } catch (RuntimeException ex) {