Skip to content

[Backport master] Add positive_score_impact to rank_features property #5614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,16 @@ namespace Nest
public class RankFeaturesAttribute : ElasticsearchPropertyAttributeBase, IRankFeaturesProperty
{
public RankFeaturesAttribute() : base(FieldType.RankFeatures) { }

private IRankFeaturesProperty Self => this;

/// <inheritdoc cref="IRankFeatureProperty.PositiveScoreImpact"/>
public bool PositiveScoreImpact
{
get => Self.PositiveScoreImpact.GetValueOrDefault(true);
set => Self.PositiveScoreImpact = value;
}

bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; }
}
}
20 changes: 19 additions & 1 deletion src/Nest/Mapping/Types/Core/RankFeatures/RankFeaturesProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Diagnostics;
using Nest.Utf8Json;
using System.Runtime.Serialization;

namespace Nest
{
Expand All @@ -15,20 +16,37 @@ namespace Nest
[InterfaceDataContract]
public interface IRankFeaturesProperty : IProperty
{
/// <summary>
/// Rank features that correlate negatively with the score should set <see cref="PositiveScoreImpact"/>
/// 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.
/// </summary>
[DataMember(Name = "positive_score_impact")]
bool? PositiveScoreImpact { get; set; }
}

/// <inheritdoc cref="IRankFeaturesProperty" />
public class RankFeaturesProperty : PropertyBase, IRankFeaturesProperty
{
public RankFeaturesProperty() : base(FieldType.RankFeatures) { }

/// <inheritdoc />
public bool? PositiveScoreImpact { get; set; }
}

/// <inheritdoc cref="IRankFeaturesProperty" />
[DebuggerDisplay("{DebugDisplay}")]
[DebuggerDisplay("{" + nameof(DebugDisplay) + "}")]
public class RankFeaturesPropertyDescriptor<T>
: PropertyDescriptorBase<RankFeaturesPropertyDescriptor<T>, IRankFeaturesProperty, T>, IRankFeaturesProperty
where T : class
{
public RankFeaturesPropertyDescriptor() : base(FieldType.RankFeatures) { }

bool? IRankFeaturesProperty.PositiveScoreImpact { get; set; }

/// <inheritdoc cref="IRankFeaturesProperty.PositiveScoreImpact" />
public RankFeaturesPropertyDescriptor<T> PositiveScoreImpact(bool? positiveScoreImpact = true) =>
Assign(positiveScoreImpact, (a, v) => a.PositiveScoreImpact = v);
}
}