-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutocompleteOptionsBuilder.cs
133 lines (116 loc) · 5.25 KB
/
AutocompleteOptionsBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using Newtonsoft.Json;
using System.Linq.Expressions;
namespace AzureSearchQueryBuilder.Builders
{
/// <summary>
/// The <see cref="AutocompleteOptions"/>`1[<typeparamref name="TModel"/>] builder.
/// </summary>
/// <typeparam name="TModel">The type of the model representing the search index documents.</typeparam>
public class AutocompleteOptionsBuilder<TModel> : OptionsBuilder<TModel, AutocompleteOptions>, IAutocompleteOptionsBuilder<TModel>
{
/// <summary>
/// Constructor.
/// </summary>
private AutocompleteOptionsBuilder(JsonSerializerSettings jsonSerializerSettings)
: base(jsonSerializerSettings)
{
}
/// <summary>
/// Gets the autocomplete mode.
/// </summary>
/// <remarks>
/// * <see cref="AutocompleteMode.OneTerm"/> - Only one term is suggested. If the query has two terms, only the last term is completed.
/// * <see cref="AutocompleteMode.TwoTerms"/> - Matching two-term phrases in the index will be suggested.
/// * <see cref="AutocompleteMode.OneTermWithContext"/> - Completes the last term in a query with two or more terms, where the last two terms are a phrase that exists in the index.
/// </remarks>
public AutocompleteMode Mode { get; private set; }
/// <summary>
/// Gets the value indicating that suggestions should be found even if there is a substituted or missing character in the search text.
/// </summary>
public bool? UseFuzzyMatching { get; private set; }
/// <summary>
/// Create a new <see cref="IAutocompleteOptionsBuilder" />`1[<typeparamref name="TModel"/>]"/>.
/// </summary>
/// <returns>a new <see cref="IAutocompleteOptionsBuilder" />`1[<typeparamref name="TModel"/>]"/>.</returns>
public static IAutocompleteOptionsBuilder<TModel> Create(JsonSerializerSettings jsonSerializerSettings) => new AutocompleteOptionsBuilder<TModel>(jsonSerializerSettings);
/// <summary>
/// Build a <see cref="AutocompleteOptions"/> object.
/// </summary>
/// <returns>the <see cref="AutocompleteOptions"/> object.</returns>
public override AutocompleteOptions Build()
{
AutocompleteOptions autocompleteOptions = new AutocompleteOptions()
{
Mode = this.Mode,
Filter = this.Filter,
HighlightPostTag = this.HighlightPostTag,
HighlightPreTag = this.HighlightPreTag,
MinimumCoverage = this.MinimumCoverage,
Size = this.Size,
UseFuzzyMatching = this.UseFuzzyMatching,
};
if (this.SearchFields != null)
{
foreach (string searchField in this.SearchFields)
{
autocompleteOptions.SearchFields.Add(searchField);
}
}
return autocompleteOptions;
}
/// <summary>
/// Sets the autocomplete mode.
/// </summary>
/// <param name="autocompleteMode">The desired autocomplete mode.</param>
/// <returns>the updated builder.</returns>
public IAutocompleteOptionsBuilder<TModel> WithMode(AutocompleteMode autocompleteMode)
{
this.Mode = autocompleteMode;
return this;
}
/// <summary>
/// Sets the use fuzzy matching value.
/// </summary>
/// <param name="useFuzzyMatching">The desired fuzzy matching mode.</param>
/// <returns>the updated builder.</returns>
public IAutocompleteOptionsBuilder<TModel> WithUseFuzzyMatching(bool? useFuzzyMatching)
{
this.UseFuzzyMatching = useFuzzyMatching;
return this;
}
#region IAutocompleteOptionsBuilder Explicit Implimentation
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.Where(Expression<BooleanLambdaDelegate<TModel>> lambdaExpression)
{
this.Where(lambdaExpression);
return this;
}
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.WithHighlightPostTag(string highlightPostTag)
{
this.WithHighlightPostTag(highlightPostTag);
return this;
}
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.WithHighlightPreTag(string highlightPreTag)
{
this.WithHighlightPreTag(highlightPreTag);
return this;
}
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.WithMinimumCoverage(double? minimumCoverage)
{
this.WithMinimumCoverage(minimumCoverage);
return this;
}
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.WithSearchField<TProperty>(Expression<PropertyLambdaDelegate<TModel, TProperty>> lambdaExpression)
{
this.WithSearchField(lambdaExpression);
return this;
}
IAutocompleteOptionsBuilder<TModel> IAutocompleteOptionsBuilder<TModel>.WithSize(int? size)
{
this.WithSize(size);
return this;
}
#endregion
}
}