Skip to content

Commit 444856c

Browse files
authored
Use float? for suggester fractional properties (#3661)
This commit updates TermSuggester to use float? instead of decimal? for properties that take a float value. Add XML documentation to suggesters
1 parent ad8ba6a commit 444856c

File tree

17 files changed

+390
-156
lines changed

17 files changed

+390
-156
lines changed

src/Nest/Mapping/Types/Specialized/Attachment/Attachment.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55

66
namespace Nest
77
{
8+
/// <summary>
9+
/// An attachment indexed with an ingest pipeline using the ingest-attachment plugin.
10+
/// Convenience class for working with attachment fields.
11+
/// </summary>
812
[JsonFormatter(typeof(AttachmentFormatter))]
913
public class Attachment
1014
{
1115
/// <summary>
12-
/// The author.
16+
/// The author
1317
/// </summary>
1418
[DataMember(Name = "author")]
1519
public string Author { get; set; }

src/Nest/Search/Suggesters/CompletionSuggester/CompletionField.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,27 @@
44
namespace Nest
55
{
66
/// <summary>
7-
/// Convenience class for use when indexing completion fields.
7+
/// A field mapped as an <see cref="ICompletionProperty" />. Convenience class to use when indexing completion
8+
/// fields.
89
/// </summary>
910
public class CompletionField
1011
{
11-
[DataMember(Name ="contexts")]
12+
/// <summary>
13+
/// The contexts to associate with the input which can be used at query time to filter and boost suggestions
14+
/// </summary>
15+
[DataMember(Name = "contexts")]
1216
public IDictionary<string, IEnumerable<string>> Contexts { get; set; }
1317

14-
[DataMember(Name ="input")]
18+
/// <summary>
19+
/// The input to store. Can be a single or multiple inputs
20+
/// </summary>
21+
[DataMember(Name = "input")]
1522
public IEnumerable<string> Input { get; set; }
1623

17-
[DataMember(Name ="weight")]
24+
/// <summary>
25+
/// A positive integer which defines a weight and allows you to rank your suggestions. This field is optional.
26+
/// </summary>
27+
[DataMember(Name = "weight")]
1828
public int? Weight { get; set; }
1929
}
2030
}

src/Nest/Search/Suggesters/CompletionSuggester/CompletionSuggester.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

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

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

48+
/// <inheritdoc cref="ICompletionSuggester" />
4349
public class CompletionSuggester : SuggesterBase, ICompletionSuggester
4450
{
4551
/// <inheritdoc />
4652
public IDictionary<string, IList<ISuggestContextQuery>> Contexts { get; set; }
4753

4854
/// <inheritdoc />
49-
public IFuzzySuggester Fuzzy { get; set; }
55+
public ISuggestFuzziness Fuzzy { get; set; }
5056

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

67+
/// <inheritdoc cref="ICompletionSuggester" />
6168
public class CompletionSuggesterDescriptor<T>
6269
: SuggestDescriptorBase<CompletionSuggesterDescriptor<T>, ICompletionSuggester, T>, ICompletionSuggester
6370
where T : class
6471
{
6572
IDictionary<string, IList<ISuggestContextQuery>> ICompletionSuggester.Contexts { get; set; }
66-
IFuzzySuggester ICompletionSuggester.Fuzzy { get; set; }
73+
ISuggestFuzziness ICompletionSuggester.Fuzzy { get; set; }
6774
string ICompletionSuggester.Prefix { get; set; }
6875
string ICompletionSuggester.Regex { get; set; }
6976
bool? ICompletionSuggester.SkipDuplicates { get; set; }
7077

71-
/// <summary>
72-
/// Prefix used to search for suggestions
73-
/// </summary>
78+
/// <inheritdoc cref="ICompletionSuggester.Prefix" />
7479
public CompletionSuggesterDescriptor<T> Prefix(string prefix) => Assign(prefix, (a, v) => a.Prefix = v);
7580

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

81-
/// <summary>
82-
/// Support fuzziness for the suggestions
83-
/// </summary>
84-
public CompletionSuggesterDescriptor<T> Fuzzy(Func<FuzzySuggestDescriptor<T>, IFuzzySuggester> selector = null) =>
85-
Assign(selector.InvokeOrDefault(new FuzzySuggestDescriptor<T>()), (a, v) => a.Fuzzy = v);
84+
/// <inheritdoc cref="ICompletionSuggester.Fuzzy" />
85+
public CompletionSuggesterDescriptor<T> Fuzzy(Func<SuggestFuzzinessDescriptor<T>, ISuggestFuzziness> selector = null) =>
86+
Assign(selector.InvokeOrDefault(new SuggestFuzzinessDescriptor<T>()), (a, v) => a.Fuzzy = v);
8687

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

95-
/// <summary>
96-
/// Whether duplicate suggestions should be filtered out. Defaults to <c>false</c>
97-
/// </summary>
94+
/// <inheritdoc cref="ICompletionSuggester.SkipDuplicates" />
9895
public CompletionSuggesterDescriptor<T> SkipDuplicates(bool? skipDuplicates = true) => Assign(skipDuplicates, (a, v) => a.SkipDuplicates = v);
9996
}
10097
}

src/Nest/Search/Suggesters/CompletionSuggester/FuzzySuggest.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Runtime.Serialization;
2+
using Elasticsearch.Net;
3+
4+
namespace Nest
5+
{
6+
/// <summary>
7+
/// Fuzziness options for a suggester
8+
/// </summary>
9+
[InterfaceDataContract]
10+
[ReadAs(typeof(SuggestFuzziness))]
11+
public interface ISuggestFuzziness
12+
{
13+
/// <summary>
14+
/// The fuzziness factor. defaults to AUTO
15+
/// </summary>
16+
[DataMember(Name = "fuzziness")]
17+
IFuzziness Fuzziness { get; set; }
18+
19+
/// <summary>
20+
/// Minimum length of the input before fuzzy suggestions are returned. Defaults to 3
21+
/// </summary>
22+
[DataMember(Name = "min_length")]
23+
int? MinLength { get; set; }
24+
25+
/// <summary>
26+
/// Minimum length of the input, which is not checked for fuzzy alternatives. Defaults to 1
27+
/// </summary>
28+
[DataMember(Name = "prefix_length")]
29+
int? PrefixLength { get; set; }
30+
31+
/// <summary>
32+
/// if set to true, transpositions are counted as one change instead of two. Defaults to true
33+
/// </summary>
34+
[DataMember(Name = "transpositions")]
35+
bool? Transpositions { get; set; }
36+
37+
/// <summary>
38+
/// If true, all measurements (like fuzzy edit distance, transpositions, and lengths) are measured in Unicode code
39+
/// points instead of in bytes. This is slightly slower than raw bytes, so it is set to false by default.
40+
/// </summary>
41+
[DataMember(Name = "unicode_aware")]
42+
bool? UnicodeAware { get; set; }
43+
}
44+
45+
/// <inheritdoc />
46+
public class SuggestFuzziness : ISuggestFuzziness
47+
{
48+
/// <inheritdoc />
49+
public IFuzziness Fuzziness { get; set; }
50+
/// <inheritdoc />
51+
public int? MinLength { get; set; }
52+
/// <inheritdoc />
53+
public int? PrefixLength { get; set; }
54+
/// <inheritdoc />
55+
public bool? Transpositions { get; set; }
56+
/// <inheritdoc />
57+
public bool? UnicodeAware { get; set; }
58+
}
59+
60+
/// <inheritdoc cref="ISuggestFuzziness" />
61+
public class SuggestFuzzinessDescriptor<T> : DescriptorBase<SuggestFuzzinessDescriptor<T>, ISuggestFuzziness>, ISuggestFuzziness
62+
where T : class
63+
{
64+
IFuzziness ISuggestFuzziness.Fuzziness { get; set; }
65+
int? ISuggestFuzziness.MinLength { get; set; }
66+
int? ISuggestFuzziness.PrefixLength { get; set; }
67+
bool? ISuggestFuzziness.Transpositions { get; set; }
68+
bool? ISuggestFuzziness.UnicodeAware { get; set; }
69+
70+
/// <inheritdoc cref="ISuggestFuzziness.Fuzziness" />
71+
public SuggestFuzzinessDescriptor<T> Fuzziness(Fuzziness fuzziness) => Assign(fuzziness, (a, v) => a.Fuzziness = v);
72+
/// <inheritdoc cref="ISuggestFuzziness.UnicodeAware" />
73+
public SuggestFuzzinessDescriptor<T> UnicodeAware(bool? aware = true) => Assign(aware, (a, v) => a.UnicodeAware = v);
74+
/// <inheritdoc cref="ISuggestFuzziness.Transpositions" />
75+
public SuggestFuzzinessDescriptor<T> Transpositions(bool? transpositions = true) => Assign(transpositions, (a, v) => a.Transpositions = v);
76+
/// <inheritdoc cref="ISuggestFuzziness.MinLength" />
77+
public SuggestFuzzinessDescriptor<T> MinLength(int? length) => Assign(length, (a, v) => a.MinLength = v);
78+
/// <inheritdoc cref="ISuggestFuzziness.PrefixLength" />
79+
public SuggestFuzzinessDescriptor<T> PrefixLength(int? length) => Assign(length, (a, v) => a.PrefixLength = v);
80+
}
81+
}

src/Nest/Search/Suggesters/PhraseSuggester/DirectGenerator.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public interface IDirectGenerator
1616
int? MaxEdits { get; set; }
1717

1818
[DataMember(Name = "max_inspections")]
19-
decimal? MaxInspections { get; set; }
19+
float? MaxInspections { get; set; }
2020

2121
[DataMember(Name = "max_term_freq")]
22-
decimal? MaxTermFrequency { get; set; }
22+
float? MaxTermFrequency { get; set; }
2323

2424
[DataMember(Name = "min_doc_freq")]
25-
decimal? MinDocFrequency { get; set; }
25+
float? MinDocFrequency { get; set; }
2626

2727
[DataMember(Name = "min_word_length")]
2828
int? MinWordLength { get; set; }
@@ -48,9 +48,9 @@ public class DirectGenerator : IDirectGenerator
4848
{
4949
public Field Field { get; set; }
5050
public int? MaxEdits { get; set; }
51-
public decimal? MaxInspections { get; set; }
52-
public decimal? MaxTermFrequency { get; set; }
53-
public decimal? MinDocFrequency { get; set; }
51+
public float? MaxInspections { get; set; }
52+
public float? MaxTermFrequency { get; set; }
53+
public float? MinDocFrequency { get; set; }
5454
public int? MinWordLength { get; set; }
5555
public string PostFilter { get; set; }
5656
public string PreFilter { get; set; }
@@ -64,9 +64,9 @@ public class DirectGeneratorDescriptor<T> : DescriptorBase<DirectGeneratorDescri
6464
{
6565
Field IDirectGenerator.Field { get; set; }
6666
int? IDirectGenerator.MaxEdits { get; set; }
67-
decimal? IDirectGenerator.MaxInspections { get; set; }
68-
decimal? IDirectGenerator.MaxTermFrequency { get; set; }
69-
decimal? IDirectGenerator.MinDocFrequency { get; set; }
67+
float? IDirectGenerator.MaxInspections { get; set; }
68+
float? IDirectGenerator.MaxTermFrequency { get; set; }
69+
float? IDirectGenerator.MinDocFrequency { get; set; }
7070
int? IDirectGenerator.MinWordLength { get; set; }
7171
string IDirectGenerator.PostFilter { get; set; }
7272
string IDirectGenerator.PreFilter { get; set; }
@@ -88,11 +88,11 @@ public class DirectGeneratorDescriptor<T> : DescriptorBase<DirectGeneratorDescri
8888

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

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

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

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

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

src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,25 @@ public class PhraseSuggestCollate : IPhraseSuggestCollate
4747
public IPhraseSuggestCollateQuery Query { get; set; }
4848
}
4949

50+
/// <inheritdoc cref="IPhraseSuggestCollate" />
5051
public class PhraseSuggestCollateDescriptor<T> : DescriptorBase<PhraseSuggestCollateDescriptor<T>, IPhraseSuggestCollate>, IPhraseSuggestCollate
5152
where T : class
5253
{
5354
IDictionary<string, object> IPhraseSuggestCollate.Params { get; set; }
5455
bool? IPhraseSuggestCollate.Prune { get; set; }
5556
IPhraseSuggestCollateQuery IPhraseSuggestCollate.Query { get; set; }
5657

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

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

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

75-
/// <summary>
76-
/// The parameters for the query. the suggestion value will be added to the variables you specify.
77-
/// </summary>
68+
/// <inheritdoc cref="IPhraseSuggestCollate.Params" />
7869
public PhraseSuggestCollateDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) =>
7970
Assign(paramsDictionary(new FluentDictionary<string, object>()), (a, v) => a.Params = v);
8071
}

src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollateQuery.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public class PhraseSuggestCollateQuery : IPhraseSuggestCollateQuery
3333
public string Source { get; set; }
3434
}
3535

36-
/// <inheritdoc />
36+
/// <inheritdoc cref="IPhraseSuggestCollateQuery" />
3737
public class PhraseSuggestCollateQueryDescriptor
3838
: DescriptorBase<PhraseSuggestCollateQueryDescriptor, IPhraseSuggestCollateQuery>, IPhraseSuggestCollateQuery
3939
{
4040
Id IPhraseSuggestCollateQuery.Id { get; set; }
4141
string IPhraseSuggestCollateQuery.Source { get; set; }
4242

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

46-
/// <inheritdoc />
46+
/// <inheritdoc cref="IPhraseSuggestCollateQuery.Id" />
4747
public PhraseSuggestCollateQueryDescriptor Id(Id id) => Assign(id, (a, v) => a.Id = v);
4848
}
4949
}

0 commit comments

Comments
 (0)