|
| 1 | +// Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +// See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Runtime.Serialization; |
| 8 | +using Elastic.Elasticsearch.Xunit.XunitPlumbing; |
| 9 | +using FluentAssertions; |
| 10 | +using Nest; |
| 11 | +using Tests.Core.Client; |
| 12 | +using static Tests.Core.Serialization.SerializationTestHelper; |
| 13 | + |
| 14 | +namespace Tests.Reproduce |
| 15 | +{ |
| 16 | + public class GithubPR5039 |
| 17 | + { |
| 18 | + public class MyCustomTokenizer : ITokenizer |
| 19 | + { |
| 20 | + public string Type => "my_custom_tok"; |
| 21 | + public string Version { get; set; } |
| 22 | + |
| 23 | + public string Y { get; set; } |
| 24 | + } |
| 25 | + |
| 26 | + [U] |
| 27 | + public void CustomTokenizer() |
| 28 | + { |
| 29 | + var tokenizer = Object(new MyCustomTokenizer() { Version = "x", Y = "z" }) |
| 30 | + .RoundTrips(new { type = "my_custom_tok", version = "x", y = "z" }); |
| 31 | + tokenizer.Type.Should().Be("my_custom_tok"); |
| 32 | + tokenizer.Version.Should().Be("x"); |
| 33 | + tokenizer.Y.Should().Be("z"); |
| 34 | + } |
| 35 | + |
| 36 | + public class DynamicSynonymTokenFilter : ITokenFilter |
| 37 | + { |
| 38 | + public bool? Expand { get; set; } |
| 39 | + public SynonymFormat? Format { get; set; } |
| 40 | + public bool? Lenient { get; set; } |
| 41 | + public IEnumerable<string> Synonyms { get; set; } |
| 42 | + |
| 43 | + [DataMember(Name = "synonyms_path")] |
| 44 | + public string SynonymsPath { get; set; } |
| 45 | + |
| 46 | + public string Tokenizer { get; set; } |
| 47 | + public bool? Updateable { get; set; } |
| 48 | + public string Type { get; } = "dynamic_synonym"; |
| 49 | + public string Version { get; set; } |
| 50 | + public int? Interval { get; set; } |
| 51 | + } |
| 52 | + |
| 53 | + [U] |
| 54 | + public void CustomTokenFilter() |
| 55 | + { |
| 56 | + var tokenizer = Object(new DynamicSynonymTokenFilter() { Version = "x", SynonymsPath = "/root/access" }) |
| 57 | + .RoundTrips(new { type = "dynamic_synonym", version = "x", synonyms_path = "/root/access" }); |
| 58 | + tokenizer.Type.Should().Be("dynamic_synonym"); |
| 59 | + tokenizer.Version.Should().Be("x"); |
| 60 | + tokenizer.SynonymsPath.Should().Be("/root/access"); |
| 61 | + } |
| 62 | + |
| 63 | + [U] |
| 64 | + public void CreateIndex() |
| 65 | + { |
| 66 | + var client = TestClient.DefaultInMemoryClient; |
| 67 | + |
| 68 | + var response = client.Indices.Create("my-index", i => i |
| 69 | + .Settings(s => s |
| 70 | + .Analysis(a => a |
| 71 | + .TokenFilters(t => t |
| 72 | + .UserDefined("mytf", |
| 73 | + new DynamicSynonymTokenFilter |
| 74 | + { |
| 75 | + SynonymsPath = "https://my-synonym-server-url-that-not-is-relevant", |
| 76 | + Updateable = true, |
| 77 | + Lenient = true, |
| 78 | + Interval = 60 |
| 79 | + }) |
| 80 | + ) |
| 81 | + .Tokenizers(t => t |
| 82 | + .UserDefined("myt", new MyCustomTokenizer { Y = "yy" }) |
| 83 | + ) |
| 84 | + ) |
| 85 | + ) |
| 86 | + ); |
| 87 | + |
| 88 | + Expect(new |
| 89 | + { |
| 90 | + settings = new |
| 91 | + { |
| 92 | + analysis = new |
| 93 | + { |
| 94 | + filter = new |
| 95 | + { |
| 96 | + mytf = new |
| 97 | + { |
| 98 | + lenient = true, |
| 99 | + synonyms_path = "https://my-synonym-server-url-that-not-is-relevant", |
| 100 | + updateable = true, |
| 101 | + type = "dynamic_synonym", |
| 102 | + interval = 60 |
| 103 | + } |
| 104 | + }, |
| 105 | + tokenizer = new { myt = new { type = "my_custom_tok", y = "yy" } } |
| 106 | + } |
| 107 | + } |
| 108 | + }) |
| 109 | + .NoRoundTrip() |
| 110 | + .FromRequest(response); |
| 111 | + } |
| 112 | + } |
| 113 | +} |
0 commit comments