Exemple #1
0
        internal static MagnitudeScoringFunction DeserializeMagnitudeScoringFunction(JsonElement element)
        {
            MagnitudeScoringParameters magnitude = default;
            string type      = default;
            string fieldName = default;
            double boost     = default;
            ScoringFunctionInterpolation?interpolation = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("magnitude"))
                {
                    magnitude = MagnitudeScoringParameters.DeserializeMagnitudeScoringParameters(property.Value);
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("fieldName"))
                {
                    fieldName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boost"))
                {
                    boost = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("interpolation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    interpolation = property.Value.GetString().ToScoringFunctionInterpolation();
                    continue;
                }
            }
            return(new MagnitudeScoringFunction(type, fieldName, boost, interpolation, magnitude));
        }
        internal static MagnitudeScoringFunction DeserializeMagnitudeScoringFunction(JsonElement element)
        {
            MagnitudeScoringFunction result = new MagnitudeScoringFunction();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("magnitude"))
                {
                    result.Parameters = MagnitudeScoringParameters.DeserializeMagnitudeScoringParameters(property.Value);
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    result.Type = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("fieldName"))
                {
                    result.FieldName = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("boost"))
                {
                    result.Boost = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("interpolation"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.Interpolation = property.Value.GetString().ToScoringFunctionInterpolation();
                    continue;
                }
            }
            return(result);
        }