Ejemplo n.º 1
0
        internal static MagnitudeScoringParameters DeserializeMagnitudeScoringParameters(JsonElement element)
        {
            MagnitudeScoringParameters result = new MagnitudeScoringParameters();

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("boostingRangeStart"))
                {
                    result.BoostingRangeStart = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("boostingRangeEnd"))
                {
                    result.BoostingRangeEnd = property.Value.GetDouble();
                    continue;
                }
                if (property.NameEquals("constantBoostBeyondRange"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        continue;
                    }
                    result.ShouldBoostBeyondRangeByConstant = property.Value.GetBoolean();
                    continue;
                }
            }
            return(result);
        }
        /// <summary> Initializes a new instance of MagnitudeScoringFunction. </summary>
        /// <param name="fieldName"> The name of the field used as input to the scoring function. </param>
        /// <param name="boost"> A multiplier for the raw score. Must be a positive number not equal to 1.0. </param>
        /// <param name="parameters"> Parameter values for the magnitude scoring function. </param>
        /// <exception cref="ArgumentException"><paramref name="fieldName"/> is an empty string.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="fieldName"/> or <paramref name="parameters"/> is null.</exception>
        public MagnitudeScoringFunction(string fieldName, double boost, MagnitudeScoringParameters parameters) : base(fieldName, boost)
        {
            Argument.AssertNotNullOrEmpty(fieldName, nameof(fieldName));
            Argument.AssertNotNull(parameters, nameof(parameters));

            Parameters = parameters;
            Type       = "magnitude";
        }
Ejemplo n.º 3
0
        public MagnitudeScoringFunction(MagnitudeScoringParameters parameters, string fieldName, double boost) : base(fieldName, boost)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }
            if (fieldName == null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            Parameters = parameters;
            Type       = "magnitude";
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 6
0
 internal MagnitudeScoringFunction(MagnitudeScoringParameters parameters, string type, string fieldName, double boost, ScoringFunctionInterpolation?interpolation) : base(type, fieldName, boost, interpolation)
 {
     Parameters = parameters;
     Type       = type ?? "magnitude";
 }