| | 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("KeywordTokenizerV2")] |
| | 10 | | [CodeGenSuppress(nameof(KeywordTokenizer), typeof(string), typeof(string), typeof(int?))] |
| | 11 | | public partial class KeywordTokenizer : IUtf8JsonSerializable |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Initializes a new instance of KeywordTokenizer. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="name"> |
| | 17 | | /// The name of the tokenizer. It must only contain letters, digits, spaces, |
| | 18 | | /// dashes or underscores, can only start and end with alphanumeric characters, |
| | 19 | | /// and is limited to 128 characters. |
| | 20 | | /// </param> |
| 3 | 21 | | public KeywordTokenizer(string name) : base(name) |
| | 22 | | { |
| 3 | 23 | | Argument.AssertNotNull(name, nameof(name)); |
| | 24 | |
|
| 3 | 25 | | ODataType = "#Microsoft.Azure.Search.KeywordTokenizerV2"; |
| 3 | 26 | | } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// The read buffer size in bytes. Default is 256. |
| | 30 | | /// Setting this property on new instances of <see cref="KeywordTokenizer"/> may result in an error |
| | 31 | | /// when sending new requests to the Azure Cognitive Search service. |
| | 32 | | /// </summary> |
| 8 | 33 | | public int? BufferSize { get; set; } |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// The maximum token length. Default is 256. |
| | 37 | | /// Tokens longer than the maximum length are split. |
| | 38 | | /// The maximum token length that can be used is 300 characters. |
| | 39 | | /// </summary> |
| 8 | 40 | | public int? MaxTokenLength { get; set; } |
| | 41 | |
|
| | 42 | | // Use global scope to fully qualify name to work around bug in generator currently. |
| | 43 | | void global::Azure.Core.IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 44 | | { |
| 2 | 45 | | writer.WriteStartObject(); |
| | 46 | |
|
| 2 | 47 | | writer.WritePropertyName("@odata.type"); |
| 2 | 48 | | writer.WriteStringValue(ODataType); |
| | 49 | |
|
| 2 | 50 | | writer.WritePropertyName("name"); |
| 2 | 51 | | writer.WriteStringValue(Name); |
| | 52 | |
|
| 2 | 53 | | if (BufferSize != null) |
| | 54 | | { |
| 2 | 55 | | writer.WritePropertyName("bufferSize"); |
| 2 | 56 | | writer.WriteNumberValue(BufferSize.Value); |
| | 57 | | } |
| | 58 | |
|
| 2 | 59 | | if (MaxTokenLength != null) |
| | 60 | | { |
| 2 | 61 | | writer.WritePropertyName("maxTokenLength"); |
| 2 | 62 | | writer.WriteNumberValue(MaxTokenLength.Value); |
| | 63 | | } |
| | 64 | |
|
| 2 | 65 | | writer.WriteEndObject(); |
| 2 | 66 | | } |
| | 67 | |
|
| | 68 | | internal static KeywordTokenizer DeserializeKeywordTokenizer(JsonElement element) |
| | 69 | | { |
| 2 | 70 | | int? bufferSize = default; |
| 2 | 71 | | int? maxTokenLength = default; |
| 2 | 72 | | string odataType = default; |
| 2 | 73 | | string name = default; |
| | 74 | |
|
| 20 | 75 | | foreach (JsonProperty property in element.EnumerateObject()) |
| | 76 | | { |
| 8 | 77 | | if (property.NameEquals("@odata.type")) |
| | 78 | | { |
| 2 | 79 | | odataType = property.Value.GetString(); |
| 2 | 80 | | continue; |
| | 81 | | } |
| | 82 | |
|
| 6 | 83 | | if (property.NameEquals("name")) |
| | 84 | | { |
| 2 | 85 | | name = property.Value.GetString(); |
| 2 | 86 | | continue; |
| | 87 | | } |
| | 88 | |
|
| 4 | 89 | | if (property.NameEquals("bufferSize")) |
| | 90 | | { |
| 2 | 91 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 92 | | { |
| | 93 | | continue; |
| | 94 | | } |
| 2 | 95 | | bufferSize = property.Value.GetInt32(); |
| 2 | 96 | | continue; |
| | 97 | | } |
| | 98 | |
|
| 2 | 99 | | if (property.NameEquals("maxTokenLength")) |
| | 100 | | { |
| 2 | 101 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 102 | | { |
| | 103 | | continue; |
| | 104 | | } |
| 2 | 105 | | maxTokenLength = property.Value.GetInt32(); |
| | 106 | | continue; |
| | 107 | | } |
| | 108 | | } |
| | 109 | |
|
| 2 | 110 | | return new KeywordTokenizer(name) |
| 2 | 111 | | { |
| 2 | 112 | | ODataType = odataType, |
| 2 | 113 | | BufferSize = bufferSize, |
| 2 | 114 | | MaxTokenLength = maxTokenLength, |
| 2 | 115 | | }; |
| | 116 | | } |
| | 117 | | } |
| | 118 | | } |