|
| 1 | +using System.Diagnostics; |
| 2 | +using System.Runtime.Serialization; |
| 3 | +using Elasticsearch.Net.Utf8Json; |
| 4 | + |
| 5 | +namespace Nest |
| 6 | +{ |
| 7 | + /// <summary> |
| 8 | + /// A field that can index numbers so that they can later be used |
| 9 | + /// to boost documents in queries with a rank_feature query. |
| 10 | + /// </summary> |
| 11 | + [InterfaceDataContract] |
| 12 | + public interface IRankFeatureProperty : IProperty |
| 13 | + { |
| 14 | + /// <summary> |
| 15 | + /// Rank features that correlate negatively with the score should set <see cref="PositiveScoreImpact"/> |
| 16 | + /// to false (defaults to true). This will be used by the rank_feature query to modify the scoring |
| 17 | + /// formula in such a way that the score decreases with the value of the feature instead of |
| 18 | + /// increasing. For instance in web search, the url length is a commonly used feature |
| 19 | + /// which correlates negatively with scores. |
| 20 | + /// </summary> |
| 21 | + [DataMember(Name = "positive_score_impact")] |
| 22 | + bool? PositiveScoreImpact { get; set; } |
| 23 | + } |
| 24 | + |
| 25 | + /// <inheritdoc cref="IRankFeatureProperty" /> |
| 26 | + public class RankFeatureProperty : PropertyBase, IRankFeatureProperty |
| 27 | + { |
| 28 | + public RankFeatureProperty() : base(FieldType.RankFeature) { } |
| 29 | + |
| 30 | + /// <inheritdoc /> |
| 31 | + public bool? PositiveScoreImpact { get; set; } |
| 32 | + } |
| 33 | + |
| 34 | + /// <inheritdoc cref="IRankFeatureProperty" /> |
| 35 | + [DebuggerDisplay("{DebugDisplay}")] |
| 36 | + public class RankFeaturePropertyDescriptor<T> |
| 37 | + : PropertyDescriptorBase<RankFeaturePropertyDescriptor<T>, IRankFeatureProperty, T>, IRankFeatureProperty |
| 38 | + where T : class |
| 39 | + { |
| 40 | + public RankFeaturePropertyDescriptor() : base(FieldType.RankFeature) { } |
| 41 | + |
| 42 | + bool? IRankFeatureProperty.PositiveScoreImpact { get; set; } |
| 43 | + |
| 44 | + /// <inheritdoc cref="IRankFeatureProperty.PositiveScoreImpact" /> |
| 45 | + public RankFeaturePropertyDescriptor<T> PositiveScoreImpact(bool? positiveScoreImpact = true) => |
| 46 | + Assign(positiveScoreImpact, (a, v) => a.PositiveScoreImpact = v); |
| 47 | + } |
| 48 | +} |
0 commit comments