Skip to content

Fix #3325 Add support for zero_terms_query to match_phrase query #3363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

}
}