| | 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 DistanceScoringFunction : IUtf8JsonSerializable |
| | 14 | | { |
| | 15 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 16 | | { |
| 6 | 17 | | writer.WriteStartObject(); |
| 6 | 18 | | writer.WritePropertyName("distance"); |
| 6 | 19 | | writer.WriteObjectValue(Parameters); |
| 6 | 20 | | writer.WritePropertyName("type"); |
| 6 | 21 | | writer.WriteStringValue(Type); |
| 6 | 22 | | writer.WritePropertyName("fieldName"); |
| 6 | 23 | | writer.WriteStringValue(FieldName); |
| 6 | 24 | | writer.WritePropertyName("boost"); |
| 6 | 25 | | writer.WriteNumberValue(Boost); |
| 6 | 26 | | if (Optional.IsDefined(Interpolation)) |
| | 27 | | { |
| 2 | 28 | | writer.WritePropertyName("interpolation"); |
| 2 | 29 | | writer.WriteStringValue(Interpolation.Value.ToSerialString()); |
| | 30 | | } |
| 6 | 31 | | writer.WriteEndObject(); |
| 6 | 32 | | } |
| | 33 | |
|
| | 34 | | internal static DistanceScoringFunction DeserializeDistanceScoringFunction(JsonElement element) |
| | 35 | | { |
| 10 | 36 | | DistanceScoringParameters distance = default; |
| 10 | 37 | | string type = default; |
| 10 | 38 | | string fieldName = default; |
| 10 | 39 | | double boost = default; |
| 10 | 40 | | Optional<ScoringFunctionInterpolation> interpolation = default; |
| 180 | 41 | | foreach (var property in element.EnumerateObject()) |
| | 42 | | { |
| 80 | 43 | | if (property.NameEquals("distance")) |
| | 44 | | { |
| 10 | 45 | | distance = DistanceScoringParameters.DeserializeDistanceScoringParameters(property.Value); |
| 10 | 46 | | continue; |
| | 47 | | } |
| 70 | 48 | | if (property.NameEquals("type")) |
| | 49 | | { |
| 10 | 50 | | type = property.Value.GetString(); |
| 10 | 51 | | continue; |
| | 52 | | } |
| 60 | 53 | | if (property.NameEquals("fieldName")) |
| | 54 | | { |
| 10 | 55 | | fieldName = property.Value.GetString(); |
| 10 | 56 | | continue; |
| | 57 | | } |
| 50 | 58 | | if (property.NameEquals("boost")) |
| | 59 | | { |
| 10 | 60 | | boost = property.Value.GetDouble(); |
| 10 | 61 | | continue; |
| | 62 | | } |
| 40 | 63 | | if (property.NameEquals("interpolation")) |
| | 64 | | { |
| 10 | 65 | | interpolation = property.Value.GetString().ToScoringFunctionInterpolation(); |
| | 66 | | continue; |
| | 67 | | } |
| | 68 | | } |
| 10 | 69 | | return new DistanceScoringFunction(type, fieldName, boost, Optional.ToNullable(interpolation), distance); |
| | 70 | | } |
| | 71 | | } |
| | 72 | | } |