|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Linq.Expressions; |
| 5 | +using System.Text; |
| 6 | +using Nest.Resolvers; |
| 7 | +using Newtonsoft.Json; |
| 8 | + |
| 9 | +namespace Nest |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// http://www.elasticsearch.org/blog/terms-filter-lookup/ |
| 13 | + /// </summary> |
| 14 | + public class TermsLookupFilterDescriptor : FilterBase |
| 15 | + { |
| 16 | + internal override bool IsConditionless |
| 17 | + { |
| 18 | + get |
| 19 | + { |
| 20 | + return this._Type == null || this._Index == null || this._Id.IsNullOrEmpty() |
| 21 | + || this._Path.IsNullOrEmpty(); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + [JsonProperty("id")] |
| 26 | + internal string _Id { get; set; } |
| 27 | + |
| 28 | + [JsonProperty("type")] |
| 29 | + internal TypeNameMarker _Type { get; set; } |
| 30 | + |
| 31 | + [JsonProperty("index")] |
| 32 | + internal IndexNameMarker _Index { get; set; } |
| 33 | + |
| 34 | + [JsonProperty("path")] |
| 35 | + internal string _Path { get; set; } |
| 36 | + |
| 37 | + [JsonProperty("routing")] |
| 38 | + internal string _Routing { get; set; } |
| 39 | + |
| 40 | + |
| 41 | + public TermsLookupFilterDescriptor Lookup<T>(string field, string id, string index = null, string type = null) |
| 42 | + { |
| 43 | + this._Path = field; |
| 44 | + this._Id = id; |
| 45 | + this._Type = type ?? new TypeNameMarker {Type = typeof (T)}; |
| 46 | + this._Index = index ?? new IndexNameMarker {Type = typeof (T)}; |
| 47 | + return this; |
| 48 | + } |
| 49 | + |
| 50 | + public TermsLookupFilterDescriptor Lookup<T>(Expression<Func<T, object>> field, string id, string index = null, string type = null) |
| 51 | + { |
| 52 | + var fieldName = new PropertyNameResolver().Resolve(field); |
| 53 | + return this.Lookup<T>(fieldName, id, index, type); |
| 54 | + } |
| 55 | + |
| 56 | + /// <summary> |
| 57 | + /// If not specified will use the default typename for the type specified on Lookup<T> |
| 58 | + /// </summary> |
| 59 | + public TermsLookupFilterDescriptor Type(string type) |
| 60 | + { |
| 61 | + this._Type = type; |
| 62 | + return this; |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// If not specified will use the default index for the type specified on Lookup<T> |
| 67 | + /// </summary> |
| 68 | + public TermsLookupFilterDescriptor Index(string index) |
| 69 | + { |
| 70 | + this._Index = index; |
| 71 | + return this; |
| 72 | + } |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// A custom routing value to be used when retrieving the external terms doc. |
| 76 | + /// </summary> |
| 77 | + public TermsLookupFilterDescriptor Routing(string routing) |
| 78 | + { |
| 79 | + this._Routing = routing; |
| 80 | + return this; |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | +} |
0 commit comments