Skip to content

Commit a5035dc

Browse files
committed
fix FTContainsAll/Any for constants, change TFScore signature to accept params
1 parent da1edaf commit a5035dc

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Diff for: src/EFCore.Cosmos/Extensions/CosmosDbFunctionsExtensions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ public static bool FullTextContainsAny(this DbFunctions _, string property, para
8989
/// Returns the full-text search score for the specified property and keywords.
9090
/// </summary>
9191
/// <param name="_">The <see cref="DbFunctions" /> instance.</param>
92-
/// <param name="property">The property to search.</param>
93-
/// <param name="keywords">The keywords to search for.</param>
92+
/// <param name="property">The property to score.</param>
93+
/// <param name="keywords">The keywords to score by.</param>
9494
/// <returns>The full-text search score.</returns>
9595
[Experimental(EFDiagnostics.CosmosFullTextSearchExperimental)]
96-
public static double FullTextScore(this DbFunctions _, string property, string[] keywords)
96+
public static double FullTextScore(this DbFunctions _, string property, params string[] keywords)
9797
=> throw new InvalidOperationException(CoreStrings.FunctionOnClient(nameof(FullTextScore)));
9898

9999
/// <summary>

Diff for: src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.InExpressionValuesExpandingExpressionVisitor.cs

+24-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected override Expression VisitExtension(Expression expression)
8585
return base.VisitExtension(expression);
8686
}
8787

88-
// Inlines array parameter of full-text functions, transforming FullTextContains(x, @keywordsArray) to FullTextContains(x, keyword1, keyword2))
88+
// Inlines array parameter of full-text functions, transforming FullTextContainsAll(x, @keywordsArray) to FullTextContainsAll(x, keyword1, keyword2))
8989
case SqlFunctionExpression
9090
{
9191
Name: "FullTextContainsAny" or "FullTextContainsAll",
@@ -106,6 +106,29 @@ protected override Expression VisitExtension(Expression expression)
106106
fullTextContainsAllAnyFunction.TypeMapping);
107107
}
108108

109+
// Inlines array parameter of full-text score, transforming FullTextScore(x, @keywordsArray) to FullTextScore(x, [keyword1, keyword2]))
110+
case SqlFunctionExpression
111+
{
112+
Name: "FullTextScore",
113+
IsScoringFunction: true,
114+
Arguments: [var property, SqlParameterExpression { TypeMapping: { ElementTypeMapping: not null } typeMapping } keywords]
115+
} fullTextScoreFunction
116+
when !UseOldBehavior35476:
117+
{
118+
var keywordValues = new List<string>();
119+
foreach (var value in (IEnumerable)parametersValues[keywords.Name])
120+
{
121+
keywordValues.Add((string)value);
122+
}
123+
124+
return new SqlFunctionExpression(
125+
fullTextScoreFunction.Name,
126+
isScoringFunction: true,
127+
[property, sqlExpressionFactory.Constant(keywordValues, typeMapping)],
128+
fullTextScoreFunction.Type,
129+
fullTextScoreFunction.TypeMapping);
130+
}
131+
109132
default:
110133
return expression;
111134
}

Diff for: src/EFCore.Cosmos/Query/Internal/Translators/CosmosFullTextSearchTranslator.cs

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public class CosmosFullTextSearchTranslator(ISqlExpressionFactory sqlExpressionF
6565
typeof(double),
6666
typeMappingSource.FindMapping(typeof(double))),
6767

68+
nameof(CosmosDbFunctionsExtensions.FullTextContainsAny) or nameof(CosmosDbFunctionsExtensions.FullTextContainsAll)
69+
when arguments is [_, SqlExpression property, SqlConstantExpression { Type: var keywordClrType, Value: string[] values } keywords]
70+
&& keywordClrType == typeof(string[]) => sqlExpressionFactory.Function(
71+
method.Name == nameof(CosmosDbFunctionsExtensions.FullTextContainsAny) ? "FullTextContainsAny" : "FullTextContainsAll",
72+
[property, .. values.Select(x => sqlExpressionFactory.Constant(x))],
73+
typeof(bool),
74+
typeMappingSource.FindMapping(typeof(bool))),
75+
6876
nameof(CosmosDbFunctionsExtensions.FullTextContainsAny) or nameof(CosmosDbFunctionsExtensions.FullTextContainsAll)
6977
when arguments is [_, SqlExpression property, SqlParameterExpression { Type: var keywordClrType } keywords]
7078
&& keywordClrType == typeof(string[]) => sqlExpressionFactory.Function(

0 commit comments

Comments
 (0)