Skip to content

Commit fae09d6

Browse files
committed
Move new IAggregateFluent members to extension methods
1 parent b576e95 commit fae09d6

File tree

5 files changed

+98
-111
lines changed

5 files changed

+98
-111
lines changed

src/MongoDB.Driver/AggregateFluent.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,6 @@ public override IAggregateFluent<TResult> Search(
299299
return WithPipeline(_pipeline.Search(searchDefinition, searchOptions));
300300
}
301301

302-
public override IAggregateFluent<TNewResult> Search<TNewResult>(
303-
SearchDefinition<TResult> searchDefinition,
304-
FieldDefinition<TResult, IEnumerable<TNewResult>> returnScope,
305-
SearchOptions<TResult> searchOptions = null)
306-
=> WithPipeline(_pipeline.Search(searchDefinition, returnScope, searchOptions));
307-
308302
public override IAggregateFluent<SearchMetaResult> SearchMeta(
309303
SearchDefinition<TResult> searchDefinition,
310304
string indexName = null,
@@ -313,13 +307,6 @@ public override IAggregateFluent<SearchMetaResult> SearchMeta(
313307
return WithPipeline(_pipeline.SearchMeta(searchDefinition, indexName, count));
314308
}
315309

316-
public override IAggregateFluent<SearchMetaResult> SearchMeta(
317-
SearchDefinition<TResult> searchDefinition,
318-
FieldDefinition<TResult> returnScope,
319-
string indexName = null,
320-
SearchCountOptions count = null)
321-
=> WithPipeline(_pipeline.SearchMeta(searchDefinition, returnScope, indexName, count));
322-
323310
public override IAggregateFluent<TResult> Set(SetFieldDefinitions<TResult> fields)
324311
{
325312
return WithPipeline(_pipeline.Set(fields));

src/MongoDB.Driver/AggregateFluentBase.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18-
using System.Linq.Expressions;
1918
using System.Threading;
2019
using System.Threading.Tasks;
2120
using MongoDB.Bson;
@@ -257,50 +256,13 @@ public virtual IAggregateFluent<TResult> Search(
257256
SearchOptions<TResult> searchOptions)
258257
=> throw new NotImplementedException();
259258

260-
/// <inheritdoc />
261-
public virtual IAggregateFluent<TNewResult> Search<TNewResult>(
262-
SearchDefinition<TResult> searchDefinition,
263-
FieldDefinition<TResult, IEnumerable<TNewResult>> returnScope,
264-
SearchOptions<TResult> searchOptions = null)
265-
=> throw new NotImplementedException();
266-
267-
/// <inheritdoc />
268-
public virtual IAggregateFluent<TNewResult> Search<TNewResult>(
269-
SearchDefinition<TResult> searchDefinition,
270-
Expression<Func<TResult, IEnumerable<TNewResult>>> returnScope,
271-
SearchOptions<TResult> searchOptions = null)
272-
=> Search(
273-
searchDefinition,
274-
new ExpressionFieldDefinition<TResult, IEnumerable<TNewResult>>(returnScope),
275-
searchOptions);
276-
277-
/// <inheritdoc />
278-
public virtual IAggregateFluent<SearchMetaResult> SearchMeta(
279-
SearchDefinition<TResult> searchDefinition,
280-
string indexName = null,
281-
SearchCountOptions count = null)
282-
=> throw new NotImplementedException();
283-
284259
/// <inheritdoc />
285260
public virtual IAggregateFluent<SearchMetaResult> SearchMeta(
286261
SearchDefinition<TResult> searchDefinition,
287-
FieldDefinition<TResult> returnScope,
288262
string indexName = null,
289263
SearchCountOptions count = null)
290264
=> throw new NotImplementedException();
291265

292-
/// <inheritdoc />
293-
public virtual IAggregateFluent<SearchMetaResult> SearchMeta(
294-
SearchDefinition<TResult> searchDefinition,
295-
Expression<Func<TResult, object>> returnScope,
296-
string indexName = null,
297-
SearchCountOptions count = null)
298-
=> SearchMeta(
299-
searchDefinition,
300-
new ExpressionFieldDefinition<TResult>(returnScope),
301-
indexName,
302-
count);
303-
304266
/// <inheritdoc />
305267
public virtual IAggregateFluent<TResult> Set(SetFieldDefinitions<TResult> fields) => throw new NotImplementedException();
306268

src/MongoDB.Driver/IAggregateFluent.cs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -441,71 +441,15 @@ IAggregateFluent<TResult> Search(
441441
SearchDefinition<TResult> searchDefinition,
442442
SearchOptions<TResult> searchOptions);
443443

444-
/// <summary>
445-
/// Appends a $search stage to the pipeline, returning documents from a nested scope.
446-
/// </summary>
447-
/// <param name="searchDefinition">The search definition.</param>
448-
/// <param name="returnScope">The level of nested documents to return.</param>
449-
/// <param name="searchOptions">The search options.</param>
450-
/// <returns>
451-
/// The fluent aggregate interface.
452-
/// </returns>
453-
IAggregateFluent<TNewResult> Search<TNewResult>(
454-
SearchDefinition<TResult> searchDefinition,
455-
FieldDefinition<TResult, IEnumerable<TNewResult>> returnScope,
456-
SearchOptions<TResult> searchOptions = null);
457-
458-
/// <summary>
459-
/// Appends a $search stage to the pipeline, returning documents from a nested scope.
460-
/// </summary>
461-
/// <param name="searchDefinition">The search definition.</param>
462-
/// <param name="returnScope">The level of nested documents to return.</param>
463-
/// <param name="searchOptions">The search options.</param>
464-
/// <returns>
465-
/// The fluent aggregate interface.
466-
/// </returns>
467-
IAggregateFluent<TNewResult> Search<TNewResult>(
468-
SearchDefinition<TResult> searchDefinition,
469-
Expression<Func<TResult, IEnumerable<TNewResult>>> returnScope,
470-
SearchOptions<TResult> searchOptions = null);
471-
472-
/// <summary>
473-
/// Appends a $searchMeta stage to the pipeline.
474-
/// </summary>
475-
/// <param name="searchDefinition">The search definition.</param>
476-
/// <param name="indexName">The index name.</param>
477-
/// <param name="count">The count options.</param>
478-
/// <returns>The fluent aggregate interface.</returns>
479-
IAggregateFluent<SearchMetaResult> SearchMeta(
480-
SearchDefinition<TResult> searchDefinition,
481-
string indexName = null,
482-
SearchCountOptions count = null);
483-
484-
/// <summary>
485-
/// Appends a $searchMeta stage to the pipeline.
486-
/// </summary>
487-
/// <param name="searchDefinition">The search definition.</param>
488-
/// <param name="returnScope">The level of nested documents to return.</param>
489-
/// <param name="indexName">The index name.</param>
490-
/// <param name="count">The count options.</param>
491-
/// <returns>The fluent aggregate interface.</returns>
492-
IAggregateFluent<SearchMetaResult> SearchMeta(
493-
SearchDefinition<TResult> searchDefinition,
494-
FieldDefinition<TResult> returnScope,
495-
string indexName = null,
496-
SearchCountOptions count = null);
497-
498444
/// <summary>
499445
/// Appends a $searchMeta stage to the pipeline.
500446
/// </summary>
501447
/// <param name="searchDefinition">The search definition.</param>
502-
/// <param name="returnScope">The level of nested documents to return.</param>
503448
/// <param name="indexName">The index name.</param>
504449
/// <param name="count">The count options.</param>
505450
/// <returns>The fluent aggregate interface.</returns>
506451
IAggregateFluent<SearchMetaResult> SearchMeta(
507452
SearchDefinition<TResult> searchDefinition,
508-
Expression<Func<TResult, object>> returnScope,
509453
string indexName = null,
510454
SearchCountOptions count = null);
511455

src/MongoDB.Driver/IAggregateFluentExtensions.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using MongoDB.Bson.Serialization;
2424
using MongoDB.Driver.Core.Misc;
2525
using MongoDB.Driver.GeoJsonObjectModel;
26+
using MongoDB.Driver.Search;
2627

2728
namespace MongoDB.Driver
2829
{
@@ -694,6 +695,99 @@ public static IAggregateFluent<TNewResult> ReplaceWith<TResult, TNewResult>(
694695
return aggregate.AppendStage(PipelineStageDefinitionBuilder.ReplaceWith(newRoot));
695696
}
696697

698+
/// <summary>
699+
/// Appends a $search stage to the pipeline, returning documents from a nested scope.
700+
/// </summary>
701+
/// <typeparam name="TResult">The type of the result.</typeparam>
702+
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
703+
/// <param name="aggregate">The aggregate.</param>
704+
/// <param name="searchDefinition">The search definition.</param>
705+
/// <param name="returnScope">The level of nested documents to return.</param>
706+
/// <param name="searchOptions">The search options.</param>
707+
/// <returns>The fluent aggregate interface.</returns>
708+
public static IAggregateFluent<TNewResult> Search<TResult, TNewResult>(
709+
this IAggregateFluent<TResult> aggregate,
710+
SearchDefinition<TResult> searchDefinition,
711+
FieldDefinition<TResult, IEnumerable<TNewResult>> returnScope,
712+
SearchOptions<TResult> searchOptions = null)
713+
{
714+
Ensure.IsNotNull(aggregate, nameof(aggregate));
715+
Ensure.IsNotNull(searchDefinition, nameof(searchDefinition));
716+
Ensure.IsNotNull(returnScope, nameof(returnScope));
717+
718+
return aggregate.AppendStage(
719+
PipelineStageDefinitionBuilder.Search(searchDefinition, returnScope, searchOptions));
720+
}
721+
722+
/// <summary>
723+
/// Appends a $search stage to the pipeline, returning documents from a nested scope.
724+
/// </summary>
725+
/// <typeparam name="TResult">The type of the result.</typeparam>
726+
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
727+
/// <param name="aggregate">The aggregate.</param>
728+
/// <param name="searchDefinition">The search definition.</param>
729+
/// <param name="returnScope">The level of nested documents to return.</param>
730+
/// <param name="searchOptions">The search options.</param>
731+
/// <returns>The fluent aggregate interface.</returns>
732+
public static IAggregateFluent<TNewResult> Search<TResult, TNewResult>(
733+
this IAggregateFluent<TResult> aggregate,
734+
SearchDefinition<TResult> searchDefinition,
735+
Expression<Func<TResult, IEnumerable<TNewResult>>> returnScope,
736+
SearchOptions<TResult> searchOptions = null)
737+
=> Search(
738+
aggregate,
739+
searchDefinition,
740+
new ExpressionFieldDefinition<TResult, IEnumerable<TNewResult>>(returnScope),
741+
searchOptions);
742+
743+
/// <summary>
744+
/// Appends a $searchMeta stage to the pipeline.
745+
/// </summary>
746+
/// <typeparam name="TResult">The type of the result.</typeparam>
747+
/// <param name="aggregate">The aggregate.</param>
748+
/// <param name="searchDefinition">The search definition.</param>
749+
/// <param name="returnScope">The level of nested documents to return.</param>
750+
/// <param name="indexName">The index name.</param>
751+
/// <param name="count">The count options.</param>
752+
/// <returns>The fluent aggregate interface.</returns>
753+
public static IAggregateFluent<SearchMetaResult> SearchMeta<TResult>(
754+
this IAggregateFluent<TResult> aggregate,
755+
SearchDefinition<TResult> searchDefinition,
756+
FieldDefinition<TResult> returnScope,
757+
string indexName = null,
758+
SearchCountOptions count = null)
759+
{
760+
Ensure.IsNotNull(aggregate, nameof(aggregate));
761+
Ensure.IsNotNull(searchDefinition, nameof(searchDefinition));
762+
Ensure.IsNotNull(returnScope, nameof(returnScope));
763+
764+
return aggregate.AppendStage(
765+
PipelineStageDefinitionBuilder.SearchMeta(searchDefinition, returnScope, indexName, count));
766+
}
767+
768+
/// <summary>
769+
/// Appends a $searchMeta stage to the pipeline.
770+
/// </summary>
771+
/// <typeparam name="TResult">The type of the result.</typeparam>
772+
/// <param name="aggregate">The aggregate.</param>
773+
/// <param name="searchDefinition">The search definition.</param>
774+
/// <param name="returnScope">The level of nested documents to return.</param>
775+
/// <param name="indexName">The index name.</param>
776+
/// <param name="count">The count options.</param>
777+
/// <returns>The fluent aggregate interface.</returns>
778+
public static IAggregateFluent<SearchMetaResult> SearchMeta<TResult>(
779+
this IAggregateFluent<TResult> aggregate,
780+
SearchDefinition<TResult> searchDefinition,
781+
Expression<Func<TResult, object>> returnScope,
782+
string indexName = null,
783+
SearchCountOptions count = null)
784+
=> SearchMeta(
785+
aggregate,
786+
searchDefinition,
787+
new ExpressionFieldDefinition<TResult>(returnScope),
788+
indexName,
789+
count);
790+
697791
/// <summary>
698792
/// Appends a $set stage to the pipeline.
699793
/// </summary>

tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ public void ReturnScope(bool useExpression)
956956

957957
var query = useExpression
958958
? aggregate.Search(searchDefinition, e => e.Movies, searchOptions)
959-
: aggregate.Search<DirectedMovie>(searchDefinition, "movies", searchOptions);
959+
: aggregate.Search<Director, DirectedMovie>(searchDefinition, "movies", searchOptions);
960960

961961
var results = query.ToList();
962962
results.Count.Should().Be(1);
@@ -972,7 +972,7 @@ public void ReturnScope_nested_path()
972972
var searchDefinition = Builders<Director>.Search.Range("movies.reviews.rating", SearchRangeBuilder.Gte(8.0));
973973
var aggregate = GetReturnScopeCollection<Director>().Aggregate();
974974

975-
var results = aggregate.Search<DirectedMovieReview>(
975+
var results = aggregate.Search<Director, DirectedMovieReview>(
976976
searchDefinition,
977977
"movies.reviews",
978978
new() { IndexName = "returnScopeIndex2" }).ToList();
@@ -998,7 +998,7 @@ public void ReturnScope_HasRoot(bool useExpression)
998998
var searchOptions = new SearchOptions<Director>() { IndexName = "returnScopeIndex1" };
999999
var query = useExpression
10001000
? aggregate.Search(searchDefinition, e => e.Movies, searchOptions)
1001-
: aggregate.Search<DirectedMovie>(searchDefinition, "movies", searchOptions);
1001+
: aggregate.Search<Director, DirectedMovie>(searchDefinition, "movies", searchOptions);
10021002

10031003
var results = query.ToList();
10041004
results.Count.Should().Be(2);
@@ -1027,7 +1027,7 @@ public void ReturnScope_HasAncestor(bool useExpression)
10271027

10281028
var aggregate = GetReturnScopeCollection<Director>().Aggregate();
10291029

1030-
var results = aggregate.Search<DirectedMovieReview>(
1030+
var results = aggregate.Search<Director, DirectedMovieReview>(
10311031
searchDefinition,
10321032
"movies.reviews",
10331033
new() { IndexName = "returnScopeIndex2" }).ToList();

0 commit comments

Comments
 (0)