|
| 1 | +using Newtonsoft.Json; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | + |
| 7 | +namespace Nest |
| 8 | +{ |
| 9 | + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] |
| 10 | + public interface ITemplateQuery : IQuery |
| 11 | + { |
| 12 | + [JsonProperty("query")] |
| 13 | + string Query { get; set; } |
| 14 | + |
| 15 | + [JsonProperty("params")] |
| 16 | + IDictionary<string, object> Params { get; set; } |
| 17 | + } |
| 18 | + |
| 19 | + public class TemplateQuery : PlainQuery, ITemplateQuery |
| 20 | + { |
| 21 | + protected override void WrapInContainer(IQueryContainer container) |
| 22 | + { |
| 23 | + container.Template = this; |
| 24 | + } |
| 25 | + |
| 26 | + public string Query { get; set; } |
| 27 | + |
| 28 | + public IDictionary<string, object> Params { get; set;} |
| 29 | + |
| 30 | + public bool IsConditionless |
| 31 | + { |
| 32 | + get { return this.Query.IsNullOrEmpty(); } |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + public class TemplateQueryDescriptor : ITemplateQuery |
| 37 | + { |
| 38 | + ITemplateQuery Self { get { return this; } } |
| 39 | + |
| 40 | + string ITemplateQuery.Query { get; set; } |
| 41 | + |
| 42 | + IDictionary<string, object> ITemplateQuery.Params { get; set; } |
| 43 | + |
| 44 | + bool IQuery.IsConditionless { get { return this.Self.Query.IsNullOrEmpty(); } } |
| 45 | + |
| 46 | + public TemplateQueryDescriptor Query(string query) |
| 47 | + { |
| 48 | + this.Self.Query = query; |
| 49 | + return this; |
| 50 | + } |
| 51 | + |
| 52 | + public TemplateQueryDescriptor Params(IDictionary<string, object> paramsDictionary) |
| 53 | + { |
| 54 | + paramsDictionary.ThrowIfNull("paramsDictionary"); |
| 55 | + this.Self.Params = paramsDictionary; |
| 56 | + return this; |
| 57 | + } |
| 58 | + |
| 59 | + public TemplateQueryDescriptor Params(Func<FluentDictionary<string, object>, FluentDictionary<string, object>> paramsDictionary) |
| 60 | + { |
| 61 | + paramsDictionary.ThrowIfNull("paramsDictionary"); |
| 62 | + this.Self.Params = paramsDictionary(new FluentDictionary<string,object>()); |
| 63 | + return this; |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments