Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keywords_pattern to Keyword Marker Token Filter. #3558

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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