diff --git a/src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs b/src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs
index da28bd30669..e8dfd84db2d 100644
--- a/src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs
+++ b/src/Nest/Search/Suggesters/PhraseSuggester/PhraseSuggestCollate.cs
@@ -4,34 +4,99 @@
namespace Nest
{
+ ///
+ /// Checks each suggestion against the specified query to prune suggestions
+ /// for which no matching docs exist in the index.
+ ///
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeJsonConverter))]
public interface IPhraseSuggestCollate
{
- [JsonProperty(PropertyName = "query")]
+ ///
+ /// The collate query to run.
+ ///
+ ///
+ /// Query parameters should be specified using
+ ///
+ [JsonProperty("query")]
ITemplateQuery Query { get; set; }
- [JsonProperty(PropertyName = "prune")]
+ ///
+ /// Controls if all phrase suggestions will be returned. When set to true, the suggestions will have
+ /// an additional option collate_match, which will be true if matching documents for the phrase was found,
+ /// false otherwise. The default value for is false.
+ ///
+ [JsonProperty("prune")]
bool? Prune { get; set; }
+
+ ///
+ /// The parameters for the query. the suggestion value will be added to the variables you specify.
+ ///
+ [JsonProperty("params")]
+ IDictionary Params { get; set; }
}
+ ///
public class PhraseSuggestCollate : IPhraseSuggestCollate
{
- public ITemplateQuery Query { get; set; }
+ private ITemplateQuery _query;
+
+ ///
+ public ITemplateQuery Query
+ {
+ get => _query;
+ set
+ {
+ _query = value;
+ if (_query != null) Params = _query.Params;
+ }
+ }
+ ///
public bool? Prune { get; set; }
+
+ ///
+ public IDictionary Params { get; set; }
}
public class PhraseSuggestCollateDescriptor : DescriptorBase, IPhraseSuggestCollate>, IPhraseSuggestCollate
where T : class
{
ITemplateQuery IPhraseSuggestCollate.Query { get; set; }
-
+ IDictionary IPhraseSuggestCollate.Params { get; set; }
bool? IPhraseSuggestCollate.Prune { get; set; }
+ ///
+ /// The collate query to run.
+ ///
+ ///
+ /// Query parameters should be specified using or
+ /// Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>>)
+ ///
public PhraseSuggestCollateDescriptor Query(Func, ITemplateQuery> selector) =>
- Assign(a => a.Query = selector?.Invoke(new TemplateQueryDescriptor()));
+ Assign(a =>
+ {
+ var templateQuery = selector?.Invoke(new TemplateQueryDescriptor());
+ a.Query = templateQuery;
+ if (templateQuery != null) Self.Params = templateQuery.Params;
+ });
+ ///
+ /// Controls if all phrase suggestions will be returned. When set to true, the suggestions will have
+ /// an additional option collate_match, which will be true if matching documents for the phrase was found,
+ /// false otherwise. The default value for is false.
+ ///
public PhraseSuggestCollateDescriptor Prune(bool? prune = true) => Assign(a => a.Prune = prune);
+
+ ///
+ /// The parameters for the query. the suggestion value will be added to the variables you specify.
+ ///
+ public PhraseSuggestCollateDescriptor Params(IDictionary paramsDictionary) => Assign(a => a.Params = paramsDictionary);
+
+ ///
+ /// The parameters for the query. the suggestion value will be added to the variables you specify.
+ ///
+ public PhraseSuggestCollateDescriptor Params(Func, FluentDictionary> paramsDictionary) =>
+ Assign(a => a.Params = paramsDictionary(new FluentDictionary()));
}
}
diff --git a/src/Tests/Search/Suggesters/SuggestApiTests.cs b/src/Tests/Search/Suggesters/SuggestApiTests.cs
index 6c1427ad67b..91f14e86420 100644
--- a/src/Tests/Search/Suggesters/SuggestApiTests.cs
+++ b/src/Tests/Search/Suggesters/SuggestApiTests.cs
@@ -80,9 +80,9 @@ protected override LazyResponses ClientUsage() => Calls(
.Confidence(1)
.Collate(c => c
.Query(q => q
- .Inline("{ \"match_all\": { }}")
- .Params(p => p.Add("field_name", _phraseSuggestField))
+ .Inline("{ \"match\": { \"{{field_name}}\" : \"{{suggestion}}\" }}")
)
+ .Params(p => p.Add("field_name", _phraseSuggestField))
.Prune()
)
.DirectGenerator(d => d
@@ -170,11 +170,11 @@ protected override LazyResponses ClientUsage() => Calls(
{
Query = new TemplateQuery
{
- Inline = "{ \"match_all\": { }}",
- Params = new Dictionary
- {
- {"field_name", _phraseSuggestField}
- }
+ Inline = "{ \"match\": { \"{{field_name}}\" : \"{{suggestion}}\" }}",
+ },
+ Params = new Dictionary
+ {
+ {"field_name", _phraseSuggestField}
},
Prune = true
},
@@ -322,11 +322,11 @@ private static void AssertCompletionSuggestResponse(ISuggestResponse re
{
query = new
{
- inline = "{ \"match_all\": { }}",
- @params = new
- {
- field_name = _phraseSuggestField
- }
+ inline = "{ \"match\": { \"{{field_name}}\" : \"{{suggestion}}\" }}",
+ },
+ @params = new
+ {
+ field_name = _phraseSuggestField
},
prune = true,
},