Skip to content
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

Use float? for suggester fractional properties #3661

Merged
merged 2 commits into from
Apr 12, 2019
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
6 changes: 5 additions & 1 deletion src/Nest/Mapping/Types/Specialized/Attachment/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

namespace Nest
{
/// <summary>
russcam marked this conversation as resolved.
Show resolved Hide resolved
/// An attachment indexed with an ingest pipeline using the ingest-attachment plugin.
/// Convenience class for working with attachment fields.
/// </summary>
[JsonFormatter(typeof(AttachmentFormatter))]
public class Attachment
{
/// <summary>
/// The author.
/// The author
/// </summary>
[DataMember(Name = "author")]
public string Author { get; set; }
Expand Down
18 changes: 14 additions & 4 deletions src/Nest/Search/Suggesters/CompletionSuggester/CompletionField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@
namespace Nest
{
/// <summary>
/// Convenience class for use when indexing completion fields.
/// A field mapped as an <see cref="ICompletionProperty" />. Convenience class to use when indexing completion
/// fields.
/// </summary>
public class CompletionField
{
[DataMember(Name ="contexts")]
/// <summary>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hate the hate on adding xmldocs but not fan of these style of SandCastle'esque summaries that feel generated. I rather have none instead.

Further more to continue my nitpick for small summaries can we have a single line

//// <summary> The summary </summary>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for small summaries can we have a single line

I can do this. We'll also need to tweak our formatting configuration which always seems to format on multiple lines

/// The contexts to associate with the input which can be used at query time to filter and boost suggestions
/// </summary>
[DataMember(Name = "contexts")]
public IDictionary<string, IEnumerable<string>> Contexts { get; set; }

[DataMember(Name ="input")]
/// <summary>
/// The input to store. Can be a single or multiple inputs
/// </summary>
[DataMember(Name = "input")]
public IEnumerable<string> Input { get; set; }

[DataMember(Name ="weight")]
/// <summary>
/// A positive integer which defines a weight and allows you to rank your suggestions. This field is optional.
/// </summary>
[DataMember(Name = "weight")]
public int? Weight { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

namespace Nest
{
/// <summary>
/// The completion suggester provides auto-complete/search-as-you-type functionality.
/// This is a navigational feature to guide users to relevant results as they are typing, improving search precision.
/// It is not meant for spell correction or did-you-mean functionality like the term or phrase suggesters.
/// </summary>
[InterfaceDataContract]
[ReadAs(typeof(CompletionSuggester))]
public interface ICompletionSuggester : ISuggester
Expand All @@ -19,7 +24,7 @@ public interface ICompletionSuggester : ISuggester
/// Support fuzziness for the suggestions
/// </summary>
[DataMember(Name = "fuzzy")]
IFuzzySuggester Fuzzy { get; set; }
ISuggestFuzziness Fuzzy { get; set; }

/// <summary>
/// Prefix used to search for suggestions
Expand All @@ -40,13 +45,14 @@ public interface ICompletionSuggester : ISuggester
bool? SkipDuplicates { get; set; }
}

/// <inheritdoc cref="ICompletionSuggester" />
public class CompletionSuggester : SuggesterBase, ICompletionSuggester
{
/// <inheritdoc />
public IDictionary<string, IList<ISuggestContextQuery>> Contexts { get; set; }

/// <inheritdoc />
public IFuzzySuggester Fuzzy { get; set; }
public ISuggestFuzziness Fuzzy { get; set; }

/// <inheritdoc />
public string Prefix { get; set; }
Expand All @@ -58,43 +64,34 @@ public class CompletionSuggester : SuggesterBase, ICompletionSuggester
public bool? SkipDuplicates { get; set; }
}

/// <inheritdoc cref="ICompletionSuggester" />
public class CompletionSuggesterDescriptor<T>
: SuggestDescriptorBase<CompletionSuggesterDescriptor<T>, ICompletionSuggester, T>, ICompletionSuggester
where T : class
{
IDictionary<string, IList<ISuggestContextQuery>> ICompletionSuggester.Contexts { get; set; }
IFuzzySuggester ICompletionSuggester.Fuzzy { get; set; }
ISuggestFuzziness ICompletionSuggester.Fuzzy { get; set; }
string ICompletionSuggester.Prefix { get; set; }
string ICompletionSuggester.Regex { get; set; }
bool? ICompletionSuggester.SkipDuplicates { get; set; }

/// <summary>
/// Prefix used to search for suggestions
/// </summary>
/// <inheritdoc cref="ICompletionSuggester.Prefix" />
public CompletionSuggesterDescriptor<T> Prefix(string prefix) => Assign(prefix, (a, v) => a.Prefix = v);

/// <summary>
/// Prefix as a regular expression used to search for suggestions
/// </summary>
/// <inheritdoc cref="ICompletionSuggester.Regex" />
public CompletionSuggesterDescriptor<T> Regex(string regex) => Assign(regex, (a, v) => a.Regex = v);

/// <summary>
/// Support fuzziness for the suggestions
/// </summary>
public CompletionSuggesterDescriptor<T> Fuzzy(Func<FuzzySuggestDescriptor<T>, IFuzzySuggester> selector = null) =>
Assign(selector.InvokeOrDefault(new FuzzySuggestDescriptor<T>()), (a, v) => a.Fuzzy = v);
/// <inheritdoc cref="ICompletionSuggester.Fuzzy" />
public CompletionSuggesterDescriptor<T> Fuzzy(Func<SuggestFuzzinessDescriptor<T>, ISuggestFuzziness> selector = null) =>
Assign(selector.InvokeOrDefault(new SuggestFuzzinessDescriptor<T>()), (a, v) => a.Fuzzy = v);

/// <summary>
/// Context mappings used to filter and/or boost suggestions
/// </summary>
/// <inheritdoc cref="ICompletionSuggester.Contexts" />
public CompletionSuggesterDescriptor<T> Contexts(
Func<SuggestContextQueriesDescriptor<T>, IPromise<IDictionary<string, IList<ISuggestContextQuery>>>> contexts
) =>
Assign(contexts, (a, v) => a.Contexts = v?.Invoke(new SuggestContextQueriesDescriptor<T>()).Value);

/// <summary>
/// Whether duplicate suggestions should be filtered out. Defaults to <c>false</c>
/// </summary>
/// <inheritdoc cref="ICompletionSuggester.SkipDuplicates" />
public CompletionSuggesterDescriptor<T> SkipDuplicates(bool? skipDuplicates = true) => Assign(skipDuplicates, (a, v) => a.SkipDuplicates = v);
}
}
54 changes: 0 additions & 54 deletions src/Nest/Search/Suggesters/CompletionSuggester/FuzzySuggest.cs

This file was deleted.

81 changes: 81 additions & 0 deletions src/Nest/Search/Suggesters/CompletionSuggester/SuggestFuzziness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using System.Runtime.Serialization;
using Elasticsearch.Net;

namespace Nest
{
/// <summary>
/// Fuzziness options for a suggester
/// </summary>
[InterfaceDataContract]
[ReadAs(typeof(SuggestFuzziness))]
public interface ISuggestFuzziness
{
/// <summary>
/// The fuzziness factor. defaults to AUTO
/// </summary>
[DataMember(Name = "fuzziness")]
IFuzziness Fuzziness { get; set; }

/// <summary>
/// Minimum length of the input before fuzzy suggestions are returned. Defaults to 3
/// </summary>
[DataMember(Name = "min_length")]
int? MinLength { get; set; }

/// <summary>
/// Minimum length of the input, which is not checked for fuzzy alternatives. Defaults to 1
/// </summary>
[DataMember(Name = "prefix_length")]
int? PrefixLength { get; set; }

/// <summary>
/// if set to true, transpositions are counted as one change instead of two. Defaults to true
/// </summary>
[DataMember(Name = "transpositions")]
bool? Transpositions { get; set; }

/// <summary>
/// If true, all measurements (like fuzzy edit distance, transpositions, and lengths) are measured in Unicode code
/// points instead of in bytes. This is slightly slower than raw bytes, so it is set to false by default.
/// </summary>
[DataMember(Name = "unicode_aware")]
bool? UnicodeAware { get; set; }
}

/// <inheritdoc />
public class SuggestFuzziness : ISuggestFuzziness
{
/// <inheritdoc />
public IFuzziness Fuzziness { get; set; }
/// <inheritdoc />
public int? MinLength { get; set; }
/// <inheritdoc />
public int? PrefixLength { get; set; }
/// <inheritdoc />
public bool? Transpositions { get; set; }
/// <inheritdoc />
public bool? UnicodeAware { get; set; }
}

/// <inheritdoc cref="ISuggestFuzziness" />
public class SuggestFuzzinessDescriptor<T> : DescriptorBase<SuggestFuzzinessDescriptor<T>, ISuggestFuzziness>, ISuggestFuzziness
where T : class
{
IFuzziness ISuggestFuzziness.Fuzziness { get; set; }
int? ISuggestFuzziness.MinLength { get; set; }
int? ISuggestFuzziness.PrefixLength { get; set; }
bool? ISuggestFuzziness.Transpositions { get; set; }
bool? ISuggestFuzziness.UnicodeAware { get; set; }

/// <inheritdoc cref="ISuggestFuzziness.Fuzziness" />
public SuggestFuzzinessDescriptor<T> Fuzziness(Fuzziness fuzziness) => Assign(fuzziness, (a, v) => a.Fuzziness = v);
/// <inheritdoc cref="ISuggestFuzziness.UnicodeAware" />
public SuggestFuzzinessDescriptor<T> UnicodeAware(bool? aware = true) => Assign(aware, (a, v) => a.UnicodeAware = v);
/// <inheritdoc cref="ISuggestFuzziness.Transpositions" />
public SuggestFuzzinessDescriptor<T> Transpositions(bool? transpositions = true) => Assign(transpositions, (a, v) => a.Transpositions = v);
/// <inheritdoc cref="ISuggestFuzziness.MinLength" />
public SuggestFuzzinessDescriptor<T> MinLength(int? length) => Assign(length, (a, v) => a.MinLength = v);
/// <inheritdoc cref="ISuggestFuzziness.PrefixLength" />
public SuggestFuzzinessDescriptor<T> PrefixLength(int? length) => Assign(length, (a, v) => a.PrefixLength = v);
}
}
24 changes: 12 additions & 12 deletions src/Nest/Search/Suggesters/PhraseSuggester/DirectGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public interface IDirectGenerator
int? MaxEdits { get; set; }

[DataMember(Name = "max_inspections")]
decimal? MaxInspections { get; set; }
float? MaxInspections { get; set; }

[DataMember(Name = "max_term_freq")]
decimal? MaxTermFrequency { get; set; }
float? MaxTermFrequency { get; set; }

[DataMember(Name = "min_doc_freq")]
decimal? MinDocFrequency { get; set; }
float? MinDocFrequency { get; set; }

[DataMember(Name = "min_word_length")]
int? MinWordLength { get; set; }
Expand All @@ -48,9 +48,9 @@ public class DirectGenerator : IDirectGenerator
{
public Field Field { get; set; }
public int? MaxEdits { get; set; }
public decimal? MaxInspections { get; set; }
public decimal? MaxTermFrequency { get; set; }
public decimal? MinDocFrequency { get; set; }
public float? MaxInspections { get; set; }
public float? MaxTermFrequency { get; set; }
public float? MinDocFrequency { get; set; }
public int? MinWordLength { get; set; }
public string PostFilter { get; set; }
public string PreFilter { get; set; }
Expand All @@ -64,9 +64,9 @@ public class DirectGeneratorDescriptor<T> : DescriptorBase<DirectGeneratorDescri
{
Field IDirectGenerator.Field { get; set; }
int? IDirectGenerator.MaxEdits { get; set; }
decimal? IDirectGenerator.MaxInspections { get; set; }
decimal? IDirectGenerator.MaxTermFrequency { get; set; }
decimal? IDirectGenerator.MinDocFrequency { get; set; }
float? IDirectGenerator.MaxInspections { get; set; }
float? IDirectGenerator.MaxTermFrequency { get; set; }
float? IDirectGenerator.MinDocFrequency { get; set; }
int? IDirectGenerator.MinWordLength { get; set; }
string IDirectGenerator.PostFilter { get; set; }
string IDirectGenerator.PreFilter { get; set; }
Expand All @@ -88,11 +88,11 @@ public class DirectGeneratorDescriptor<T> : DescriptorBase<DirectGeneratorDescri

public DirectGeneratorDescriptor<T> MaxEdits(int? maxEdits) => Assign(maxEdits, (a, v) => a.MaxEdits = v);

public DirectGeneratorDescriptor<T> MaxInspections(decimal? maxInspections) => Assign(maxInspections, (a, v) => a.MaxInspections = v);
public DirectGeneratorDescriptor<T> MaxInspections(float? maxInspections) => Assign(maxInspections, (a, v) => a.MaxInspections = v);

public DirectGeneratorDescriptor<T> MinDocFrequency(decimal? frequency) => Assign(frequency, (a, v) => a.MinDocFrequency = v);
public DirectGeneratorDescriptor<T> MinDocFrequency(float? frequency) => Assign(frequency, (a, v) => a.MinDocFrequency = v);

public DirectGeneratorDescriptor<T> MaxTermFrequency(decimal? frequency) => Assign(frequency, (a, v) => a.MaxTermFrequency = v);
public DirectGeneratorDescriptor<T> MaxTermFrequency(float? frequency) => Assign(frequency, (a, v) => a.MaxTermFrequency = v);

public DirectGeneratorDescriptor<T> PreFilter(string preFilter) => Assign(preFilter, (a, v) => a.PreFilter = v);

Expand Down
19 changes: 5 additions & 14 deletions src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,25 @@ public class PhraseSuggestCollate : IPhraseSuggestCollate
public IPhraseSuggestCollateQuery Query { get; set; }
}

/// <inheritdoc cref="IPhraseSuggestCollate" />
public class PhraseSuggestCollateDescriptor<T> : DescriptorBase<PhraseSuggestCollateDescriptor<T>, IPhraseSuggestCollate>, IPhraseSuggestCollate
where T : class
{
IDictionary<string, object> IPhraseSuggestCollate.Params { get; set; }
bool? IPhraseSuggestCollate.Prune { get; set; }
IPhraseSuggestCollateQuery IPhraseSuggestCollate.Query { get; set; }

/// <summary>
/// The collate query to run
/// </summary>
/// <inheritdoc cref="IPhraseSuggestCollate.Query" />
public PhraseSuggestCollateDescriptor<T> Query(Func<PhraseSuggestCollateQueryDescriptor, IPhraseSuggestCollateQuery> selector) =>
Assign(selector, (a, v) => a.Query = v?.Invoke(new PhraseSuggestCollateQueryDescriptor()));

/// <summary>
/// Controls if all phrase suggestions will be returned. When set to <c>true</c>, the suggestions will have
/// an additional option collate_match, which will be <c>true</c> if matching documents for the phrase was found,
/// <c>false</c> otherwise. The default value for <see cref="Prune" /> is <c>false</c>.
/// </summary>
/// <inheritdoc cref="IPhraseSuggestCollate.Prune" />
public PhraseSuggestCollateDescriptor<T> Prune(bool? prune = true) => Assign(prune, (a, v) => a.Prune = v);

/// <summary>
/// The parameters for the query. the suggestion value will be added to the variables you specify.
/// </summary>
/// <inheritdoc cref="IPhraseSuggestCollate.Params" />
public PhraseSuggestCollateDescriptor<T> Params(IDictionary<string, object> paramsDictionary) => Assign(paramsDictionary, (a, v) => a.Params = v);

/// <summary>
/// The parameters for the query. the suggestion value will be added to the variables you specify.
/// </summary>
/// <inheritdoc cref="IPhraseSuggestCollate.Params" />
public PhraseSuggestCollateDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) =>
Assign(paramsDictionary(new FluentDictionary<string, object>()), (a, v) => a.Params = v);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public class PhraseSuggestCollateQuery : IPhraseSuggestCollateQuery
public string Source { get; set; }
}

/// <inheritdoc />
/// <inheritdoc cref="IPhraseSuggestCollateQuery" />
public class PhraseSuggestCollateQueryDescriptor
: DescriptorBase<PhraseSuggestCollateQueryDescriptor, IPhraseSuggestCollateQuery>, IPhraseSuggestCollateQuery
{
Id IPhraseSuggestCollateQuery.Id { get; set; }
string IPhraseSuggestCollateQuery.Source { get; set; }

/// <inheritdoc />
/// <inheritdoc cref="IPhraseSuggestCollateQuery.Source" />
public PhraseSuggestCollateQueryDescriptor Source(string source) => Assign(source, (a, v) => a.Source = v);

/// <inheritdoc />
/// <inheritdoc cref="IPhraseSuggestCollateQuery.Id" />
public PhraseSuggestCollateQueryDescriptor Id(Id id) => Assign(id, (a, v) => a.Id = v);
}
}
Loading