|
4 | 4 |
|
5 | 5 | namespace Nest
|
6 | 6 | {
|
| 7 | + /// <summary> |
| 8 | + /// Checks each suggestion against the specified query to prune suggestions |
| 9 | + /// for which no matching docs exist in the index. |
| 10 | + /// </summary> |
7 | 11 | [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
8 | 12 | [JsonConverter(typeof(ReadAsTypeJsonConverter<PhraseSuggestCollate>))]
|
9 | 13 | public interface IPhraseSuggestCollate
|
10 | 14 | {
|
11 |
| - [JsonProperty(PropertyName = "query")] |
| 15 | + /// <summary> |
| 16 | + /// The collate query to run. |
| 17 | + /// </summary> |
| 18 | + /// <remarks> |
| 19 | + /// Query parameters should be specified using <see cref="Params"/> |
| 20 | + /// </remarks> |
| 21 | + [JsonProperty("query")] |
12 | 22 | ITemplateQuery Query { get; set; }
|
13 | 23 |
|
14 |
| - [JsonProperty(PropertyName = "prune")] |
| 24 | + /// <summary> |
| 25 | + /// Controls if all phrase suggestions will be returned. When set to <c>true</c>, the suggestions will have |
| 26 | + /// an additional option collate_match, which will be <c>true</c> if matching documents for the phrase was found, |
| 27 | + /// <c>false</c> otherwise. The default value for <see cref="Prune"/> is <c>false</c>. |
| 28 | + /// </summary> |
| 29 | + [JsonProperty("prune")] |
15 | 30 | bool? Prune { get; set; }
|
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// The parameters for the query. the suggestion value will be added to the variables you specify. |
| 34 | + /// </summary> |
| 35 | + [JsonProperty("params")] |
| 36 | + IDictionary<string, object> Params { get; set; } |
16 | 37 | }
|
17 | 38 |
|
| 39 | + /// <inheritdoc /> |
18 | 40 | public class PhraseSuggestCollate : IPhraseSuggestCollate
|
19 | 41 | {
|
20 |
| - public ITemplateQuery Query { get; set; } |
| 42 | + private ITemplateQuery _query; |
| 43 | + |
| 44 | + /// <inheritdoc /> |
| 45 | + public ITemplateQuery Query |
| 46 | + { |
| 47 | + get => _query; |
| 48 | + set |
| 49 | + { |
| 50 | + _query = value; |
| 51 | + if (_query != null) Params = _query.Params; |
| 52 | + } |
| 53 | + } |
21 | 54 |
|
| 55 | + /// <inheritdoc /> |
22 | 56 | public bool? Prune { get; set; }
|
| 57 | + |
| 58 | + /// <inheritdoc /> |
| 59 | + public IDictionary<string, object> Params { get; set; } |
23 | 60 | }
|
24 | 61 |
|
25 | 62 | public class PhraseSuggestCollateDescriptor<T> : DescriptorBase<PhraseSuggestCollateDescriptor<T>, IPhraseSuggestCollate>, IPhraseSuggestCollate
|
26 | 63 | where T : class
|
27 | 64 | {
|
28 | 65 | ITemplateQuery IPhraseSuggestCollate.Query { get; set; }
|
29 |
| - |
| 66 | + IDictionary<string, object> IPhraseSuggestCollate.Params { get; set; } |
30 | 67 | bool? IPhraseSuggestCollate.Prune { get; set; }
|
31 | 68 |
|
| 69 | + /// <summary> |
| 70 | + /// The collate query to run. |
| 71 | + /// </summary> |
| 72 | + /// <remarks> |
| 73 | + /// Query parameters should be specified using <see cref="Params(IDictionary<string, object>)"/> or |
| 74 | + /// Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>>) |
| 75 | + /// </remarks> |
32 | 76 | public PhraseSuggestCollateDescriptor<T> Query(Func<TemplateQueryDescriptor<T>, ITemplateQuery> selector) =>
|
33 |
| - Assign(a => a.Query = selector?.Invoke(new TemplateQueryDescriptor<T>())); |
| 77 | + Assign(a => |
| 78 | + { |
| 79 | + var templateQuery = selector?.Invoke(new TemplateQueryDescriptor<T>()); |
| 80 | + a.Query = templateQuery; |
| 81 | + if (templateQuery != null) Self.Params = templateQuery.Params; |
| 82 | + }); |
34 | 83 |
|
| 84 | + /// <summary> |
| 85 | + /// Controls if all phrase suggestions will be returned. When set to <c>true</c>, the suggestions will have |
| 86 | + /// an additional option collate_match, which will be <c>true</c> if matching documents for the phrase was found, |
| 87 | + /// <c>false</c> otherwise. The default value for <see cref="Prune"/> is <c>false</c>. |
| 88 | + /// </summary> |
35 | 89 | public PhraseSuggestCollateDescriptor<T> Prune(bool? prune = true) => Assign(a => a.Prune = prune);
|
| 90 | + |
| 91 | + /// <summary> |
| 92 | + /// The parameters for the query. the suggestion value will be added to the variables you specify. |
| 93 | + /// </summary> |
| 94 | + public PhraseSuggestCollateDescriptor<T> Params(IDictionary<string, object> paramsDictionary) => Assign(a => a.Params = paramsDictionary); |
| 95 | + |
| 96 | + /// <summary> |
| 97 | + /// The parameters for the query. the suggestion value will be added to the variables you specify. |
| 98 | + /// </summary> |
| 99 | + public PhraseSuggestCollateDescriptor<T> Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) => |
| 100 | + Assign(a => a.Params = paramsDictionary(new FluentDictionary<string, object>())); |
36 | 101 | }
|
37 | 102 | }
|
0 commit comments