| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System.Collections.Generic; |
| | 9 | | using System.Text.Json; |
| | 10 | | using Azure.Core; |
| | 11 | |
|
| | 12 | | namespace Azure.Search.Documents.Indexes.Models |
| | 13 | | { |
| | 14 | | public partial class ScoringProfile : IUtf8JsonSerializable |
| | 15 | | { |
| | 16 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 17 | | { |
| 6 | 18 | | writer.WriteStartObject(); |
| 6 | 19 | | writer.WritePropertyName("name"); |
| 6 | 20 | | writer.WriteStringValue(Name); |
| 6 | 21 | | if (Optional.IsDefined(TextWeights)) |
| | 22 | | { |
| 0 | 23 | | if (TextWeights != null) |
| | 24 | | { |
| 0 | 25 | | writer.WritePropertyName("text"); |
| 0 | 26 | | writer.WriteObjectValue(TextWeights); |
| | 27 | | } |
| | 28 | | else |
| | 29 | | { |
| 0 | 30 | | writer.WriteNull("text"); |
| | 31 | | } |
| | 32 | | } |
| 6 | 33 | | if (Optional.IsCollectionDefined(Functions)) |
| | 34 | | { |
| 6 | 35 | | writer.WritePropertyName("functions"); |
| 6 | 36 | | writer.WriteStartArray(); |
| 24 | 37 | | foreach (var item in Functions) |
| | 38 | | { |
| 6 | 39 | | writer.WriteObjectValue(item); |
| | 40 | | } |
| 6 | 41 | | writer.WriteEndArray(); |
| | 42 | | } |
| 6 | 43 | | if (Optional.IsDefined(FunctionAggregation)) |
| | 44 | | { |
| 6 | 45 | | writer.WritePropertyName("functionAggregation"); |
| 6 | 46 | | writer.WriteStringValue(FunctionAggregation.Value.ToSerialString()); |
| | 47 | | } |
| 6 | 48 | | writer.WriteEndObject(); |
| 6 | 49 | | } |
| | 50 | |
|
| | 51 | | internal static ScoringProfile DeserializeScoringProfile(JsonElement element) |
| | 52 | | { |
| 10 | 53 | | string name = default; |
| 10 | 54 | | Optional<TextWeights> text = default; |
| 10 | 55 | | Optional<IList<ScoringFunction>> functions = default; |
| 10 | 56 | | Optional<ScoringFunctionAggregation> functionAggregation = default; |
| 100 | 57 | | foreach (var property in element.EnumerateObject()) |
| | 58 | | { |
| 40 | 59 | | if (property.NameEquals("name")) |
| | 60 | | { |
| 10 | 61 | | name = property.Value.GetString(); |
| 10 | 62 | | continue; |
| | 63 | | } |
| 30 | 64 | | if (property.NameEquals("text")) |
| | 65 | | { |
| 10 | 66 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 67 | | { |
| 10 | 68 | | text = null; |
| 10 | 69 | | continue; |
| | 70 | | } |
| 0 | 71 | | text = TextWeights.DeserializeTextWeights(property.Value); |
| 0 | 72 | | continue; |
| | 73 | | } |
| 20 | 74 | | if (property.NameEquals("functions")) |
| | 75 | | { |
| 10 | 76 | | List<ScoringFunction> array = new List<ScoringFunction>(); |
| 40 | 77 | | foreach (var item in property.Value.EnumerateArray()) |
| | 78 | | { |
| 10 | 79 | | array.Add(ScoringFunction.DeserializeScoringFunction(item)); |
| | 80 | | } |
| 10 | 81 | | functions = array; |
| 10 | 82 | | continue; |
| | 83 | | } |
| 10 | 84 | | if (property.NameEquals("functionAggregation")) |
| | 85 | | { |
| 10 | 86 | | functionAggregation = property.Value.GetString().ToScoringFunctionAggregation(); |
| | 87 | | continue; |
| | 88 | | } |
| | 89 | | } |
| 10 | 90 | | return new ScoringProfile(name, text.Value, Optional.ToList(functions), Optional.ToNullable(functionAggregat |
| | 91 | | } |
| | 92 | | } |
| | 93 | | } |