Skip to content

Commit 3839351

Browse files

File tree

12 files changed

+80
-5
lines changed

12 files changed

+80
-5
lines changed

src/Nest/Nest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@
10511051
<Compile Include="QueryDsl\Joining\Nested\NestedScoreMode.cs" />
10521052
<Compile Include="QueryDsl\Joining\ParentId\ParentIdQuery.cs" />
10531053
<Compile Include="QueryDsl\MatchAllQuery.cs" />
1054+
<Compile Include="QueryDsl\MatchNoneQuery.cs" />
10541055
<Compile Include="QueryDsl\MultiTermQueryRewrite\RewriteMultiTerm.cs" />
10551056
<Compile Include="QueryDsl\NestSpecific\ConditionlessQuery.cs" />
10561057
<Compile Include="QueryDsl\NestSpecific\RawQuery.cs" />

src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public interface IQueryContainer
2828
[JsonProperty("match_all")]
2929
IMatchAllQuery MatchAll { get; set; }
3030

31+
[JsonProperty("match_none")]
32+
IMatchNoneQuery MatchNone { get; set; }
33+
3134
[JsonProperty("term")]
3235
ITermQuery Term { get; set; }
3336

src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
88
{
99
private IBoolQuery _b;
1010
private IMatchAllQuery _matchAllQuery;
11+
private IMatchNoneQuery _matchNoneQuery;
1112
private ITermQuery _term;
1213
private IWildcardQuery _wildcard;
1314
private IPrefixQuery _prefix;
@@ -70,6 +71,7 @@ private T Set<T>(T value) where T : IQuery
7071
IRawQuery IQueryContainer.RawQuery { get { return _raw; } set { _raw = Set(value); } }
7172
IBoolQuery IQueryContainer.Bool { get { return _b; } set { _b = Set(value); } }
7273
IMatchAllQuery IQueryContainer.MatchAll { get { return _matchAllQuery; } set { _matchAllQuery = Set(value); } }
74+
IMatchNoneQuery IQueryContainer.MatchNone { get { return _matchNoneQuery; } set { _matchNoneQuery = Set(value); } }
7375
ITermQuery IQueryContainer.Term { get { return _term; } set { _term = Set(value); } }
7476
IWildcardQuery IQueryContainer.Wildcard { get { return _wildcard; } set { _wildcard = Set(value); } }
7577
IPrefixQuery IQueryContainer.Prefix { get { return _prefix; } set { _prefix = Set(value); } }

src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ public QueryContainer Boosting(Func<BoostingQueryDescriptor<T>, IBoostingQuery>
310310
public QueryContainer MatchAll(Func<MatchAllQueryDescriptor, IMatchAllQuery> selector = null) =>
311311
WrapInContainer(selector, (query, container) => container.MatchAll = query ?? new MatchAllQuery());
312312

313+
/// <summary>
314+
/// A query that matches no documents. This is the inverse of the match_all query.
315+
/// </summary>
316+
public QueryContainer MatchNone(Func<MatchNoneQueryDescriptor, IMatchNoneQuery> selector = null) =>
317+
WrapInContainer(selector, (query, container) => container.MatchNone = query ?? new MatchNoneQuery());
318+
313319
/// <summary>
314320
/// Matches documents that have fields that contain a term (not analyzed).
315321
/// The term query maps to Lucene TermQuery.

src/Nest/QueryDsl/MatchAllQuery.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ public class MatchAllQuery : QueryBase, IMatchAllQuery
1717

1818
protected override bool Conditionless => false;
1919

20-
internal override void InternalWrapInContainer(IQueryContainer container)
21-
{
22-
container.MatchAll = this;
23-
}
20+
internal override void InternalWrapInContainer(IQueryContainer container) => container.MatchAll = this;
2421
}
2522

2623
public class MatchAllQueryDescriptor
2724
: QueryDescriptorBase<MatchAllQueryDescriptor, IMatchAllQuery>
28-
, IMatchAllQuery
25+
, IMatchAllQuery
2926
{
3027
protected override bool Conditionless => false;
3128

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Nest
4+
{
5+
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
6+
[JsonConverter(typeof(ReadAsTypeJsonConverter<MatchNoneQuery>))]
7+
public interface IMatchNoneQuery : IQuery
8+
{
9+
}
10+
11+
public class MatchNoneQuery : QueryBase, IMatchNoneQuery
12+
{
13+
protected override bool Conditionless => false;
14+
15+
internal override void InternalWrapInContainer(IQueryContainer container) => container.MatchNone = this;
16+
}
17+
18+
public class MatchNoneQueryDescriptor
19+
: QueryDescriptorBase<MatchNoneQueryDescriptor, IMatchNoneQuery>
20+
, IMatchNoneQuery
21+
{
22+
protected override bool Conditionless => false;
23+
}
24+
}

src/Nest/QueryDsl/Query.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ public static QueryContainer Match(Func<MatchQueryDescriptor<T>, IMatchQuery> se
9595
public static QueryContainer MatchAll(Func<MatchAllQueryDescriptor, IMatchAllQuery> selector = null) =>
9696
new QueryContainerDescriptor<T>().MatchAll(selector);
9797

98+
public static QueryContainer MatchNone(Func<MatchNoneQueryDescriptor, IMatchNoneQuery> selector = null) =>
99+
new QueryContainerDescriptor<T>().MatchNone(selector);
100+
98101
public static QueryContainer MatchPhrase(Func<MatchPhraseQueryDescriptor<T>, IMatchQuery> selector) =>
99102
new QueryContainerDescriptor<T>().MatchPhrase(selector);
100103

src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ private void Write(string queryType, Field field = null)
106106

107107
public virtual void Visit(IMatchAllQuery query) => Write("match_all");
108108

109+
public virtual void Visit(IMatchNoneQuery query) => Write("match_none");
110+
109111
public virtual void Visit(IMoreLikeThisQuery query) => Write("more_like_this");
110112

111113
public virtual void Visit(IMultiMatchQuery query) => Write("multi_match");

src/Nest/QueryDsl/Visitor/QueryVisitor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public interface IQueryVisitor
4242
#pragma warning restore 618
4343
void Visit(IMatchQuery query);
4444
void Visit(IMatchAllQuery query);
45+
void Visit(IMatchNoneQuery query);
4546
void Visit(IMoreLikeThisQuery query);
4647
void Visit(IMultiMatchQuery query);
4748
void Visit(INestedQuery query);
@@ -151,6 +152,8 @@ public virtual void Visit(IMatchQuery query) { }
151152

152153
public virtual void Visit(IMatchAllQuery query) { }
153154

155+
public virtual void Visit(IMatchNoneQuery query) { }
156+
154157
public virtual void Visit(IMoreLikeThisQuery query) { }
155158

156159
public virtual void Visit(IMultiMatchQuery query) { }

src/Nest/QueryDsl/Visitor/QueryWalker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public void Walk(IQueryContainer qd, IQueryVisitor visitor)
1010
{
1111
visitor.Visit(qd);
1212
VisitQuery(qd.MatchAll, visitor, (v, d) => v.Visit(d));
13+
VisitQuery(qd.MatchNone, visitor, (v, d) => v.Visit(d));
1314
VisitQuery(qd.MoreLikeThis, visitor, (v, d) => v.Visit(d));
1415
VisitQuery(qd.MultiMatch, visitor, (v, d) => v.Visit(d));
1516
VisitQuery(qd.CommonTerms, visitor, (v, d) => v.Visit(d));

0 commit comments

Comments
 (0)