Skip to content

Commit 2737b05

Browse files
committed
added name to all the queries
1 parent ce2faf2 commit 2737b05

File tree

52 files changed

+754
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+754
-298
lines changed

src/Nest/DSL/Filter/RawFilter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ namespace Nest
88
{
99
[JsonConverter(typeof(CustomJsonConverter))]
1010
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
11+
[Obsolete("Never used and scheduled to be removed in 2.0")]
1112
public class RawFilter : IQuery, ICustomJson
1213
{
1314
internal object Json { get; set; }
1415
bool IQuery.IsConditionless { get { return this.Json == null || this.Json.ToString().IsNullOrEmpty(); } }
16+
17+
string IQuery.Name { get; set; }
1518

1619
object ICustomJson.GetCustomJson()
1720
{

src/Nest/DSL/Query/BoolQueryDescriptor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ protected override void WrapInContainer(IQueryContainer container)
4040
container.Bool = this;
4141
}
4242

43+
public string Name { get; set; }
44+
4345
bool IQuery.IsConditionless { get { return false; } }
4446

4547
public IEnumerable<IQueryContainer> Must { get; set; }
@@ -70,7 +72,10 @@ public class BoolBaseQueryDescriptor : IBoolQuery
7072

7173
[JsonProperty("boost")]
7274
double? IBoolQuery.Boost { get; set; }
73-
75+
76+
[JsonProperty("_name")]
77+
string IQuery.Name { get; set; }
78+
7479
bool IQuery.IsConditionless
7580
{
7681
get

src/Nest/DSL/Query/BoostingQueryDescriptor.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Configuration;
34
using System.Linq;
45
using Nest.Resolvers.Converters;
56
using Newtonsoft.Json;
@@ -27,6 +28,7 @@ protected override void WrapInContainer(IQueryContainer container)
2728
container.Boosting = this;
2829
}
2930

31+
public string Name { get; set; }
3032
bool IQuery.IsConditionless { get { return false; } }
3133
public QueryContainer PositiveQuery { get; set; }
3234
public QueryContainer NegativeQuery { get; set; }
@@ -35,6 +37,8 @@ protected override void WrapInContainer(IQueryContainer container)
3537

3638
public class BoostingQueryDescriptor<T> : IBoostingQuery where T : class
3739
{
40+
private IBoostingQuery Self { get { return this; } }
41+
3842
QueryContainer IBoostingQuery.PositiveQuery { get; set; }
3943

4044
QueryContainer IBoostingQuery.NegativeQuery { get; set; }
@@ -45,31 +49,39 @@ bool IQuery.IsConditionless
4549
{
4650
get
4751
{
48-
if (((IBoostingQuery)this).NegativeQuery == null && ((IBoostingQuery)this).PositiveQuery == null)
52+
if (Self.NegativeQuery == null && Self.PositiveQuery == null)
4953
return true;
50-
return ((IBoostingQuery)this).PositiveQuery == null && ((IBoostingQuery)this).NegativeQuery.IsConditionless
51-
|| ((IBoostingQuery)this).NegativeQuery == null && ((IBoostingQuery)this).PositiveQuery.IsConditionless;
54+
return (Self.PositiveQuery == null || Self.NegativeQuery.IsConditionless)
55+
|| (Self.NegativeQuery == null || Self.PositiveQuery.IsConditionless);
5256
}
5357
}
5458

59+
string IQuery.Name { get; set; }
60+
61+
public BoostingQueryDescriptor<T> Name(string name)
62+
{
63+
Self.Name = name;
64+
return this;
65+
}
66+
5567
public BoostingQueryDescriptor<T> NegativeBoost(double boost)
5668
{
57-
((IBoostingQuery)this).NegativeBoost = boost;
69+
Self.NegativeBoost = boost;
5870
return this;
5971
}
6072

6173
public BoostingQueryDescriptor<T> Positive(Func<QueryDescriptor<T>, QueryContainer> selector)
6274
{
6375
var query = new QueryDescriptor<T>();
6476
var q = selector(query);
65-
((IBoostingQuery)this).PositiveQuery = q;
77+
Self.PositiveQuery = q;
6678
return this;
6779
}
6880
public BoostingQueryDescriptor<T> Negative(Func<QueryDescriptor<T>, QueryContainer> selector)
6981
{
7082
var query = new QueryDescriptor<T>();
7183
var q = selector(query);
72-
((IBoostingQuery)this).NegativeQuery = q;
84+
Self.NegativeQuery = q;
7385
return this;
7486
}
7587
}

src/Nest/DSL/Query/CommonTermsQueryDescriptor.cs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ protected override void WrapInContainer(IQueryContainer container)
4747
{
4848
container.CommonTerms = this;
4949
}
50-
5150
bool IQuery.IsConditionless { get { return false; } }
51+
5252
PropertyPathMarker IFieldNameQuery.GetFieldName()
5353
{
5454
return this.Field;
@@ -59,6 +59,7 @@ void IFieldNameQuery.SetFieldName(string fieldName)
5959
this.Field = fieldName;
6060
}
6161

62+
public string Name { get; set; }
6263
public string Query { get; set; }
6364
public PropertyPathMarker Field { get; set; }
6465
public double? CutoffFrequency { get; set; }
@@ -72,6 +73,8 @@ void IFieldNameQuery.SetFieldName(string fieldName)
7273

7374
public class CommonTermsQueryDescriptor<T> : ICommonTermsQuery where T : class
7475
{
76+
private ICommonTermsQuery Self { get { return this; }}
77+
7578
string ICommonTermsQuery.Query { get; set; }
7679

7780
PropertyPathMarker ICommonTermsQuery.Field { get; set; }
@@ -90,77 +93,85 @@ public class CommonTermsQueryDescriptor<T> : ICommonTermsQuery where T : class
9093

9194
bool? ICommonTermsQuery.DisableCoord { get; set; }
9295

96+
string IQuery.Name { get; set; }
97+
9398
bool IQuery.IsConditionless
9499
{
95100
get
96101
{
97-
return ((ICommonTermsQuery)this).Field.IsConditionless() || ((ICommonTermsQuery)this).Query.IsNullOrEmpty();
102+
return Self.Field.IsConditionless() || Self.Query.IsNullOrEmpty();
98103
}
99104
}
100105
void IFieldNameQuery.SetFieldName(string fieldName)
101106
{
102-
((ICommonTermsQuery)this).Field = fieldName;
107+
Self.Field = fieldName;
103108
}
104109
PropertyPathMarker IFieldNameQuery.GetFieldName()
105110
{
106-
return ((ICommonTermsQuery)this).Field;
111+
return Self.Field;
112+
}
113+
114+
public CommonTermsQueryDescriptor<T> Name(string name)
115+
{
116+
Self.Name = name;
117+
return this;
107118
}
108119

109120
public CommonTermsQueryDescriptor<T> OnField(string field)
110121
{
111-
((ICommonTermsQuery)this).Field = field;
122+
Self.Field = field;
112123
return this;
113124
}
114125
public CommonTermsQueryDescriptor<T> OnField(Expression<Func<T, object>> objectPath)
115126
{
116-
((ICommonTermsQuery)this).Field = objectPath;
127+
Self.Field = objectPath;
117128
return this;
118129
}
119130

120131
public CommonTermsQueryDescriptor<T> Query(string query)
121132
{
122-
((ICommonTermsQuery)this).Query = query;
133+
Self.Query = query;
123134
return this;
124135
}
125136
public CommonTermsQueryDescriptor<T> LowFrequencyOperator(Operator op)
126137
{
127-
((ICommonTermsQuery)this).LowFrequencyOperator = op;
138+
Self.LowFrequencyOperator = op;
128139
return this;
129140
}
130141
public CommonTermsQueryDescriptor<T> HighFrequencyOperator(Operator op)
131142
{
132-
((ICommonTermsQuery)this).HighFrequencyOperator = op;
143+
Self.HighFrequencyOperator = op;
133144
return this;
134145
}
135146
public CommonTermsQueryDescriptor<T> Analyzer(string analyzer)
136147
{
137-
((ICommonTermsQuery)this).Analyzer = analyzer;
148+
Self.Analyzer = analyzer;
138149
return this;
139150
}
140151

141152
public CommonTermsQueryDescriptor<T> CutoffFrequency(double cutOffFrequency)
142153
{
143-
((ICommonTermsQuery)this).CutoffFrequency = cutOffFrequency;
154+
Self.CutoffFrequency = cutOffFrequency;
144155
return this;
145156
}
146157
public CommonTermsQueryDescriptor<T> MinimumShouldMatch(string minimumShouldMatch)
147158
{
148-
((ICommonTermsQuery)this).MinimumShouldMatch = minimumShouldMatch;
159+
Self.MinimumShouldMatch = minimumShouldMatch;
149160
return this;
150161
}
151162
public CommonTermsQueryDescriptor<T> MinimumShouldMatch(int minimumShouldMatch)
152163
{
153-
((ICommonTermsQuery)this).MinimumShouldMatch = minimumShouldMatch.ToString(CultureInfo.InvariantCulture);
164+
Self.MinimumShouldMatch = minimumShouldMatch.ToString(CultureInfo.InvariantCulture);
154165
return this;
155166
}
156167
public CommonTermsQueryDescriptor<T> Boost(double boost)
157168
{
158-
((ICommonTermsQuery)this).Boost = boost;
169+
Self.Boost = boost;
159170
return this;
160171
}
161172
public CommonTermsQueryDescriptor<T> DisableCoord(bool disable = true)
162173
{
163-
((ICommonTermsQuery)this).DisableCoord = disable;
174+
Self.DisableCoord = disable;
164175
return this;
165176
}
166177

src/Nest/DSL/Query/ConditionlessQueryDescriptor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ bool IQuery.IsConditionless
2121
}
2222
}
2323

24+
string IQuery.Name { get; set; }
25+
2426
public ConditionlessQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryContainer> querySelector)
2527
{
2628
querySelector.ThrowIfNull("querySelector");

src/Nest/DSL/Query/ConstantScoreQueryDescriptor.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ protected override void WrapInContainer(IQueryContainer container)
2929
container.ConstantScore = this;
3030
}
3131

32+
public string Name { get; set; }
33+
//TODO 2.0 change to explicit IQuery implementation
3234
public bool IsConditionless { get { return false; } }
3335
public string Lang { get; set; }
3436
public string Script { get; set; }
@@ -40,51 +42,61 @@ protected override void WrapInContainer(IQueryContainer container)
4042

4143
public class ConstantScoreQueryDescriptor<T> : IConstantScoreQuery where T : class
4244
{
45+
private IConstantScoreQuery Self { get { return this; }}
46+
4347
IQueryContainer IConstantScoreQuery.Query { get; set; }
4448

4549
IFilterContainer IConstantScoreQuery.Filter { get; set; }
4650

4751
double? IConstantScoreQuery.Boost { get; set; }
52+
53+
string IQuery.Name { get; set; }
4854

4955
bool IQuery.IsConditionless
5056
{
5157
get
5258
{
53-
if (((IConstantScoreQuery)this).Query == null && ((IConstantScoreQuery)this).Filter == null)
59+
if (Self.Query == null && Self.Filter == null)
5460
return true;
55-
if (((IConstantScoreQuery)this).Filter == null && ((IConstantScoreQuery)this).Query != null)
56-
return ((IConstantScoreQuery)this).Query.IsConditionless;
57-
if (((IConstantScoreQuery)this).Filter != null && ((IConstantScoreQuery)this).Query == null)
58-
return ((IConstantScoreQuery)this).Filter.IsConditionless;
61+
if (Self.Filter == null && Self.Query != null)
62+
return Self.Query.IsConditionless;
63+
if (Self.Filter != null && Self.Query == null)
64+
return Self.Filter.IsConditionless;
5965
return false;
6066
}
6167
}
6268

69+
public ConstantScoreQueryDescriptor<T> Name(string name)
70+
{
71+
Self.Name = name;
72+
return this;
73+
}
74+
6375
public ConstantScoreQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryContainer> querySelector)
6476
{
6577
querySelector.ThrowIfNull("querySelector");
66-
((IConstantScoreQuery)this).Filter = null;
78+
Self.Filter = null;
6779
var query = new QueryDescriptor<T>();
6880
var q = querySelector(query);
6981

70-
((IConstantScoreQuery)this).Query = q;
82+
Self.Query = q;
7183
return this;
7284
}
7385

7486
public ConstantScoreQueryDescriptor<T> Filter(Func<FilterDescriptor<T>, FilterContainer> filterSelector)
7587
{
7688
filterSelector.ThrowIfNull("filterSelector");
77-
((IConstantScoreQuery)this).Query = null;
89+
Self.Query = null;
7890
var filter = new FilterDescriptor<T>();
7991
var f = filterSelector(filter);
8092

81-
((IConstantScoreQuery)this).Filter = f;
93+
Self.Filter = f;
8294
return this;
8395
}
8496

8597
public ConstantScoreQueryDescriptor<T> Boost(double boost)
8698
{
87-
((IConstantScoreQuery)this).Boost = boost;
99+
Self.Boost = boost;
88100
return this;
89101
}
90102
}

src/Nest/DSL/Query/CustomBoostFactorQueryDescriptor.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,50 @@ protected override void WrapInContainer(IQueryContainer container)
2525
container.CustomBoostFactor = this;
2626
}
2727

28+
public string Name { get; set; }
29+
2830
bool IQuery.IsConditionless { get { return false; } }
2931
public IQueryContainer Query { get; set; }
3032
public double? BoostFactor { get; set; }
3133
}
3234

3335
public class CustomBoostFactorQueryDescriptor<T> : ICustomBoostFactorQuery where T : class
3436
{
37+
private ICustomBoostFactorQuery Self { get { return this; }}
38+
3539
IQueryContainer ICustomBoostFactorQuery.Query { get; set; }
3640

3741
double? ICustomBoostFactorQuery.BoostFactor { get; set; }
3842

43+
string IQuery.Name { get; set; }
44+
3945
bool IQuery.IsConditionless
4046
{
4147
get
4248
{
43-
return ((ICustomBoostFactorQuery)this).Query == null || ((ICustomBoostFactorQuery)this).Query.IsConditionless;
49+
return Self.Query == null || Self.Query.IsConditionless;
4450
}
4551
}
4652

53+
public CustomBoostFactorQueryDescriptor<T> Name(string name)
54+
{
55+
Self.Name = name;
56+
return this;
57+
}
4758

4859
public CustomBoostFactorQueryDescriptor<T> Query(Func<QueryDescriptor<T>, QueryContainer> querySelector)
4960
{
5061
querySelector.ThrowIfNull("querySelector");
5162
var query = new QueryDescriptor<T>();
5263
var q = querySelector(query);
5364

54-
((ICustomBoostFactorQuery)this).Query = q;
65+
Self.Query = q;
5566
return this;
5667
}
5768

5869
public CustomBoostFactorQueryDescriptor<T> BoostFactor(double boostFactor)
5970
{
60-
((ICustomBoostFactorQuery)this).BoostFactor = boostFactor;
71+
Self.BoostFactor = boostFactor;
6172
return this;
6273
}
6374
}

0 commit comments

Comments
 (0)