Beispiel #1
0
        /// <summary> Initializes a new instance of FreshnessScoringFunction. </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 freshness 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 FreshnessScoringFunction(string fieldName, double boost, FreshnessScoringParameters parameters) : base(fieldName, boost)
        {
            Argument.AssertNotNullOrEmpty(fieldName, nameof(fieldName));
            Argument.AssertNotNull(parameters, nameof(parameters));

            Parameters = parameters;
            Type       = "freshness";
        }
        internal static FreshnessScoringFunction DeserializeFreshnessScoringFunction(JsonElement element)
        {
            FreshnessScoringParameters freshness = default;
            string type      = default;
            string fieldName = default;
            double boost     = default;
            Optional <ScoringFunctionInterpolation> interpolation = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("freshness"))
                {
                    freshness = FreshnessScoringParameters.DeserializeFreshnessScoringParameters(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)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    interpolation = property.Value.GetString().ToScoringFunctionInterpolation();
                    continue;
                }
            }
            return(new FreshnessScoringFunction(type, fieldName, boost, Optional.ToNullable(interpolation), freshness));
        }
Beispiel #3
0
 internal FreshnessScoringFunction(string type, string fieldName, double boost, ScoringFunctionInterpolation?interpolation, FreshnessScoringParameters parameters) : base(type, fieldName, boost, interpolation)
 {
     Parameters = parameters;
     Type       = type ?? "freshness";
 }