Skip to content

Commit

Permalink
Fix #3325 Add support for zero_terms_query to match_phrase query (#3363)
Browse files Browse the repository at this point in the history
(cherry picked from commit 93400ac)
  • Loading branch information
Mpdreamz committed Sep 3, 2018
1 parent 56109cf commit a684be9
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public interface IMatchPhrasePrefixQuery : IFieldNameQuery

[JsonProperty("slop")]
int? Slop { get; set; }

/// <summary>
/// If the analyzer used removes all tokens in a query like a stop filter does, the default behavior is
/// to match no documents at all. In order to change that, <see cref="ZeroTermsQuery"/> can be used,
/// which accepts <see cref="ZeroTermsQuery.None"/> (default) and <see cref="ZeroTermsQuery.All"/>
/// which corresponds to a match_all query.
/// </summary>
[JsonProperty("zero_terms_query")]
ZeroTermsQuery? ZeroTermsQuery { get; set; }
}

public class MatchPhrasePrefixQuery : FieldNameQueryBase, IMatchPhrasePrefixQuery
Expand All @@ -28,6 +37,8 @@ public class MatchPhrasePrefixQuery : FieldNameQueryBase, IMatchPhrasePrefixQuer
public int? MaxExpansions { get; set; }
public string Query { get; set; }
public int? Slop { get; set; }
/// <inheritdoc />
public ZeroTermsQuery? ZeroTermsQuery { get; set; }

internal override void InternalWrapInContainer(IQueryContainer c) => c.MatchPhrasePrefix = this;

Expand All @@ -44,6 +55,7 @@ public class MatchPhrasePrefixQueryDescriptor<T>
string IMatchPhrasePrefixQuery.Analyzer { get; set; }
int? IMatchPhrasePrefixQuery.MaxExpansions { get; set; }
int? IMatchPhrasePrefixQuery.Slop { get; set; }
ZeroTermsQuery? IMatchPhrasePrefixQuery.ZeroTermsQuery { get; set; }

public MatchPhrasePrefixQueryDescriptor<T> Query(string query) => Assign(a => a.Query = query);

Expand All @@ -52,5 +64,9 @@ public class MatchPhrasePrefixQueryDescriptor<T>
public MatchPhrasePrefixQueryDescriptor<T> MaxExpansions(int? maxExpansions) => Assign(a => a.MaxExpansions = maxExpansions);

public MatchPhrasePrefixQueryDescriptor<T> Slop(int? slop) => Assign(a => a.Slop = slop);

/// <inheritdoc cref="IMatchQuery.ZeroTermsQuery" />
public MatchPhrasePrefixQueryDescriptor<T> ZeroTermsQuery(ZeroTermsQuery? zeroTermsQuery) => Assign(a => a.ZeroTermsQuery = zeroTermsQuery);

}
}

0 comments on commit a684be9

Please sign in to comment.