|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using Newtonsoft.Json; |
| 6 | +using System.Linq.Expressions; |
| 7 | +using System.Globalization; |
| 8 | +using Newtonsoft.Json.Converters; |
| 9 | +using Elasticsearch.Net; |
| 10 | +using Nest.Resolvers; |
| 11 | + |
| 12 | +namespace Nest |
| 13 | +{ |
| 14 | + [JsonObject(MemberSerialization = MemberSerialization.OptIn)] |
| 15 | + public class SimpleQueryStringQueryDescriptor<T> : IQuery where T : class |
| 16 | + { |
| 17 | + [JsonProperty(PropertyName = "query")] |
| 18 | + internal string _QueryString { get; set; } |
| 19 | + [JsonProperty(PropertyName = "default_field")] |
| 20 | + internal PropertyPathMarker _Field { get; set; } |
| 21 | + [JsonProperty(PropertyName = "fields")] |
| 22 | + internal IEnumerable<PropertyPathMarker> _Fields { get; set; } |
| 23 | + [JsonProperty(PropertyName = "default_operator")] |
| 24 | + [JsonConverter(typeof(StringEnumConverter))] |
| 25 | + internal Operator? _DefaultOperator { get; set; } |
| 26 | + [JsonProperty(PropertyName = "analyzer")] |
| 27 | + internal string _Analyzer { get; set; } |
| 28 | + [JsonProperty(PropertyName = "lowercase_expanded_terms")] |
| 29 | + internal bool? _LowercaseExpendedTerms { get; set; } |
| 30 | + [JsonProperty(PropertyName = "flags")] |
| 31 | + internal string _Flags { get; set; } |
| 32 | + [JsonProperty(PropertyName = "locale")] |
| 33 | + internal string _Locale { get; set; } |
| 34 | + |
| 35 | + |
| 36 | + bool IQuery.IsConditionless |
| 37 | + { |
| 38 | + get |
| 39 | + { |
| 40 | + return this._QueryString.IsNullOrEmpty(); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + public SimpleQueryStringQueryDescriptor<T> OnField(string field) |
| 46 | + { |
| 47 | + this._Field = field; |
| 48 | + return this; |
| 49 | + } |
| 50 | + public SimpleQueryStringQueryDescriptor<T> OnField(Expression<Func<T, object>> objectPath) |
| 51 | + { |
| 52 | + this._Field = objectPath; |
| 53 | + return this; |
| 54 | + } |
| 55 | + public SimpleQueryStringQueryDescriptor<T> OnFields(IEnumerable<string> fields) |
| 56 | + { |
| 57 | + this._Fields = fields.Select(f=>(PropertyPathMarker)f); |
| 58 | + return this; |
| 59 | + } |
| 60 | + public SimpleQueryStringQueryDescriptor<T> OnFields( |
| 61 | + params Expression<Func<T, object>>[] objectPaths) |
| 62 | + { |
| 63 | + this._Fields = objectPaths.Select(e=>(PropertyPathMarker)e); |
| 64 | + return this; |
| 65 | + } |
| 66 | + public SimpleQueryStringQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<Expression<Func<T, object>>, double?>> boostableSelector) |
| 67 | + { |
| 68 | + var d = new FluentDictionary<Expression<Func<T, object>>, double?>(); |
| 69 | + boostableSelector(d); |
| 70 | + this._Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value)); |
| 71 | + return this; |
| 72 | + } |
| 73 | + public SimpleQueryStringQueryDescriptor<T> OnFieldsWithBoost(Action<FluentDictionary<string, double?>> boostableSelector) |
| 74 | + { |
| 75 | + var d = new FluentDictionary<string, double?>(); |
| 76 | + boostableSelector(d); |
| 77 | + this._Fields = d.Select(o => PropertyPathMarker.Create(o.Key, o.Value)); |
| 78 | + return this; |
| 79 | + } |
| 80 | + |
| 81 | + public SimpleQueryStringQueryDescriptor<T> Query(string query) |
| 82 | + { |
| 83 | + this._QueryString = query; |
| 84 | + return this; |
| 85 | + } |
| 86 | + public SimpleQueryStringQueryDescriptor<T> DefaultOperator(Operator op) |
| 87 | + { |
| 88 | + this._DefaultOperator = op; |
| 89 | + return this; |
| 90 | + } |
| 91 | + public SimpleQueryStringQueryDescriptor<T> Analyzer(string analyzer) |
| 92 | + { |
| 93 | + this._Analyzer = analyzer; |
| 94 | + return this; |
| 95 | + } |
| 96 | + public SimpleQueryStringQueryDescriptor<T> Flags(string flags) |
| 97 | + { |
| 98 | + this._Flags = flags; |
| 99 | + return this; |
| 100 | + } |
| 101 | + public SimpleQueryStringQueryDescriptor<T> LowercaseExpendedTerms(bool lowercaseExpendedTerms) |
| 102 | + { |
| 103 | + this._LowercaseExpendedTerms = lowercaseExpendedTerms; |
| 104 | + return this; |
| 105 | + } |
| 106 | + public SimpleQueryStringQueryDescriptor<T> Locale(string locale) |
| 107 | + { |
| 108 | + this._Locale = locale; |
| 109 | + return this; |
| 110 | + } |
| 111 | + |
| 112 | + } |
| 113 | +} |
0 commit comments