Skip to content

Commit 9189a58

Browse files
authored
CSHARP-4440: Incorporate MongoDB.Labs.Search library (#989)
1 parent 0bb42fa commit 9189a58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6487
-115
lines changed

Diff for: build.cake

+7
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ Task("TestAtlasDataLake")
240240
action: (BuildConfig buildConfig, Path testProject) =>
241241
RunTests(buildConfig, testProject, filter: "Category=\"AtlasDataLake\""));
242242

243+
Task("TestAtlasSearch")
244+
.IsDependentOn("Build")
245+
.DoesForEach(
246+
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
247+
action: (BuildConfig buildConfig, Path testProject) =>
248+
RunTests(buildConfig, testProject, filter: "Category=\"AtlasSearch\""));
249+
243250
Task("TestOcsp")
244251
.IsDependentOn("Build")
245252
.DoesForEach(

Diff for: evergreen/evergreen.yml

+20
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,15 @@ functions:
684684
${PREPARE_SHELL}
685685
evergreen/run-atlas-data-lake-test.sh
686686
687+
run-atlas-search-test:
688+
- command: shell.exec
689+
type: test
690+
params:
691+
working_dir: mongo-csharp-driver
692+
script: |
693+
${PREPARE_SHELL}
694+
ATLAS_SEARCH="${ATLAS_SEARCH}" evergreen/run-atlas-search-test.sh
695+
687696
run-ocsp-test:
688697
- command: shell.exec
689698
type: test
@@ -1202,6 +1211,10 @@ tasks:
12021211
- func: bootstrap-mongohoused
12031212
- func: run-atlas-data-lake-test
12041213

1214+
- name: atlas-search-test
1215+
commands:
1216+
- func: run-atlas-search-test
1217+
12051218
- name: test-serverless-net472
12061219
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
12071220
commands:
@@ -2068,6 +2081,13 @@ buildvariants:
20682081
tasks:
20692082
- name: atlas-data-lake-test
20702083

2084+
- name: atlas-search-test
2085+
display_name: "Atlas Search Tests"
2086+
run_on:
2087+
- windows-64-vs2017-test
2088+
tasks:
2089+
- name: atlas-search-test
2090+
20712091
- name: gssapi-auth-tests-windows
20722092
run_on:
20732093
- windows-64-vs2017-test

Diff for: evergreen/run-atlas-search-test.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -o xtrace
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Environment variables produced as output
7+
# ATLAS_SEARCH_TESTS_ENABLED Enable atlas search tests.
8+
9+
############################################
10+
# Main Program #
11+
############################################
12+
13+
echo "Running Atlas Search driver tests"
14+
15+
export ATLAS_SEARCH_TESTS_ENABLED=true
16+
17+
powershell.exe .\\build.ps1 --target=TestAtlasSearch

Diff for: src/MongoDB.Driver.Core/Core/Misc/Ensure.cs

+72-69
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ namespace MongoDB.Driver.Core.Misc
2727
[DebuggerStepThrough]
2828
public static class Ensure
2929
{
30+
/// <summary>
31+
/// Ensures that the value of a parameter is not null.
32+
/// </summary>
33+
/// <typeparam name="T">Type type of the value.</typeparam>
34+
/// <param name="value">The value of the parameter.</param>
35+
/// <param name="paramName">The name of the parameter.</param>
36+
/// <returns>The value of the parameter.</returns>
37+
public static Nullable<T> HasValue<T>(Nullable<T> value, string paramName) where T : struct
38+
{
39+
if (!value.HasValue)
40+
{
41+
throw new ArgumentException("The Nullable parameter must have a value.", paramName);
42+
}
43+
return value;
44+
}
45+
3046
/// <summary>
3147
/// Ensures that the value of a parameter is between a minimum and a maximum value.
3248
/// </summary>
@@ -65,34 +81,36 @@ public static T IsEqualTo<T>(T value, T comparand, string paramName)
6581
}
6682

6783
/// <summary>
68-
/// Ensures that the value of a parameter is greater than or equal to a comparand.
84+
/// Ensures that the value of a parameter is greater than a comparand.
6985
/// </summary>
7086
/// <typeparam name="T">Type type of the value.</typeparam>
7187
/// <param name="value">The value of the parameter.</param>
7288
/// <param name="comparand">The comparand.</param>
7389
/// <param name="paramName">The name of the parameter.</param>
7490
/// <returns>The value of the parameter.</returns>
75-
public static T IsGreaterThanOrEqualTo<T>(T value, T comparand, string paramName) where T : IComparable<T>
91+
public static T IsGreaterThan<T>(T value, T comparand, string paramName) where T : IComparable<T>
7692
{
77-
if (value.CompareTo(comparand) < 0)
93+
if (value.CompareTo(comparand) <= 0)
7894
{
79-
var message = string.Format("Value is not greater than or equal to {1}: {0}.", value, comparand);
95+
var message = $"Value is not greater than {comparand}: {value}.";
8096
throw new ArgumentOutOfRangeException(paramName, message);
8197
}
8298
return value;
8399
}
84100

85101
/// <summary>
86-
/// Ensures that the value of a parameter is greater than or equal to zero.
102+
/// Ensures that the value of a parameter is greater than or equal to a comparand.
87103
/// </summary>
104+
/// <typeparam name="T">Type type of the value.</typeparam>
88105
/// <param name="value">The value of the parameter.</param>
106+
/// <param name="comparand">The comparand.</param>
89107
/// <param name="paramName">The name of the parameter.</param>
90108
/// <returns>The value of the parameter.</returns>
91-
public static int IsGreaterThanOrEqualToZero(int value, string paramName)
109+
public static T IsGreaterThanOrEqualTo<T>(T value, T comparand, string paramName) where T : IComparable<T>
92110
{
93-
if (value < 0)
111+
if (value.CompareTo(comparand) < 0)
94112
{
95-
var message = string.Format("Value is not greater than or equal to 0: {0}.", value);
113+
var message = string.Format("Value is not greater than or equal to {1}: {0}.", value, comparand);
96114
throw new ArgumentOutOfRangeException(paramName, message);
97115
}
98116
return value;
@@ -104,79 +122,62 @@ public static int IsGreaterThanOrEqualToZero(int value, string paramName)
104122
/// <param name="value">The value of the parameter.</param>
105123
/// <param name="paramName">The name of the parameter.</param>
106124
/// <returns>The value of the parameter.</returns>
107-
public static long IsGreaterThanOrEqualToZero(long value, string paramName)
108-
{
109-
if (value < 0)
110-
{
111-
var message = string.Format("Value is not greater than or equal to 0: {0}.", value);
112-
throw new ArgumentOutOfRangeException(paramName, message);
113-
}
114-
return value;
115-
}
125+
public static int IsGreaterThanOrEqualToZero(int value, string paramName) =>
126+
IsGreaterThanOrEqualTo(value, 0, paramName);
116127

117128
/// <summary>
118129
/// Ensures that the value of a parameter is greater than or equal to zero.
119130
/// </summary>
120131
/// <param name="value">The value of the parameter.</param>
121132
/// <param name="paramName">The name of the parameter.</param>
122133
/// <returns>The value of the parameter.</returns>
123-
public static TimeSpan IsGreaterThanOrEqualToZero(TimeSpan value, string paramName)
124-
{
125-
if (value < TimeSpan.Zero)
126-
{
127-
var message = string.Format("Value is not greater than or equal to zero: {0}.", TimeSpanParser.ToString(value));
128-
throw new ArgumentOutOfRangeException(paramName, message);
129-
}
130-
return value;
131-
}
134+
public static long IsGreaterThanOrEqualToZero(long value, string paramName) =>
135+
IsGreaterThanOrEqualTo(value, 0, paramName);
136+
137+
/// <summary>
138+
/// Ensures that the value of a parameter is greater than or equal to zero.
139+
/// </summary>
140+
/// <param name="value">The value of the parameter.</param>
141+
/// <param name="paramName">The name of the parameter.</param>
142+
/// <returns>The value of the parameter.</returns>
143+
public static TimeSpan IsGreaterThanOrEqualToZero(TimeSpan value, string paramName) =>
144+
IsGreaterThanOrEqualTo(value, TimeSpan.Zero, paramName);
132145

133146
/// <summary>
134147
/// Ensures that the value of a parameter is greater than zero.
135148
/// </summary>
136149
/// <param name="value">The value of the parameter.</param>
137150
/// <param name="paramName">The name of the parameter.</param>
138151
/// <returns>The value of the parameter.</returns>
139-
public static int IsGreaterThanZero(int value, string paramName)
140-
{
141-
if (value <= 0)
142-
{
143-
var message = string.Format("Value is not greater than zero: {0}.", value);
144-
throw new ArgumentOutOfRangeException(paramName, message);
145-
}
146-
return value;
147-
}
152+
public static int IsGreaterThanZero(int value, string paramName) =>
153+
IsGreaterThan(value, 0, paramName);
148154

149155
/// <summary>
150156
/// Ensures that the value of a parameter is greater than zero.
151157
/// </summary>
152158
/// <param name="value">The value of the parameter.</param>
153159
/// <param name="paramName">The name of the parameter.</param>
154160
/// <returns>The value of the parameter.</returns>
155-
public static long IsGreaterThanZero(long value, string paramName)
156-
{
157-
if (value <= 0)
158-
{
159-
var message = string.Format("Value is not greater than zero: {0}.", value);
160-
throw new ArgumentOutOfRangeException(paramName, message);
161-
}
162-
return value;
163-
}
161+
public static long IsGreaterThanZero(long value, string paramName) =>
162+
IsGreaterThan(value, 0, paramName);
164163

165164
/// <summary>
166165
/// Ensures that the value of a parameter is greater than zero.
167166
/// </summary>
168167
/// <param name="value">The value of the parameter.</param>
169168
/// <param name="paramName">The name of the parameter.</param>
170169
/// <returns>The value of the parameter.</returns>
171-
public static TimeSpan IsGreaterThanZero(TimeSpan value, string paramName)
172-
{
173-
if (value <= TimeSpan.Zero)
174-
{
175-
var message = string.Format("Value is not greater than zero: {0}.", value);
176-
throw new ArgumentOutOfRangeException(paramName, message);
177-
}
178-
return value;
179-
}
170+
public static double IsGreaterThanZero(double value, string paramName) =>
171+
IsGreaterThan(value, 0, paramName);
172+
173+
/// <summary>
174+
/// Ensures that the value of a parameter is greater than zero.
175+
/// </summary>
176+
/// <param name="value">The value of the parameter.</param>
177+
/// <param name="paramName">The name of the parameter.</param>
178+
/// <returns>The value of the parameter.</returns>
179+
public static TimeSpan IsGreaterThanZero(TimeSpan value, string paramName) =>
180+
IsGreaterThan(value, TimeSpan.Zero, paramName);
180181

181182
/// <summary>
182183
/// Ensures that the value of a parameter is infinite or greater than or equal to zero.
@@ -247,22 +248,6 @@ public static IEnumerable<T> IsNotNullAndDoesNotContainAnyNulls<T>(IEnumerable<T
247248
return values;
248249
}
249250

250-
/// <summary>
251-
/// Ensures that the value of a parameter is not null.
252-
/// </summary>
253-
/// <typeparam name="T">Type type of the value.</typeparam>
254-
/// <param name="value">The value of the parameter.</param>
255-
/// <param name="paramName">The name of the parameter.</param>
256-
/// <returns>The value of the parameter.</returns>
257-
public static Nullable<T> HasValue<T>(Nullable<T> value, string paramName) where T : struct
258-
{
259-
if (!value.HasValue)
260-
{
261-
throw new ArgumentException("The Nullable parameter must have a value.", paramName);
262-
}
263-
return value;
264-
}
265-
266251
/// <summary>
267252
/// Ensures that the value of a parameter is not null or empty.
268253
/// </summary>
@@ -298,6 +283,24 @@ public static T IsNull<T>(T value, string paramName) where T : class
298283
return value;
299284
}
300285

286+
/// <summary>
287+
/// Ensures that the value of a parameter is null or is between a minimum and a maximum value.
288+
/// </summary>
289+
/// <typeparam name="T">Type type of the value.</typeparam>
290+
/// <param name="value">The value of the parameter.</param>
291+
/// <param name="min">The minimum value.</param>
292+
/// <param name="max">The maximum value.</param>
293+
/// <param name="paramName">The name of the parameter.</param>
294+
/// <returns>The value of the parameter.</returns>
295+
public static T? IsNullOrBetween<T>(T? value, T min, T max, string paramName) where T : struct, IComparable<T>
296+
{
297+
if (value != null)
298+
{
299+
IsBetween(value.Value, min, max, paramName);
300+
}
301+
return value;
302+
}
303+
301304
/// <summary>
302305
/// Ensures that the value of a parameter is null or greater than or equal to zero.
303306
/// </summary>

Diff for: src/MongoDB.Driver/AggregateFluent.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
* limitations under the License.
1414
*/
1515

16-
using MongoDB.Bson;
17-
using MongoDB.Bson.Serialization;
18-
using MongoDB.Driver.Core.Misc;
1916
using System.Collections.Generic;
2017
using System.Linq;
2118
using System.Threading;
2219
using System.Threading.Tasks;
20+
using MongoDB.Bson;
21+
using MongoDB.Bson.Serialization;
22+
using MongoDB.Driver.Core.Misc;
23+
using MongoDB.Driver.Search;
2324

2425
namespace MongoDB.Driver
2526
{
@@ -238,6 +239,24 @@ public override IAggregateFluent<TNewResult> ReplaceWith<TNewResult>(AggregateEx
238239
return WithPipeline(_pipeline.ReplaceWith(newRoot));
239240
}
240241

242+
public override IAggregateFluent<TResult> Search(
243+
SearchDefinition<TResult> searchDefinition,
244+
SearchHighlightOptions<TResult> highlight = null,
245+
string indexName = null,
246+
SearchCountOptions count = null,
247+
bool returnStoredSource = false)
248+
{
249+
return WithPipeline(_pipeline.Search(searchDefinition, highlight, indexName, count, returnStoredSource));
250+
}
251+
252+
public override IAggregateFluent<SearchMetaResult> SearchMeta(
253+
SearchDefinition<TResult> searchDefinition,
254+
string indexName = null,
255+
SearchCountOptions count = null)
256+
{
257+
return WithPipeline(_pipeline.SearchMeta(searchDefinition, indexName, count));
258+
}
259+
241260
public override IAggregateFluent<BsonDocument> SetWindowFields<TWindowFields>(
242261
AggregateExpressionDefinition<ISetWindowFieldsPartition<TResult>, TWindowFields> output)
243262
{

Diff for: src/MongoDB.Driver/AggregateFluentBase.cs

+21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Threading.Tasks;
2020
using MongoDB.Bson;
2121
using MongoDB.Bson.Serialization;
22+
using MongoDB.Driver.Search;
2223

2324
namespace MongoDB.Driver
2425
{
@@ -215,6 +216,26 @@ public virtual IAggregateFluent<TNewResult> ReplaceWith<TNewResult>(AggregateExp
215216
throw new NotImplementedException();
216217
}
217218

219+
/// <inheritdoc />
220+
public virtual IAggregateFluent<TResult> Search(
221+
SearchDefinition<TResult> searchDefinition,
222+
SearchHighlightOptions<TResult> highlight = null,
223+
string indexName = null,
224+
SearchCountOptions count = null,
225+
bool returnStoredSource = false)
226+
{
227+
throw new NotImplementedException();
228+
}
229+
230+
/// <inheritdoc />
231+
public virtual IAggregateFluent<SearchMetaResult> SearchMeta(
232+
SearchDefinition<TResult> searchDefinition,
233+
string indexName = null,
234+
SearchCountOptions count = null)
235+
{
236+
throw new NotImplementedException();
237+
}
238+
218239
/// <inheritdoc />
219240
public virtual IAggregateFluent<BsonDocument> SetWindowFields<TWindowFields>(
220241
AggregateExpressionDefinition<ISetWindowFieldsPartition<TResult>, TWindowFields> output)

0 commit comments

Comments
 (0)