Skip to content

Commit dee7e74

Browse files
authored
Add positive_score_impact to rank_features property (#5607) (#5614)
(cherry picked from commit e2b2eda)
1 parent a658109 commit dee7e74

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,16 @@ namespace Nest
88
public class RankFeaturesAttribute : ElasticsearchPropertyAttributeBase, IRankFeaturesProperty
99
{
1010
public RankFeaturesAttribute() : base(FieldType.RankFeatures) { }
11+
12+
private IRankFeaturesProperty Self => this;
13+
14+
/// <inheritdoc cref="IRankFeatureProperty.PositiveScoreImpact"/>
15+
public bool PositiveScoreImpact
16+
{
17+
get => Self.PositiveScoreImpact.GetValueOrDefault(true);
18+
set => Self.PositiveScoreImpact = value;
19+
}
20+
21+
bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; }
1122
}
1223
}

src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.Diagnostics;
66
using Nest.Utf8Json;
7+
using System.Runtime.Serialization;
78

89
namespace Nest
910
{
@@ -15,20 +16,37 @@ namespace Nest
1516
[InterfaceDataContract]
1617
public interface IRankFeaturesProperty : IProperty
1718
{
19+
/// <summary>
20+
/// Rank features that correlate negatively with the score should set <see cref="PositiveScoreImpact"/>
21+
/// to false (defaults to true). This will be used by the rank_features query to modify the scoring
22+
/// formula in such a way that the score decreases with the value of the feature instead of
23+
/// increasing.
24+
/// </summary>
25+
[DataMember(Name = "positive_score_impact")]
26+
bool? PositiveScoreImpact { get; set; }
1827
}
1928

2029
/// <inheritdoc cref="IRankFeaturesProperty" />
2130
public class RankFeaturesProperty : PropertyBase, IRankFeaturesProperty
2231
{
2332
public RankFeaturesProperty() : base(FieldType.RankFeatures) { }
33+
34+
/// <inheritdoc />
35+
public bool? PositiveScoreImpact { get; set; }
2436
}
2537

2638
/// <inheritdoc cref="IRankFeaturesProperty" />
27-
[DebuggerDisplay("{DebugDisplay}")]
39+
[DebuggerDisplay("{" + nameof(DebugDisplay) + "}")]
2840
public class RankFeaturesPropertyDescriptor<T>
2941
: PropertyDescriptorBase<RankFeaturesPropertyDescriptor<T>, IRankFeaturesProperty, T>, IRankFeaturesProperty
3042
where T : class
3143
{
3244
public RankFeaturesPropertyDescriptor() : base(FieldType.RankFeatures) { }
45+
46+
bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; }
47+
48+
/// <inheritdoc cref="IRankFeaturesProperty.PositiveScoreImpact" />
49+
public RankFeaturesPropertyDescriptor<T> PositiveScoreImpact(bool? positiveScoreImpact = true) =>
50+
Assign(positiveScoreImpact, (a, v) => a.PositiveScoreImpact = v);
3351
}
3452
}

0 commit comments

Comments
 (0)