| | | 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.Text.Json; |
| | | 9 | | using Azure.Core; |
| | | 10 | | |
| | | 11 | | namespace Azure.Search.Documents.Indexes.Models |
| | | 12 | | { |
| | | 13 | | public partial class ScoringFunction : IUtf8JsonSerializable |
| | | 14 | | { |
| | | 15 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | | 16 | | { |
| | 0 | 17 | | writer.WriteStartObject(); |
| | 0 | 18 | | writer.WritePropertyName("type"); |
| | 0 | 19 | | writer.WriteStringValue(Type); |
| | 0 | 20 | | writer.WritePropertyName("fieldName"); |
| | 0 | 21 | | writer.WriteStringValue(FieldName); |
| | 0 | 22 | | writer.WritePropertyName("boost"); |
| | 0 | 23 | | writer.WriteNumberValue(Boost); |
| | 0 | 24 | | if (Optional.IsDefined(Interpolation)) |
| | | 25 | | { |
| | 0 | 26 | | writer.WritePropertyName("interpolation"); |
| | 0 | 27 | | writer.WriteStringValue(Interpolation.Value.ToSerialString()); |
| | | 28 | | } |
| | 0 | 29 | | writer.WriteEndObject(); |
| | 0 | 30 | | } |
| | | 31 | | |
| | | 32 | | internal static ScoringFunction DeserializeScoringFunction(JsonElement element) |
| | | 33 | | { |
| | 10 | 34 | | if (element.TryGetProperty("type", out JsonElement discriminator)) |
| | | 35 | | { |
| | 10 | 36 | | switch (discriminator.GetString()) |
| | | 37 | | { |
| | 10 | 38 | | case "distance": return DistanceScoringFunction.DeserializeDistanceScoringFunction(element); |
| | 0 | 39 | | case "freshness": return FreshnessScoringFunction.DeserializeFreshnessScoringFunction(element); |
| | 0 | 40 | | case "magnitude": return MagnitudeScoringFunction.DeserializeMagnitudeScoringFunction(element); |
| | 0 | 41 | | case "tag": return TagScoringFunction.DeserializeTagScoringFunction(element); |
| | | 42 | | } |
| | | 43 | | } |
| | 0 | 44 | | string type = default; |
| | 0 | 45 | | string fieldName = default; |
| | 0 | 46 | | double boost = default; |
| | 0 | 47 | | Optional<ScoringFunctionInterpolation> interpolation = default; |
| | 0 | 48 | | foreach (var property in element.EnumerateObject()) |
| | | 49 | | { |
| | 0 | 50 | | if (property.NameEquals("type")) |
| | | 51 | | { |
| | 0 | 52 | | type = property.Value.GetString(); |
| | 0 | 53 | | continue; |
| | | 54 | | } |
| | 0 | 55 | | if (property.NameEquals("fieldName")) |
| | | 56 | | { |
| | 0 | 57 | | fieldName = property.Value.GetString(); |
| | 0 | 58 | | continue; |
| | | 59 | | } |
| | 0 | 60 | | if (property.NameEquals("boost")) |
| | | 61 | | { |
| | 0 | 62 | | boost = property.Value.GetDouble(); |
| | 0 | 63 | | continue; |
| | | 64 | | } |
| | 0 | 65 | | if (property.NameEquals("interpolation")) |
| | | 66 | | { |
| | 0 | 67 | | interpolation = property.Value.GetString().ToScoringFunctionInterpolation(); |
| | | 68 | | continue; |
| | | 69 | | } |
| | | 70 | | } |
| | 0 | 71 | | return new ScoringFunction(type, fieldName, boost, Optional.ToNullable(interpolation)); |
| | | 72 | | } |
| | | 73 | | } |
| | | 74 | | } |