| | 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("EdgeNGramTokenFilterV2")] |
| | 10 | | [CodeGenSuppress(nameof(EdgeNGramTokenFilter), typeof(string), typeof(string), typeof(int?), typeof(int?), typeof(Ed |
| | 11 | | public partial class EdgeNGramTokenFilter : IUtf8JsonSerializable |
| | 12 | | { |
| | 13 | | /// <summary> Initializes a new instance of EdgeNGramTokenFilter. </summary> |
| | 14 | | /// <param name="name"> The name of the token filter. It must only contain letters, digits, spaces, dashes or un |
| 3 | 15 | | public EdgeNGramTokenFilter(string name) : base(name) |
| | 16 | | { |
| 3 | 17 | | Argument.AssertNotNull(name, nameof(name)); |
| | 18 | |
|
| 3 | 19 | | ODataType = "#Microsoft.Azure.Search.EdgeNGramTokenFilterV2"; |
| 3 | 20 | | } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// The minimum n-gram length. Default is 1. Must be less than the value of maxGram. |
| | 24 | | /// </summary> |
| 8 | 25 | | public int? MinGram { get; set; } |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// The maximum n-gram length. Default is 2. |
| | 29 | | /// </summary> |
| 8 | 30 | | public int? MaxGram { get; set; } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Specifies which side of the input the n-gram should be generated from. Default is <see cref="EdgeNGramTokenF |
| | 34 | | /// </summary> |
| 8 | 35 | | public EdgeNGramTokenFilterSide? Side { get; set; } |
| | 36 | |
|
| | 37 | | void global::Azure.Core.IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 38 | | { |
| 2 | 39 | | writer.WriteStartObject(); |
| | 40 | |
|
| 2 | 41 | | writer.WritePropertyName("@odata.type"); |
| 2 | 42 | | writer.WriteStringValue(ODataType); |
| | 43 | |
|
| 2 | 44 | | writer.WritePropertyName("name"); |
| 2 | 45 | | writer.WriteStringValue(Name); |
| | 46 | |
|
| 2 | 47 | | if (MinGram != null) |
| | 48 | | { |
| 2 | 49 | | writer.WritePropertyName("minGram"); |
| 2 | 50 | | writer.WriteNumberValue(MinGram.Value); |
| | 51 | | } |
| | 52 | |
|
| 2 | 53 | | if (MaxGram != null) |
| | 54 | | { |
| 2 | 55 | | writer.WritePropertyName("maxGram"); |
| 2 | 56 | | writer.WriteNumberValue(MaxGram.Value); |
| | 57 | | } |
| | 58 | |
|
| 2 | 59 | | if (Side != null) |
| | 60 | | { |
| 2 | 61 | | writer.WritePropertyName("side"); |
| 2 | 62 | | writer.WriteStringValue(Side.Value.ToSerialString()); |
| | 63 | | } |
| | 64 | |
|
| 2 | 65 | | writer.WriteEndObject(); |
| 2 | 66 | | } |
| | 67 | |
|
| | 68 | | internal static EdgeNGramTokenFilter DeserializeEdgeNGramTokenFilter(JsonElement element) |
| | 69 | | { |
| 2 | 70 | | int? minGram = default; |
| 2 | 71 | | int? maxGram = default; |
| 2 | 72 | | EdgeNGramTokenFilterSide? side = default; |
| 2 | 73 | | string odataType = default; |
| 2 | 74 | | string name = default; |
| | 75 | |
|
| 24 | 76 | | foreach (var property in element.EnumerateObject()) |
| | 77 | | { |
| 10 | 78 | | if (property.NameEquals("@odata.type")) |
| | 79 | | { |
| 2 | 80 | | odataType = property.Value.GetString(); |
| 2 | 81 | | continue; |
| | 82 | | } |
| | 83 | |
|
| 8 | 84 | | if (property.NameEquals("name")) |
| | 85 | | { |
| 2 | 86 | | name = property.Value.GetString(); |
| 2 | 87 | | continue; |
| | 88 | | } |
| | 89 | |
|
| 6 | 90 | | if (property.NameEquals("minGram")) |
| | 91 | | { |
| 2 | 92 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 93 | | { |
| | 94 | | continue; |
| | 95 | | } |
| 2 | 96 | | minGram = property.Value.GetInt32(); |
| 2 | 97 | | continue; |
| | 98 | | } |
| | 99 | |
|
| 4 | 100 | | if (property.NameEquals("maxGram")) |
| | 101 | | { |
| 2 | 102 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 103 | | { |
| | 104 | | continue; |
| | 105 | | } |
| 2 | 106 | | maxGram = property.Value.GetInt32(); |
| 2 | 107 | | continue; |
| | 108 | | } |
| | 109 | |
|
| 2 | 110 | | if (property.NameEquals("side")) |
| | 111 | | { |
| 2 | 112 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 113 | | { |
| | 114 | | continue; |
| | 115 | | } |
| 2 | 116 | | side = property.Value.GetString().ToEdgeNGramTokenFilterSide(); |
| | 117 | | continue; |
| | 118 | | } |
| | 119 | | } |
| | 120 | |
|
| 2 | 121 | | return new EdgeNGramTokenFilter(name) |
| 2 | 122 | | { |
| 2 | 123 | | ODataType = odataType, |
| 2 | 124 | | MinGram = minGram, |
| 2 | 125 | | MaxGram = maxGram, |
| 2 | 126 | | Side = side, |
| 2 | 127 | | }; |
| | 128 | | } |
| | 129 | | } |
| | 130 | | } |