Skip to content

Commit

Permalink
Add keywords_pattern to Keyword Marker Token Filter. (#3558)
Browse files Browse the repository at this point in the history
A regular expression pattern to match against words in the text.
  • Loading branch information
Stuart Cam authored and russcam committed Mar 20, 2019
1 parent 023f0e8 commit 74bcbc7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/Nest/Analysis/TokenFilters/KeywordMarkerTokenFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public interface IKeywordMarkerTokenFilter : ITokenFilter
/// </summary>
[JsonProperty("keywords_path")]
string KeywordsPath { get; set; }

/// <summary>
/// A regular expression pattern to match against words in the text.
/// </summary>
[JsonProperty("keywords_pattern")]
string KeywordsPattern { get; set; }
}

/// <inheritdoc />
Expand All @@ -40,6 +46,9 @@ public KeywordMarkerTokenFilter() : base("keyword_marker") { }

/// <inheritdoc />
public string KeywordsPath { get; set; }

/// <inheritdoc />
public string KeywordsPattern { get; set; }
}

/// <inheritdoc />
Expand All @@ -52,12 +61,17 @@ public class KeywordMarkerTokenFilterDescriptor
IEnumerable<string> IKeywordMarkerTokenFilter.Keywords { get; set; }
string IKeywordMarkerTokenFilter.KeywordsPath { get; set; }

string IKeywordMarkerTokenFilter.KeywordsPattern { get; set; }

/// <inheritdoc />
public KeywordMarkerTokenFilterDescriptor IgnoreCase(bool? ignoreCase = true) => Assign(a => a.IgnoreCase = ignoreCase);

/// <inheritdoc />
public KeywordMarkerTokenFilterDescriptor KeywordsPath(string path) => Assign(a => a.KeywordsPath = path);

/// <inheritdoc />
public KeywordMarkerTokenFilterDescriptor KeywordsPattern(string pattern) => Assign(a => a.KeywordsPattern = pattern);

/// <inheritdoc />
public KeywordMarkerTokenFilterDescriptor Keywords(IEnumerable<string> keywords) => Assign(a => a.Keywords = keywords);

Expand Down
8 changes: 6 additions & 2 deletions src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,19 @@ public class MarkerTests : TokenFilterAssertionBase<MarkerTests>
.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";
Expand Down

0 comments on commit 74bcbc7

Please sign in to comment.