From d2b26701fc2b29b030a3acc68be485704c15b1b9 Mon Sep 17 00:00:00 2001 From: Steve Gordon Date: Fri, 23 Apr 2021 05:54:46 +0100 Subject: [PATCH] Add positive_score_impact to rank_features property (#5607) (cherry picked from commit e2b2eda27bbc13d15a84e6cf9b1ce17085c97429) --- .../RankFeatures/RankFeaturesAttribute.cs | 11 ++++++++++ .../Core/RankFeatures/RankFeaturesProperty.cs | 20 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs b/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs index 6afd7af84f4..993ea7cc9b9 100644 --- a/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs +++ b/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs @@ -8,5 +8,16 @@ namespace Nest public class RankFeaturesAttribute : ElasticsearchPropertyAttributeBase, IRankFeaturesProperty { public RankFeaturesAttribute() : base(FieldType.RankFeatures) { } + + private IRankFeaturesProperty Self => this; + + /// + public bool PositiveScoreImpact + { + get => Self.PositiveScoreImpact.GetValueOrDefault(true); + set => Self.PositiveScoreImpact = value; + } + + bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; } } } diff --git a/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs b/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs index d28b691f672..c190824f09d 100644 --- a/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs +++ b/src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using Nest.Utf8Json; +using System.Runtime.Serialization; namespace Nest { @@ -15,20 +16,37 @@ namespace Nest [InterfaceDataContract] public interface IRankFeaturesProperty : IProperty { + /// + /// Rank features that correlate negatively with the score should set + /// to false (defaults to true). This will be used by the rank_features query to modify the scoring + /// formula in such a way that the score decreases with the value of the feature instead of + /// increasing. + /// + [DataMember(Name = "positive_score_impact")] + bool? PositiveScoreImpact { get; set; } } /// public class RankFeaturesProperty : PropertyBase, IRankFeaturesProperty { public RankFeaturesProperty() : base(FieldType.RankFeatures) { } + + /// + public bool? PositiveScoreImpact { get; set; } } /// - [DebuggerDisplay("{DebugDisplay}")] + [DebuggerDisplay("{" + nameof(DebugDisplay) + "}")] public class RankFeaturesPropertyDescriptor : PropertyDescriptorBase, IRankFeaturesProperty, T>, IRankFeaturesProperty where T : class { public RankFeaturesPropertyDescriptor() : base(FieldType.RankFeatures) { } + + bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; } + + /// + public RankFeaturesPropertyDescriptor PositiveScoreImpact(bool? positiveScoreImpact = true) => + Assign(positiveScoreImpact, (a, v) => a.PositiveScoreImpact = v); } }