Skip to content

Commit 539dbcc

Browse files
Mpdreamzrusscam
authored andcommitted
Add lenient to synonym and synonym_graph token filters (#3428)
(cherry picked from commit 1adc417)
1 parent d88b057 commit 539dbcc

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/Nest/Analysis/TokenFilters/Synonym/SynonymGraphTokenFilter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public interface ISynonymGraphTokenFilter : ITokenFilter
3131

3232
[JsonProperty("tokenizer")]
3333
string Tokenizer { get; set; }
34+
35+
/// <inheritdoc cref="ISynonymTokenFilter.Lenient"/>
36+
[JsonProperty("lenient")]
37+
bool? Lenient { get; set; }
3438
}
3539

3640
/// <inheritdoc/>
@@ -54,6 +58,9 @@ public SynonymGraphTokenFilter() : base("synonym_graph") { }
5458
/// <inheritdoc/>
5559
public bool? Expand { get; set; }
5660

61+
/// <inheritdoc cref="ISynonymTokenFilter.Lenient"/>
62+
public bool? Lenient { get; set; }
63+
5764
/// <inheritdoc/>
5865
public string Tokenizer { get; set; }
5966
}
@@ -65,6 +72,7 @@ public class SynonymGraphTokenFilterDescriptor
6572

6673
bool? ISynonymGraphTokenFilter.IgnoreCase { get; set; }
6774
bool? ISynonymGraphTokenFilter.Expand { get; set; }
75+
bool? ISynonymGraphTokenFilter.Lenient { get; set; }
6876
string ISynonymGraphTokenFilter.Tokenizer { get; set; }
6977
string ISynonymGraphTokenFilter.SynonymsPath { get; set; }
7078
SynonymFormat? ISynonymGraphTokenFilter.Format{ get; set; }
@@ -78,6 +86,10 @@ public class SynonymGraphTokenFilterDescriptor
7886
///<inheritdoc/>
7987
public SynonymGraphTokenFilterDescriptor Expand(bool? expand = true) => Assign(a => a.Expand = expand);
8088

89+
/// <inheritdoc cref="ISynonymTokenFilter.Lenient"/>
90+
public SynonymGraphTokenFilterDescriptor Lenient(bool? lenient = true) => Assign(a => a.Lenient = lenient);
91+
92+
8193
///<inheritdoc/>
8294
public SynonymGraphTokenFilterDescriptor Tokenizer(string tokenizer) => Assign(a => a.Tokenizer = tokenizer);
8395

src/Nest/Analysis/TokenFilters/Synonym/SynonymTokenFilter.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public interface ISynonymTokenFilter : ITokenFilter
3030

3131
[JsonProperty("tokenizer")]
3232
string Tokenizer { get; set; }
33+
34+
/// <summary>
35+
/// If `true` ignores exceptions while parsing the synonym configuration. It is important
36+
// to note that only those synonym rules which cannot get parsed are ignored.
37+
/// </summary>
38+
[JsonProperty("lenient")]
39+
bool? Lenient { get; set; }
3340
}
3441

3542
/// <inheritdoc/>
@@ -53,6 +60,9 @@ public SynonymTokenFilter() : base("synonym") { }
5360
/// <inheritdoc/>
5461
public bool? Expand { get; set; }
5562

63+
/// <inheritdoc cref="ISynonymTokenFilter.Lenient"/>
64+
public bool? Lenient { get; set; }
65+
5666
/// <inheritdoc/>
5767
public string Tokenizer { get; set; }
5868
}
@@ -64,6 +74,7 @@ public class SynonymTokenFilterDescriptor
6474

6575
bool? ISynonymTokenFilter.IgnoreCase { get; set; }
6676
bool? ISynonymTokenFilter.Expand { get; set; }
77+
bool? ISynonymTokenFilter.Lenient { get; set; }
6778
string ISynonymTokenFilter.Tokenizer { get; set; }
6879
string ISynonymTokenFilter.SynonymsPath { get; set; }
6980
SynonymFormat? ISynonymTokenFilter.Format { get; set; }
@@ -76,6 +87,9 @@ public class SynonymTokenFilterDescriptor
7687
///<inheritdoc/>
7788
public SynonymTokenFilterDescriptor Expand(bool? expand = true) => Assign(a => a.Expand = expand);
7889

90+
/// <inheritdoc cref="ISynonymTokenFilter.Lenient"/>
91+
public SynonymTokenFilterDescriptor Lenient(bool? lenient = true) => Assign(a => a.Lenient = lenient);
92+
7993
///<inheritdoc/>
8094
public SynonymTokenFilterDescriptor Tokenizer(string tokenizer) => Assign(a => a.Tokenizer = tokenizer);
8195

src/Tests/Tests/Analysis/TokenFilters/TokenFilterTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,33 @@ public class SynonymTests : TokenFilterAssertionBase<SynonymTests>
674674
expand = true,
675675
tokenizer = "whitespace"
676676
};
677+
}
678+
679+
[SkipVersion("<6.4.0", "Lenient is an option introduced in 6.4.0")]
680+
public class SynonymLenientTests : TokenFilterAssertionBase<SynonymTests>
681+
{
682+
public override string Name => "syn";
683+
private readonly string[] _synonyms = {"foo", "bar => baz"};
684+
685+
public override ITokenFilter Initializer =>
686+
new SynonymTokenFilter
687+
{
688+
Lenient = true,
689+
Synonyms = _synonyms
690+
};
677691

692+
public override FuncTokenFilters Fluent => (n, tf) => tf
693+
.Synonym(n, t => t
694+
.Lenient()
695+
.Synonyms(_synonyms)
696+
);
697+
698+
public override object Json => new
699+
{
700+
type = "synonym",
701+
synonyms = _synonyms,
702+
lenient = true,
703+
};
678704
}
679705

680706
public class SynonymGraphTests : TokenFilterAssertionBase<SynonymGraphTests>

0 commit comments

Comments
 (0)