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
4 changes: 2 additions & 2 deletions docs/aggregations/reserved-agg-names.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/master
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/2.3

:github: https://github.com/elastic/elasticsearch-net

Expand All @@ -7,7 +7,7 @@
////
IMPORTANT NOTE
==============
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/master/src/Tests/Aggregations/ReservedAggNames.doc.cs.
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/2.x/src/Tests/Aggregations/ReservedAggNames.doc.cs.
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,
please modify the original csharp file found at the link and submit the PR with that change. Thanks!
////
Expand Down
5 changes: 5 additions & 0 deletions src/Nest/Nest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,11 @@
<Compile Include="Search\Suggesters\PhraseSuggester\PhraseSuggestCollate.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\PhraseSuggester.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\PhraseSuggestHighlight.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\SmoothingModel\LaplaceSmoothingModel.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\SmoothingModel\LinearInterpolationSmoothingModel.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\SmoothingModel\SmoothingModelBase.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\SmoothingModel\SmoothingModelContainer.cs" />
<Compile Include="Search\Suggesters\PhraseSuggester\SmoothingModel\StupidBackoffSmoothingModel.cs" />
<Compile Include="Search\Suggesters\Suggest.cs" />
<Compile Include="Search\Suggesters\SuggestBucket.cs" />
<Compile Include="Search\Suggesters\SuggestContainer.cs" />
Expand Down
10 changes: 9 additions & 1 deletion src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public interface IPhraseSuggester : ISuggester

[JsonProperty(PropertyName = "collate")]
IPhraseSuggestCollate Collate { get; set; }

[JsonProperty("smoothing")]
SmoothingModelContainer Smoothing { get; set; }
}

public class PhraseSuggester : SuggesterBase, IPhraseSuggester
Expand All @@ -44,6 +47,7 @@ public class PhraseSuggester : SuggesterBase, IPhraseSuggester
public IEnumerable<IDirectGenerator> DirectGenerator { get; set; }
public IPhraseSuggestHighlight Highlight { get; set; }
public IPhraseSuggestCollate Collate { get; set; }
public SmoothingModelContainer Smoothing { get; set; }
}

public class PhraseSuggesterDescriptor<T> : SuggestDescriptorBase<PhraseSuggesterDescriptor<T>, IPhraseSuggester, T>, IPhraseSuggester
Expand All @@ -57,6 +61,7 @@ public class PhraseSuggesterDescriptor<T> : SuggestDescriptorBase<PhraseSuggeste
IEnumerable<IDirectGenerator> IPhraseSuggester.DirectGenerator { get; set; }
IPhraseSuggestHighlight IPhraseSuggester.Highlight { get; set; }
IPhraseSuggestCollate IPhraseSuggester.Collate { get; set; }
SmoothingModelContainer IPhraseSuggester.Smoothing { get; set; }

public PhraseSuggesterDescriptor<T> GramSize(int? gramSize) => Assign(a => a.GramSize = gramSize);

Expand All @@ -69,13 +74,16 @@ public class PhraseSuggesterDescriptor<T> : SuggestDescriptorBase<PhraseSuggeste
public PhraseSuggesterDescriptor<T> DirectGenerator(params Func<DirectGeneratorDescriptor<T>, IDirectGenerator>[] generators) =>
Assign(a=>a.DirectGenerator = generators.Select(g => g(new DirectGeneratorDescriptor<T>())).ToList());

public PhraseSuggesterDescriptor<T> RealWordErrorLikelihood(double? realWordErrorLikelihood) =>
public PhraseSuggesterDescriptor<T> RealWordErrorLikelihood(double? realWordErrorLikelihood) =>
Assign(a => a.RealWordErrorLikelihood = realWordErrorLikelihood);

public PhraseSuggesterDescriptor<T> Highlight(Func<PhraseSuggestHighlightDescriptor, IPhraseSuggestHighlight> selector) =>
Assign(a=> a.Highlight = selector?.Invoke(new PhraseSuggestHighlightDescriptor()));

public PhraseSuggesterDescriptor<T> Collate(Func<PhraseSuggestCollateDescriptor<T>, IPhraseSuggestCollate> selector) =>
Assign(a => a.Collate = selector?.Invoke(new PhraseSuggestCollateDescriptor<T>()));

public PhraseSuggesterDescriptor<T> Smoothing(Func<SmoothingModelContainerDescriptor, SmoothingModelContainer> selector) =>
Assign(a => a.Smoothing = selector?.Invoke(new SmoothingModelContainerDescriptor()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;

namespace Nest
{
[JsonObject]
[JsonConverter(typeof(ReadAsTypeJsonConverter<LaplaceSmoothingModel>))]
public interface ILaplaceSmoothingModel : ISmoothingModel
{
[JsonProperty("alpha")]
double? Alpha { get; set; }
}

public class LaplaceSmoothingModel : SmoothingModelBase, ILaplaceSmoothingModel
{
public double? Alpha { get; set; }

internal override void WrapInContainer(ISmoothingModelContainer container) => container.Laplace = this;
}

public class LaplaceSmoothingModelDescriptor : DescriptorBase<LaplaceSmoothingModelDescriptor, ILaplaceSmoothingModel>, ILaplaceSmoothingModel
{
double? ILaplaceSmoothingModel.Alpha{ get; set; }

public LaplaceSmoothingModelDescriptor Alpha(double? alpha) => Assign(a => a.Alpha = alpha);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Newtonsoft.Json;
using System;

namespace Nest
{
[JsonObject]
[JsonConverter(typeof(ReadAsTypeJsonConverter<LinearInterpolationSmoothingModel>))]
public interface ILinearInterpolationSmoothingModel : ISmoothingModel
{
[JsonProperty("trigram_lambda")]
double TrigramLambda { get; set; }
[JsonProperty("bigram_lambda")]
double BigramLambda { get; set; }
[JsonProperty("unigram_lambda")]
double UnigramLambda { get; set; }
}

public class LinearInterpolationSmoothingModel : SmoothingModelBase, ILinearInterpolationSmoothingModel
{
public double TrigramLambda { get; set; }
public double BigramLambda { get; set; }
public double UnigramLambda { get; set; }

internal override void WrapInContainer(ISmoothingModelContainer container) => container.LinearInterpolation = this;
}

public class LinearInterpolationSmoothingModelDescriptor : DescriptorBase<LinearInterpolationSmoothingModelDescriptor, ILinearInterpolationSmoothingModel>, ILinearInterpolationSmoothingModel
{
double ILinearInterpolationSmoothingModel.TrigramLambda { get; set; }
double ILinearInterpolationSmoothingModel.UnigramLambda { get; set; }
double ILinearInterpolationSmoothingModel.BigramLambda { get; set; }

public LinearInterpolationSmoothingModelDescriptor TrigramLambda(double lambda) => Assign(a => a.TrigramLambda = lambda);
public LinearInterpolationSmoothingModelDescriptor UnigramLambda(double lambda) => Assign(a => a.UnigramLambda = lambda);
public LinearInterpolationSmoothingModelDescriptor BigramLambda(double lambda) => Assign(a => a.BigramLambda = lambda);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace Nest
{
[JsonObject]
public interface ISmoothingModel {}

public abstract class SmoothingModelBase
{
public static implicit operator SmoothingModelContainer(SmoothingModelBase model) => model == null
? null
: new SmoothingModelContainer(model);

internal abstract void WrapInContainer(ISmoothingModelContainer container);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Newtonsoft.Json;

namespace Nest
{
[JsonObject(MemberSerialization.OptIn)]
[JsonConverter(typeof(ReserializeJsonConverter<SmoothingModelContainer, ISmoothingModelContainer>))]
public interface ISmoothingModelContainer
{
[JsonProperty("stupid_backoff")]
IStupidBackoffSmoothingModel StupidBackoff { get; set; }

[JsonProperty("laplace")]
ILaplaceSmoothingModel Laplace { get; set; }

[JsonProperty("linear_interpolation")]
ILinearInterpolationSmoothingModel LinearInterpolation { get; set; }
}

[JsonObject(MemberSerialization.OptIn)]
public class SmoothingModelContainer : ISmoothingModelContainer, IDescriptor
{
internal SmoothingModelContainer() {}

public SmoothingModelContainer(SmoothingModelBase model)
{
model.ThrowIfNull(nameof(model));
model.WrapInContainer(this);
}

IStupidBackoffSmoothingModel ISmoothingModelContainer.StupidBackoff { get; set; }
ILaplaceSmoothingModel ISmoothingModelContainer.Laplace { get; set; }
ILinearInterpolationSmoothingModel ISmoothingModelContainer.LinearInterpolation { get; set; }
}

public class SmoothingModelContainerDescriptor : SmoothingModelContainer
{
private SmoothingModelContainerDescriptor Assign(Action<ISmoothingModelContainer> assigner) => Fluent.Assign(this, assigner);

public SmoothingModelContainerDescriptor StupidBackoff(Func<StupidBackoffSmoothingModelDescriptor, IStupidBackoffSmoothingModel> selector) =>
Assign(a => a.StupidBackoff = selector?.InvokeOrDefault(new StupidBackoffSmoothingModelDescriptor()));

public SmoothingModelContainerDescriptor LinearInterpolation(Func<LinearInterpolationSmoothingModelDescriptor, ILinearInterpolationSmoothingModel> selector) =>
Assign(a => a.LinearInterpolation = selector?.InvokeOrDefault(new LinearInterpolationSmoothingModelDescriptor()));

public SmoothingModelContainerDescriptor Laplace(Func<LaplaceSmoothingModelDescriptor, ILaplaceSmoothingModel> selector) =>
Assign(a => a.Laplace = selector?.InvokeOrDefault(new LaplaceSmoothingModelDescriptor()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Newtonsoft.Json;
using System;

namespace Nest
{
[JsonObject]
[JsonConverter(typeof(ReadAsTypeJsonConverter<StupidBackoffSmoothingModel>))]
public interface IStupidBackoffSmoothingModel : ISmoothingModel
{
[JsonProperty("discount")]
double? Discount { get; set; }
}

public class StupidBackoffSmoothingModel : SmoothingModelBase, IStupidBackoffSmoothingModel
{
public double? Discount { get; set; }

internal override void WrapInContainer(ISmoothingModelContainer container) => container.StupidBackoff = this;
}

public class StupidBackoffSmoothingModelDescriptor : DescriptorBase<StupidBackoffSmoothingModelDescriptor, IStupidBackoffSmoothingModel>, IStupidBackoffSmoothingModel
{
double? IStupidBackoffSmoothingModel.Discount{ get; set; }

public StupidBackoffSmoothingModelDescriptor Discount(double? discount) => Assign(a => a.Discount = discount);
}
}
1 change: 1 addition & 0 deletions src/Tests/CodeStandards/Descriptors.doc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ where t.IsClass() && typeof(IDescriptor).IsAssignableFrom(t)
{ typeof(TriggerDescriptor), typeof(TriggerContainer) },
{ typeof(TransformDescriptor), typeof(TransformContainer) },
{ typeof(InputDescriptor), typeof(InputContainer) },
{ typeof(SmoothingModelContainerDescriptor), typeof(SmoothingModelContainer) },
{ typeof(FluentDictionary<,>), typeof(FluentDictionary<,>) }
};

Expand Down