-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5543: Add new options for Atlas Search Text and Phrase operators #1678
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few minor comments
/// <summary> | ||
/// The score modifier. | ||
/// </summary> | ||
public SearchScoreDefinition<TDocument> Score { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetic order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/// The criteria to use to match the terms in the query. Value can be either "any" or "all". | ||
/// Defaults to "all" if omitted. | ||
/// </summary> | ||
public string MatchCriteria { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check if this can be enum.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be ok!
@@ -457,6 +470,7 @@ internal sealed class TextSearchDefinition<TDocument> : OperatorSearchDefinition | |||
private readonly SearchFuzzyOptions _fuzzy; | |||
private readonly SearchQueryDefinition _query; | |||
private readonly string _synonyms; | |||
private readonly string _matchCriteria; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetical order.
/// <summary> | ||
/// Represents the criteria used to match terms in a query for the Atlas Search Text operator. | ||
/// </summary> | ||
public enum MatchCriteria |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should in Search folder (and namespace).
@@ -329,11 +330,23 @@ public PhraseSearchDefinition( | |||
_slop = slop; | |||
} | |||
|
|||
public PhraseSearchDefinition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need two ctors? This class is internal so it's safe to change.
/// The criteria to use to match the terms in the query. Value can be either "any" or "all". | ||
/// Defaults to "all" if omitted. | ||
/// </summary> | ||
public MatchCriteria MatchCriteria { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say we do not need the property be nullable. It should simply have the default value of MatchCriteria.All
. Why do we need additional third state of null
?
private protected override BsonDocument RenderArguments(RenderArgs<TDocument> args) => | ||
new() | ||
{ | ||
{ "query", _query.Render() }, | ||
{ "fuzzy", () => _fuzzy.Render(), _fuzzy != null }, | ||
{ "synonyms", _synonyms, _synonyms != null } | ||
{ "synonyms", _synonyms, _synonyms != null }, | ||
{ "matchCriteria", _matchCriteria == MatchCriteria.Any ? "any" : "all", _matchCriteria != null } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases CSharp driver do not write default values into the wire, so the check should skip on writing "all":
{ "matchCriteria", _matchCriteria == MatchCriteria.Any ? "any" : "all", _matchCriteria != null && _matchCriteria != MatchCriteria.All }
Making _matchCriteria
non-nullable will simplify the check:
{ "matchCriteria", _matchCriteria == MatchCriteria.Any ? "any" : "all", _matchCriteria != MatchCriteria.All }
/// The criteria to use to match the terms in the query. Value can be either "any" or "all". | ||
/// Defaults to "all" if omitted. | ||
/// </summary> | ||
public MatchCriteria MatchCriteria { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property should default to "all", but the default value of the enum is Any. Need to change enum to have All as default value.
@@ -455,6 +468,7 @@ private protected override BsonDocument RenderArguments(RenderArgs<TDocument> ar | |||
internal sealed class TextSearchDefinition<TDocument> : OperatorSearchDefinition<TDocument> | |||
{ | |||
private readonly SearchFuzzyOptions _fuzzy; | |||
private readonly MatchCriteria? _matchCriteria; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it should not be nullable.
/// <summary> | ||
/// Match documents containing all the terms from a query. | ||
/// </summary> | ||
All |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All should be the first enum value to make it default.
|
||
AssertRendered( | ||
subject.Text("x", "foo", new SearchTextOptions<BsonDocument> {Score = scoreBuilder.Constant(1), MatchCriteria = MatchCriteria.All}), | ||
"{ text: { query: 'foo', matchCriteria: 'all', path: 'x', score: { constant: { value: 1 } } } }"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we skip on writing the default matchCriteria
value?
/// The criteria to use to match the terms in the query. Value can be either "any" or "all". | ||
/// Defaults to "all" if omitted. | ||
/// </summary> | ||
public MatchCriteria MatchCriteria { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say we do not need the property be nullable. It should simply have the default value of MatchCriteria.All
. Why do we need additional third state of null
?
_query = Ensure.IsNotNull(query, nameof(query)); | ||
_fuzzy = options?.Fuzzy; | ||
_synonyms = options?.Synonyms; | ||
_matchCriteria = options?.MatchCriteria; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_matchCriteria = options?.MatchCriteria ?? MatchCriteria.All;
(see comment below)
private protected override BsonDocument RenderArguments(RenderArgs<TDocument> args) => | ||
new() | ||
{ | ||
{ "query", _query.Render() }, | ||
{ "fuzzy", () => _fuzzy.Render(), _fuzzy != null }, | ||
{ "synonyms", _synonyms, _synonyms != null } | ||
{ "synonyms", _synonyms, _synonyms != null }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we omit empty string also?
/// <summary> | ||
/// The name of the synonym mapping definition in the index definition. Value can't be an empty string. | ||
/// </summary> | ||
public string Synonyms { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xml-docs says: Value can't be an empty string
. Should we enforce this condition?
private protected override BsonDocument RenderArguments(RenderArgs<TDocument> args) => | ||
new() | ||
{ | ||
{ "query", _query.Render() }, | ||
{ "slop", _slop, _slop != null } | ||
{ "slop", _slop, _slop != null }, | ||
{ "synonyms", _synonyms, _synonyms != null } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we omit empty string also?
No description provided.