|  |  | 1 |  | // Copyright (c) Microsoft Corporation. All rights reserved. | 
|  |  | 2 |  | // Licensed under the MIT License. | 
|  |  | 3 |  |  | 
|  |  | 4 |  | using System.Text.Json; | 
|  |  | 5 |  | using Azure.Core; | 
|  |  | 6 |  |  | 
|  |  | 7 |  | namespace Azure.Search.Documents.Indexes.Models | 
|  |  | 8 |  | { | 
|  |  | 9 |  |     [CodeGenModel("NGramTokenFilterV2")] | 
|  |  | 10 |  |     [CodeGenSuppress(nameof(NGramTokenFilter), typeof(string), typeof(string), typeof(int?), typeof(int?))] | 
|  |  | 11 |  |     public partial class NGramTokenFilter : IUtf8JsonSerializable | 
|  |  | 12 |  |     { | 
|  |  | 13 |  |         /// <summary> | 
|  |  | 14 |  |         /// Initializes a new instance of NGramTokenFilter. | 
|  |  | 15 |  |         /// </summary> | 
|  |  | 16 |  |         /// <param name="name"> | 
|  |  | 17 |  |         /// The name of the token filter. It must only contain letters, digits, spaces, dashes or underscores, | 
|  |  | 18 |  |         /// can only start and end with alphanumeric characters, and is limited to 128 characters. | 
|  |  | 19 |  |         /// </param> | 
|  | 3 | 20 |  |         public NGramTokenFilter(string name) : base(name) | 
|  |  | 21 |  |         { | 
|  | 3 | 22 |  |             Argument.AssertNotNull(name, nameof(name)); | 
|  |  | 23 |  |  | 
|  | 3 | 24 |  |             ODataType = "#Microsoft.Azure.Search.NGramTokenFilterV2"; | 
|  | 3 | 25 |  |         } | 
|  |  | 26 |  |  | 
|  |  | 27 |  |         /// <summary> | 
|  |  | 28 |  |         /// The minimum n-gram length. Default is 1. | 
|  |  | 29 |  |         /// Maximum is 300. | 
|  |  | 30 |  |         /// Must be less than the value of maxGram. | 
|  |  | 31 |  |         /// </summary> | 
|  | 8 | 32 |  |         public int? MinGram { get; set; } | 
|  |  | 33 |  |  | 
|  |  | 34 |  |         /// <summary> | 
|  |  | 35 |  |         /// The maximum n-gram length. Default is 2. | 
|  |  | 36 |  |         /// Maximum is 300. | 
|  |  | 37 |  |         /// </summary> | 
|  | 8 | 38 |  |         public int? MaxGram { get; set; } | 
|  |  | 39 |  |  | 
|  |  | 40 |  |         void global::Azure.Core.IUtf8JsonSerializable.Write(Utf8JsonWriter writer) | 
|  |  | 41 |  |         { | 
|  | 2 | 42 |  |             writer.WriteStartObject(); | 
|  |  | 43 |  |  | 
|  | 2 | 44 |  |             writer.WritePropertyName("@odata.type"); | 
|  | 2 | 45 |  |             writer.WriteStringValue(ODataType); | 
|  |  | 46 |  |  | 
|  | 2 | 47 |  |             writer.WritePropertyName("name"); | 
|  | 2 | 48 |  |             writer.WriteStringValue(Name); | 
|  |  | 49 |  |  | 
|  | 2 | 50 |  |             if (MinGram != null) | 
|  |  | 51 |  |             { | 
|  | 2 | 52 |  |                 writer.WritePropertyName("minGram"); | 
|  | 2 | 53 |  |                 writer.WriteNumberValue(MinGram.Value); | 
|  |  | 54 |  |             } | 
|  |  | 55 |  |  | 
|  | 2 | 56 |  |             if (MaxGram != null) | 
|  |  | 57 |  |             { | 
|  | 2 | 58 |  |                 writer.WritePropertyName("maxGram"); | 
|  | 2 | 59 |  |                 writer.WriteNumberValue(MaxGram.Value); | 
|  |  | 60 |  |             } | 
|  |  | 61 |  |  | 
|  | 2 | 62 |  |             writer.WriteEndObject(); | 
|  | 2 | 63 |  |         } | 
|  |  | 64 |  |  | 
|  |  | 65 |  |         internal static NGramTokenFilter DeserializeNGramTokenFilter(JsonElement element) | 
|  |  | 66 |  |         { | 
|  | 2 | 67 |  |             int? minGram = default; | 
|  | 2 | 68 |  |             int? maxGram = default; | 
|  | 2 | 69 |  |             string odataType = default; | 
|  | 2 | 70 |  |             string name = default; | 
|  | 20 | 71 |  |             foreach (var property in element.EnumerateObject()) | 
|  |  | 72 |  |             { | 
|  | 8 | 73 |  |                 if (property.NameEquals("@odata.type")) | 
|  |  | 74 |  |                 { | 
|  | 2 | 75 |  |                     odataType = property.Value.GetString(); | 
|  | 2 | 76 |  |                     continue; | 
|  |  | 77 |  |                 } | 
|  |  | 78 |  |  | 
|  | 6 | 79 |  |                 if (property.NameEquals("name")) | 
|  |  | 80 |  |                 { | 
|  | 2 | 81 |  |                     name = property.Value.GetString(); | 
|  | 2 | 82 |  |                     continue; | 
|  |  | 83 |  |                 } | 
|  |  | 84 |  |  | 
|  | 4 | 85 |  |                 if (property.NameEquals("minGram")) | 
|  |  | 86 |  |                 { | 
|  | 2 | 87 |  |                     if (property.Value.ValueKind == JsonValueKind.Null) | 
|  |  | 88 |  |                     { | 
|  |  | 89 |  |                         continue; | 
|  |  | 90 |  |                     } | 
|  | 2 | 91 |  |                     minGram = property.Value.GetInt32(); | 
|  | 2 | 92 |  |                     continue; | 
|  |  | 93 |  |                 } | 
|  |  | 94 |  |  | 
|  | 2 | 95 |  |                 if (property.NameEquals("maxGram")) | 
|  |  | 96 |  |                 { | 
|  | 2 | 97 |  |                     if (property.Value.ValueKind == JsonValueKind.Null) | 
|  |  | 98 |  |                     { | 
|  |  | 99 |  |                         continue; | 
|  |  | 100 |  |                     } | 
|  | 2 | 101 |  |                     maxGram = property.Value.GetInt32(); | 
|  |  | 102 |  |                     continue; | 
|  |  | 103 |  |                 } | 
|  |  | 104 |  |             } | 
|  |  | 105 |  |  | 
|  | 2 | 106 |  |             return new NGramTokenFilter(name) | 
|  | 2 | 107 |  |             { | 
|  | 2 | 108 |  |                 ODataType = odataType, | 
|  | 2 | 109 |  |                 MinGram = minGram, | 
|  | 2 | 110 |  |                 MaxGram = maxGram, | 
|  | 2 | 111 |  |             }; | 
|  |  | 112 |  |         } | 
|  |  | 113 |  |     } | 
|  |  | 114 |  | } |