Skip to content
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 @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System.Diagnostics;
using System.Runtime.Serialization;
using Elasticsearch.Net.Utf8Json;

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);
}
}