-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Suggester fixes #2548
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
Suggester fixes #2548
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Nest/Search/Suggesters/PhraseSuggester/SmoothingModel/LaplaceSmoothingModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...est/Search/Suggesters/PhraseSuggester/SmoothingModel/LinearInterpolationSmoothingModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Nest/Search/Suggesters/PhraseSuggester/SmoothingModel/SmoothingModelBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Nest/Search/Suggesters/PhraseSuggester/SmoothingModel/SmoothingModelContainer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Nest/Search/Suggesters/PhraseSuggester/SmoothingModel/StupidBackoffSmoothingModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 nice