From 721ae316ca7e65d807b8d5e25cb0e52b810c00b2 Mon Sep 17 00:00:00 2001 From: gmarz Date: Mon, 4 May 2015 11:05:03 -0400 Subject: [PATCH] Add percentage and scripted heuristics to significant terms Closes #1339 --- .../SignificantTermsAggregationDescriptor.cs | 24 +++++++++++++ .../ISignificantTermsHeuristic.cs | 36 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs b/src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs index ae4175439f8..5141efc875e 100644 --- a/src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs +++ b/src/Nest/DSL/Aggregations/SignificantTermsAggregationDescriptor.cs @@ -40,6 +40,12 @@ public interface ISignificantTermsAggregator : IBucketAggregator [JsonProperty("gnd")] GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + [JsonProperty("percentage")] + PercentageScoreHeuristic PercentageScore { get; set; } + + [JsonProperty("script_heuristic")] + ScriptedHeuristic Script { get; set; } + [JsonProperty("background_filter")] IFilterContainer BackgroundFilter { get; set; } @@ -57,6 +63,8 @@ public class SignificantTermsAggregator : BucketAggregator, ISignificantTermsAgg public MutualInformationHeuristic MutualInformation { get; set; } public ChiSquareHeuristic ChiSquare { get; set; } public GoogleNormalizedDistanceHeuristic GoogleNormalizedDistance { get; set; } + public PercentageScoreHeuristic PercentageScore { get; set; } + public ScriptedHeuristic Script { get; set; } public IFilterContainer BackgroundFilter { get; set; } } @@ -84,6 +92,10 @@ public class SignificantTermsAggregationDescriptor : BucketAggregationBaseDes GoogleNormalizedDistanceHeuristic ISignificantTermsAggregator.GoogleNormalizedDistance { get; set; } + PercentageScoreHeuristic ISignificantTermsAggregator.PercentageScore { get; set; } + + ScriptedHeuristic ISignificantTermsAggregator.Script { get; set; } + IFilterContainer ISignificantTermsAggregator.BackgroundFilter { get; set; } public SignificantTermsAggregationDescriptor Field(string field) @@ -167,6 +179,18 @@ public SignificantTermsAggregationDescriptor GoogleNormalizedDistance(bool? b return this; } + public SignificantTermsAggregationDescriptor PercentageScore() + { + this.Self.PercentageScore = new PercentageScoreHeuristic(); + return this; + } + + public SignificantTermsAggregationDescriptor Script(Func scriptSelector) + { + this.Self.Script = scriptSelector(new ScriptedHeuristicDescriptor()).ScriptedHeuristic; + return this; + } + public SignificantTermsAggregationDescriptor BackgroundFilter(Func, FilterContainer> selector) { this.Self.BackgroundFilter = selector(new FilterDescriptor()); diff --git a/src/Nest/Domain/Aggregations/ISignificantTermsHeuristic.cs b/src/Nest/Domain/Aggregations/ISignificantTermsHeuristic.cs index 78af660bec9..6a8c4a6e8e1 100644 --- a/src/Nest/Domain/Aggregations/ISignificantTermsHeuristic.cs +++ b/src/Nest/Domain/Aggregations/ISignificantTermsHeuristic.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using System; namespace Nest { @@ -25,4 +26,39 @@ public class GoogleNormalizedDistanceHeuristic public bool? BackgroundIsSuperSet { get; set; } } + public class PercentageScoreHeuristic + { + } + + public class ScriptedHeuristic + { + [JsonProperty("script")] + public string Script { get; set; } + [JsonProperty("lang")] + public string Lang { get; set; } + [JsonProperty("params")] + public IDictionary Params { get; set; } + } + + public class ScriptedHeuristicDescriptor + { + internal ScriptedHeuristic ScriptedHeuristic = new ScriptedHeuristic(); + public ScriptedHeuristicDescriptor Script(string script) + { + this.ScriptedHeuristic.Script = script; + return this; + } + + public ScriptedHeuristicDescriptor Lang(string lang) + { + this.ScriptedHeuristic.Lang = lang; + return this; + } + + public ScriptedHeuristicDescriptor Params(Func, FluentDictionary> paramsSelector) + { + this.ScriptedHeuristic.Params = paramsSelector(new FluentDictionary()); + return this; + } + } } \ No newline at end of file