From 8b8c65d7b76e974760163612b7b93bccc8787653 Mon Sep 17 00:00:00 2001 From: adelinowona Date: Thu, 27 Mar 2025 14:10:48 -0400 Subject: [PATCH] CSHARP-5541: move rankFusion methods to IAggregateFluentExtensions --- src/MongoDB.Driver/AggregateFluent.cs | 22 -------- src/MongoDB.Driver/AggregateFluentBase.cs | 23 -------- src/MongoDB.Driver/IAggregateFluent.cs | 35 ------------ .../IAggregateFluentExtensions.cs | 56 +++++++++++++++++++ .../Search/RankFusionScoreDetails.cs | 2 +- 5 files changed, 57 insertions(+), 81 deletions(-) diff --git a/src/MongoDB.Driver/AggregateFluent.cs b/src/MongoDB.Driver/AggregateFluent.cs index c43d79a3525..90bd9823ce1 100644 --- a/src/MongoDB.Driver/AggregateFluent.cs +++ b/src/MongoDB.Driver/AggregateFluent.cs @@ -257,28 +257,6 @@ public override IAggregateFluent Project(ProjectionDefin return WithPipeline(_pipeline.Project(projection)); } - public override IAggregateFluent RankFusion( - Dictionary> pipelines, - Dictionary weights = null, - RankFusionOptions options = null) - { - return WithPipeline(_pipeline.RankFusion(pipelines, weights, options)); - } - - public override IAggregateFluent RankFusion( - PipelineDefinition[] pipelines, - RankFusionOptions options = null) - { - return WithPipeline(_pipeline.RankFusion(pipelines, options)); - } - - public override IAggregateFluent RankFusion( - (PipelineDefinition, double?)[] pipelinesWithWeights, - RankFusionOptions options = null) - { - return WithPipeline(_pipeline.RankFusion(pipelinesWithWeights, options)); - } - public override IAggregateFluent ReplaceRoot(AggregateExpressionDefinition newRoot) { return WithPipeline(_pipeline.ReplaceRoot(newRoot)); diff --git a/src/MongoDB.Driver/AggregateFluentBase.cs b/src/MongoDB.Driver/AggregateFluentBase.cs index 795d9ab1164..51381f930bd 100644 --- a/src/MongoDB.Driver/AggregateFluentBase.cs +++ b/src/MongoDB.Driver/AggregateFluentBase.cs @@ -225,29 +225,6 @@ public virtual Task> OutAsync(IMongoCollection ou /// public abstract IAggregateFluent Project(ProjectionDefinition projection); - /// - public virtual IAggregateFluent RankFusion( - Dictionary> pipelines, - Dictionary weights = null, - RankFusionOptions options = null) - { - throw new NotImplementedException(); - } - - /// - public virtual IAggregateFluent RankFusion(PipelineDefinition[] pipelines, RankFusionOptions options = null) - { - throw new NotImplementedException(); - } - - /// - public virtual IAggregateFluent RankFusion( - (PipelineDefinition, double?)[] pipelinesWithWeights, - RankFusionOptions options = null) - { - throw new NotImplementedException(); - } - /// public virtual IAggregateFluent ReplaceRoot(AggregateExpressionDefinition newRoot) { diff --git a/src/MongoDB.Driver/IAggregateFluent.cs b/src/MongoDB.Driver/IAggregateFluent.cs index 3a458b3877a..dfb0b821ec8 100644 --- a/src/MongoDB.Driver/IAggregateFluent.cs +++ b/src/MongoDB.Driver/IAggregateFluent.cs @@ -365,41 +365,6 @@ IAggregateFluent Lookup IAggregateFluent Project(ProjectionDefinition projection); - /// - /// Appends a $rankFusion stage to the pipeline. - /// - /// The type of the new result. - /// The map of named pipelines whose results will be combined. The pipelines must operate on the same collection. - /// The map of pipeline names to non-negative numerical weights determining result importance during combination. Default weight is 1 when unspecified. - /// The rankFusion options. - /// The fluent aggregate interface. - IAggregateFluent RankFusion( - Dictionary> pipelines, - Dictionary weights = null, - RankFusionOptions options = null); - - /// - /// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc. - /// - /// The type of the new result. - /// The collection of pipelines whose results will be combined. The pipelines must operate on the same collection. - /// The rankFusion options. - /// The fluent aggregate interface. - IAggregateFluent RankFusion( - PipelineDefinition[] pipelines, - RankFusionOptions options = null); - - /// - /// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc. - /// - /// The type of the new result. - /// The collection of tuples containing (pipeline, weight) pairs. The pipelines must operate on the same collection. - /// The rankFusion options. - /// The fluent aggregate interface. - IAggregateFluent RankFusion( - (PipelineDefinition, double?)[] pipelinesWithWeights, - RankFusionOptions options = null); - /// /// Appends a $replaceRoot stage to the pipeline. /// diff --git a/src/MongoDB.Driver/IAggregateFluentExtensions.cs b/src/MongoDB.Driver/IAggregateFluentExtensions.cs index c19b94ec667..fba43b6a38a 100644 --- a/src/MongoDB.Driver/IAggregateFluentExtensions.cs +++ b/src/MongoDB.Driver/IAggregateFluentExtensions.cs @@ -563,6 +563,62 @@ public static IAggregateFluent Project(this IAg return aggregate.AppendStage(PipelineStageDefinitionBuilder.Project(projection)); } + /// + /// Appends a $rankFusion stage to the pipeline. + /// + /// The type of the result. + /// The type of the new result. + /// The aggregate. + /// The map of named pipelines whose results will be combined. The pipelines must operate on the same collection. + /// The map of pipeline names to non-negative numerical weights determining result importance during combination. Default weight is 1 when unspecified. + /// The rankFusion options. + /// The fluent aggregate interface. + public static IAggregateFluent RankFusion( + this IAggregateFluent aggregate, + Dictionary> pipelines, + Dictionary weights = null, + RankFusionOptions options = null) + { + Ensure.IsNotNull(aggregate, nameof(aggregate)); + return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelines, weights, options)); + } + + /// + /// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc. + /// + /// The type of the result. + /// The type of the new result. + /// The aggregate. + /// The collection of pipelines whose results will be combined. The pipelines must operate on the same collection. + /// The rankFusion options. + /// The fluent aggregate interface. + public static IAggregateFluent RankFusion( + this IAggregateFluent aggregate, + PipelineDefinition[] pipelines, + RankFusionOptions options = null) + { + Ensure.IsNotNull(aggregate, nameof(aggregate)); + return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelines, options)); + } + + /// + /// Appends a $rankFusion stage to the pipeline. Pipelines will be automatically named as "pipeline1", "pipeline2", etc. + /// + /// The type of the result. + /// The type of the new result. + /// The aggregate. + /// The collection of tuples containing (pipeline, weight) pairs. The pipelines must operate on the same collection. + /// The rankFusion options. + /// The fluent aggregate interface. + public static IAggregateFluent RankFusion( + this IAggregateFluent aggregate, + (PipelineDefinition, double?)[] pipelinesWithWeights, + RankFusionOptions options = null) + { + Ensure.IsNotNull(aggregate, nameof(aggregate)); + return aggregate.AppendStage(PipelineStageDefinitionBuilder.RankFusion(pipelinesWithWeights, options)); + } + /// /// Appends a $replaceRoot stage to the pipeline. /// diff --git a/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs b/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs index 7832529aff6..c9b3156ddd7 100644 --- a/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs +++ b/src/MongoDB.Driver/Search/RankFusionScoreDetails.cs @@ -30,7 +30,7 @@ public sealed class RankFusionScoreDetails /// The computed score which is the same as the score available via {$meta: "score"}. /// Description of how the score was computed. /// Info about how each input pipeline in the rankFusion stage contributed to the computed score. - /// + /// public RankFusionScoreDetails(double value, string description, BsonDocument[] details) { Value = value;