Skip to content

Commit c344285

Browse files
committed
Merge pull request #1122 from elasticsearch/feature/span-not-query-updates
fix #1099 add support for pre/post/dist to span not query
2 parents 0673203 + 998018f commit c344285

File tree

3 files changed

+67
-27
lines changed

3 files changed

+67
-27
lines changed

src/Nest/DSL/Query/SpanNotQueryDescriptor.cs

+53-22
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,17 @@ public interface ISpanNotQuery : ISpanSubQuery
1616
[JsonProperty(PropertyName = "exclude")]
1717
ISpanQuery Exclude { get; set; }
1818

19-
[JsonProperty(PropertyName = "boost")]
20-
double? Boost { get; set; }
19+
[JsonProperty(PropertyName = "boost")]
20+
double? Boost { get; set; }
21+
22+
[JsonProperty(PropertyName = "pre")]
23+
int? Pre { get; set; }
24+
25+
[JsonProperty(PropertyName = "post")]
26+
int? Post { get; set; }
27+
28+
[JsonProperty(PropertyName = "dist")]
29+
int? Dist { get; set; }
2130

2231
}
2332

@@ -31,22 +40,30 @@ protected override void WrapInContainer(IQueryContainer container)
3140
bool IQuery.IsConditionless { get { return false; } }
3241
public ISpanQuery Include { get; set; }
3342
public ISpanQuery Exclude { get; set; }
34-
public double? Boost { get; set; }
43+
public double? Boost { get; set; }
44+
public int? Pre { get; set; }
45+
public int? Post { get; set; }
46+
public int? Dist { get; set; }
3547
}
3648

3749
public class SpanNotQuery<T> : ISpanNotQuery where T : class
3850
{
51+
private ISpanNotQuery Self { get { return this; } }
52+
3953
ISpanQuery ISpanNotQuery.Include { get; set; }
4054

4155
ISpanQuery ISpanNotQuery.Exclude { get; set; }
42-
double? ISpanNotQuery.Boost { get; set; }
56+
double? ISpanNotQuery.Boost { get; set; }
57+
int? ISpanNotQuery.Pre { get; set; }
58+
int? ISpanNotQuery.Post { get; set; }
59+
int? ISpanNotQuery.Dist { get; set; }
4360

44-
bool IQuery.IsConditionless
61+
bool IQuery.IsConditionless
4562
{
4663
get
4764
{
48-
var excludeQuery = ((ISpanNotQuery)this).Exclude as IQuery;
49-
var includeQuery = ((ISpanNotQuery)this).Include as IQuery;
65+
var excludeQuery = Self.Exclude as IQuery;
66+
var includeQuery = Self.Include as IQuery;
5067

5168
return excludeQuery == null && includeQuery == null
5269
|| (includeQuery == null && excludeQuery.IsConditionless)
@@ -59,29 +76,43 @@ bool IQuery.IsConditionless
5976

6077
public SpanNotQuery<T> Include(Func<SpanQuery<T>, SpanQuery<T>> selector)
6178
{
62-
if (selector == null)
63-
return this;
64-
var descriptors = new List<SpanQuery<T>>();
79+
if (selector == null) return this;
6580
var span = new SpanQuery<T>();
66-
var q = selector(span);
67-
((ISpanNotQuery)this).Include = q;
81+
Self.Include = selector(span); ;
6882
return this;
6983
}
84+
7085
public SpanNotQuery<T> Exclude(Func<SpanQuery<T>, SpanQuery<T>> selector)
7186
{
72-
if (selector == null)
73-
return this;
74-
var descriptors = new List<SpanQuery<T>>();
87+
if (selector == null) return this;
7588
var span = new SpanQuery<T>();
76-
var q = selector(span);
77-
((ISpanNotQuery)this).Exclude = q;
89+
Self.Exclude = selector(span);;
90+
return this;
91+
}
92+
93+
public SpanNotQuery<T> Boost(double boost)
94+
{
95+
Self.Boost = boost;
96+
return this;
97+
}
98+
99+
public SpanNotQuery<T> Pre(int pre)
100+
{
101+
Self.Pre = pre;
102+
return this;
103+
}
104+
105+
public SpanNotQuery<T> Post(int post)
106+
{
107+
Self.Post = post;
108+
return this;
109+
}
110+
111+
public SpanNotQuery<T> Dist(int dist)
112+
{
113+
Self.Dist = dist;
78114
return this;
79115
}
80116

81-
public ISpanNotQuery Boost(double boost)
82-
{
83-
((ISpanNotQuery)this).Boost = boost;
84-
return this;
85-
}
86117
}
87118
}

src/Tests/Nest.Tests.Unit/QueryParsers/Queries/SpanNotQueryTests.cs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public void SpanNot_Deserializes()
1111
var q = this.SerializeThenDeserialize(
1212
f=>f.SpanNot,
1313
f=>f.SpanNot(sn=>sn
14+
.Pre(1)
15+
.Post(2)
16+
.Dist(3)
1417
.Include(e =>e.SpanTerm(p => p.Name, "elasticsearch.pm", 1.1))
1518
.Exclude(e=>e.SpanTerm(p => p.Name, "elasticsearch.pm", 1.1))
1619
)

src/Tests/Nest.Tests.Unit/Search/Query/Singles/SpanNotQueryJson.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ public void SpanNotQuery()
1313
.From(0)
1414
.Size(10)
1515
.Query(q => q
16-
.SpanNot(sf=>sf
17-
.Include(e =>e.SpanTerm(f => f.Name, "elasticsearch.pm", 1.1))
18-
.Exclude(e=>e.SpanTerm(f => f.Name, "elasticsearch.pm", 1.1))
19-
.Boost(2.2)
16+
.SpanNot(sf => sf
17+
.Pre(1)
18+
.Post(2)
19+
.Dist(3)
20+
.Include(e => e.SpanTerm(f => f.Name, "elasticsearch.pm", 1.1))
21+
.Exclude(e => e.SpanTerm(f => f.Name, "elasticsearch.pm", 1.1))
22+
.Boost(2.2)
2023
)
2124
);
2225
var json = TestElasticClient.Serialize(s);
@@ -39,7 +42,10 @@ public void SpanNotQuery()
3942
}
4043
}
4144
},
42-
boost: 2.2
45+
boost: 2.2,
46+
pre: 1,
47+
post: 2,
48+
dist: 3
4349
}}}";
4450
Assert.True(json.JsonEquals(expected), json);
4551
}

0 commit comments

Comments
 (0)