From 74bcbc7bbea0b20b2677ad6f1387f4e356749373 Mon Sep 17 00:00:00 2001 From: Stuart Cam Date: Tue, 5 Mar 2019 16:16:41 +1100 Subject: [PATCH] Add keywords_pattern to Keyword Marker Token Filter. (#3558) A regular expression pattern to match against words in the text. --- .../TokenFilters/KeywordMarkerTokenFilter.cs | 14 ++++++++++++++ .../Analysis/TokenFilters/TokenFilterTests.cs | 8 ++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs b/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs index c58b6a11049..83159434aca 100644 --- a/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs +++ b/src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs @@ -25,6 +25,12 @@ public interface IKeywordMarkerTokenFilter : ITokenFilter /// [JsonProperty("keywords_path")] string KeywordsPath { get; set; } + + /// + /// A regular expression pattern to match against words in the text. + /// + [JsonProperty("keywords_pattern")] + string KeywordsPattern { get; set; } } /// @@ -40,6 +46,9 @@ public KeywordMarkerTokenFilter() : base("keyword_marker") { } /// public string KeywordsPath { get; set; } + + /// + public string KeywordsPattern { get; set; } } /// @@ -52,12 +61,17 @@ public class KeywordMarkerTokenFilterDescriptor IEnumerable IKeywordMarkerTokenFilter.Keywords { get; set; } string IKeywordMarkerTokenFilter.KeywordsPath { get; set; } + string IKeywordMarkerTokenFilter.KeywordsPattern { get; set; } + /// public KeywordMarkerTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase); /// public KeywordMarkerTokenFilterDescriptor KeywordsPath(string path) => Assign(a => a.KeywordsPath = path); + /// + public KeywordMarkerTokenFilterDescriptor KeywordsPattern(string pattern) => Assign(a => a.KeywordsPattern = pattern); + /// public KeywordMarkerTokenFilterDescriptor Keywords(IEnumerable keywords) => Assign(a => a.Keywords = keywords); diff --git a/src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs b/src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs index 21a95246fc7..61964d640fd 100644 --- a/src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs +++ b/src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs @@ -334,15 +334,19 @@ public class MarkerTests : TokenFilterAssertionBase .KeywordMarker("marker", t => t .IgnoreCase() .Keywords("a", "b") + .KeywordsPattern(".*") + .KeywordsPath("path") ); - public override ITokenFilter Initializer => new KeywordMarkerTokenFilter { IgnoreCase = true, Keywords = new[] { "a", "b" } }; + public override ITokenFilter Initializer => new KeywordMarkerTokenFilter { IgnoreCase = true, Keywords = new[] { "a", "b" }, KeywordsPath = "path", KeywordsPattern = ".*" }; public override object Json => new { type = "keyword_marker", keywords = new[] { "a", "b" }, - ignore_case = true + ignore_case = true, + keywords_path = "path", + keywords_pattern = ".*" }; public override string Name => "marker";