Skip to content

CSHARP-5541: move rankFusion methods to IAggregateFluentExtensions #1648

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
Mar 27, 2025
Merged
Show file tree
Hide file tree
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
22 changes: 0 additions & 22 deletions src/MongoDB.Driver/AggregateFluent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,28 +257,6 @@ public override IAggregateFluent<TNewResult> Project<TNewResult>(ProjectionDefin
return WithPipeline(_pipeline.Project(projection));
}

public override IAggregateFluent<TNewResult> RankFusion<TNewResult>(
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Dictionary<string, double> weights = null,
RankFusionOptions<TNewResult> options = null)
{
return WithPipeline(_pipeline.RankFusion(pipelines, weights, options));
}

public override IAggregateFluent<TNewResult> RankFusion<TNewResult>(
PipelineDefinition<TResult, TNewResult>[] pipelines,
RankFusionOptions<TNewResult> options = null)
{
return WithPipeline(_pipeline.RankFusion(pipelines, options));
}

public override IAggregateFluent<TNewResult> RankFusion<TNewResult>(
(PipelineDefinition<TResult, TNewResult>, double?)[] pipelinesWithWeights,
RankFusionOptions<TNewResult> options = null)
{
return WithPipeline(_pipeline.RankFusion(pipelinesWithWeights, options));
}

public override IAggregateFluent<TNewResult> ReplaceRoot<TNewResult>(AggregateExpressionDefinition<TResult, TNewResult> newRoot)
{
return WithPipeline(_pipeline.ReplaceRoot(newRoot));
Expand Down
23 changes: 0 additions & 23 deletions src/MongoDB.Driver/AggregateFluentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,29 +225,6 @@ public virtual Task<IAsyncCursor<TResult>> OutAsync(IMongoCollection<TResult> ou
/// <inheritdoc />
public abstract IAggregateFluent<TNewResult> Project<TNewResult>(ProjectionDefinition<TResult, TNewResult> projection);

/// <inheritdoc />
public virtual IAggregateFluent<TNewResult> RankFusion<TNewResult>(
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Dictionary<string, double> weights = null,
RankFusionOptions<TNewResult> options = null)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public virtual IAggregateFluent<TNewResult> RankFusion<TNewResult>(PipelineDefinition<TResult, TNewResult>[] pipelines, RankFusionOptions<TNewResult> options = null)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public virtual IAggregateFluent<TNewResult> RankFusion<TNewResult>(
(PipelineDefinition<TResult, TNewResult>, double?)[] pipelinesWithWeights,
RankFusionOptions<TNewResult> options = null)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public virtual IAggregateFluent<TNewResult> ReplaceRoot<TNewResult>(AggregateExpressionDefinition<TResult, TNewResult> newRoot)
{
Expand Down
35 changes: 0 additions & 35 deletions src/MongoDB.Driver/IAggregateFluent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,41 +365,6 @@ IAggregateFluent<TNewResult> Lookup<TForeignDocument, TAsElement, TAs, TNewResul
/// </returns>
IAggregateFluent<TNewResult> Project<TNewResult>(ProjectionDefinition<TResult, TNewResult> projection);

/// <summary>
/// Appends a $rankFusion stage to the pipeline.
/// </summary>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="pipelines">The map of named pipelines whose results will be combined. The pipelines must operate on the same collection.</param>
/// <param name="weights">The map of pipeline names to non-negative numerical weights determining result importance during combination. Default weight is 1 when unspecified.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
IAggregateFluent<TNewResult> RankFusion<TNewResult>(
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Dictionary<string, double> weights = null,
RankFusionOptions<TNewResult> options = null);

/// <summary>
/// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc.
/// </summary>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="pipelines">The collection of pipelines whose results will be combined. The pipelines must operate on the same collection.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
IAggregateFluent<TNewResult> RankFusion<TNewResult>(
PipelineDefinition<TResult, TNewResult>[] pipelines,
RankFusionOptions<TNewResult> options = null);

/// <summary>
/// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc.
/// </summary>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="pipelinesWithWeights">The collection of tuples containing (pipeline, weight) pairs. The pipelines must operate on the same collection.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
IAggregateFluent<TNewResult> RankFusion<TNewResult>(
(PipelineDefinition<TResult, TNewResult>, double?)[] pipelinesWithWeights,
RankFusionOptions<TNewResult> options = null);

/// <summary>
/// Appends a $replaceRoot stage to the pipeline.
/// </summary>
Expand Down
56 changes: 56 additions & 0 deletions src/MongoDB.Driver/IAggregateFluentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,62 @@ public static IAggregateFluent<TNewResult> Project<TResult, TNewResult>(this IAg
return aggregate.AppendStage(PipelineStageDefinitionBuilder.Project(projection));
}

/// <summary>
/// Appends a $rankFusion stage to the pipeline.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="aggregate">The aggregate.</param>
/// <param name="pipelines">The map of named pipelines whose results will be combined. The pipelines must operate on the same collection.</param>
/// <param name="weights">The map of pipeline names to non-negative numerical weights determining result importance during combination. Default weight is 1 when unspecified.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
public static IAggregateFluent<TNewResult> RankFusion<TResult, TNewResult>(
this IAggregateFluent<TResult> aggregate,
Dictionary<string, PipelineDefinition<TResult, TNewResult>> pipelines,
Dictionary<string, double> weights = null,
RankFusionOptions<TNewResult> options = null)
{
Ensure.IsNotNull(aggregate, nameof(aggregate));
return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelines, weights, options));
}

/// <summary>
/// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="aggregate">The aggregate.</param>
/// <param name="pipelines">The collection of pipelines whose results will be combined. The pipelines must operate on the same collection.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
public static IAggregateFluent<TNewResult> RankFusion<TResult, TNewResult>(
this IAggregateFluent<TResult> aggregate,
PipelineDefinition<TResult, TNewResult>[] pipelines,
RankFusionOptions<TNewResult> options = null)
{
Ensure.IsNotNull(aggregate, nameof(aggregate));
return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelines, options));
}

/// <summary>
/// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc.
/// </summary>
/// <typeparam name="TResult">The type of the result.</typeparam>
/// <typeparam name="TNewResult">The type of the new result.</typeparam>
/// <param name="aggregate">The aggregate.</param>
/// <param name="pipelinesWithWeights">The collection of tuples containing (pipeline, weight) pairs. The pipelines must operate on the same collection.</param>
/// <param name="options">The rankFusion options.</param>
/// <returns>The fluent aggregate interface.</returns>
public static IAggregateFluent<TNewResult> RankFusion<TResult, TNewResult>(
this IAggregateFluent<TResult> aggregate,
(PipelineDefinition<TResult, TNewResult>, double?)[] pipelinesWithWeights,
RankFusionOptions<TNewResult> options = null)
{
Ensure.IsNotNull(aggregate, nameof(aggregate));
return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelinesWithWeights, options));
}

/// <summary>
/// Appends a $replaceRoot stage to the pipeline.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/MongoDB.Driver/Search/RankFusionScoreDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class RankFusionScoreDetails
/// <param name="value">The computed score which is the same as the score available via {$meta: "score"}.</param>
/// <param name="description">Description of how the score was computed.</param>
/// <param name="details">Info about how each input pipeline in the rankFusion stage contributed to the computed score.</param>
/// <seealso cref="IAggregateFluent{TResult}.RankFusion{TNewResult}(Dictionary{string,PipelineDefinition{TResult,TNewResult}}, Dictionary{string,double}, RankFusionOptions{TNewResult})"/>
/// <seealso cref="IAggregateFluentExtensions.RankFusion{TResult, TNewResult}(IAggregateFluent{TResult}, Dictionary{string,PipelineDefinition{TResult,TNewResult}}, Dictionary{string,double}, RankFusionOptions{TNewResult})"/>
public RankFusionScoreDetails(double value, string description, BsonDocument[] details)
{
Value = value;
Expand Down