Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,6 @@ private static readonly MethodInfo FullTextCatalogIsAccentSensitiveMethodInfo
= typeof(SqlServerFullTextCatalogBuilder).GetRuntimeMethod(
nameof(SqlServerFullTextCatalogBuilder.IsAccentSensitive), [typeof(bool)])!;

private static readonly MethodInfo IndexHasFullTextKeyIndexMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextKeyIndex), [typeof(IndexBuilder), typeof(string)])!;

private static readonly MethodInfo IndexHasFullTextCatalogMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextCatalog), [typeof(IndexBuilder), typeof(string)])!;

private static readonly MethodInfo IndexHasFullTextChangeTrackingMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextChangeTracking), [typeof(IndexBuilder), typeof(FullTextChangeTracking)])!;

private static readonly MethodInfo IndexHasFullTextLanguageMethodInfo
= typeof(SqlServerIndexBuilderExtensions).GetRuntimeMethod(
nameof(SqlServerIndexBuilderExtensions.HasFullTextLanguage), [typeof(IndexBuilder), typeof(string), typeof(string)])!;

#endregion MethodInfos

/// <summary>
Expand Down Expand Up @@ -469,30 +453,6 @@ protected override bool IsHandledByConvention(IProperty property, IAnnotation an
_ => null
};

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public override IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
IIndex index,
IDictionary<string, IAnnotation> annotations)
{
var fragments = new List<MethodCallCodeFragment>(base.GenerateFluentApiCalls(index, annotations));

if (annotations.Remove(SqlServerAnnotationNames.FullTextLanguages, out var languagesAnnotation)
&& languagesAnnotation.Value is Dictionary<string, string> languages)
{
foreach (var (propertyName, language) in languages.OrderBy(l => l.Key))
{
fragments.Add(new MethodCallCodeFragment(IndexHasFullTextLanguageMethodInfo, propertyName, language));
}
}

return fragments;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand All @@ -515,13 +475,6 @@ public override IReadOnlyList<MethodCallCodeFragment> GenerateFluentApiCalls(
SqlServerAnnotationNames.DataCompression
=> new MethodCallCodeFragment(IndexUseDataCompressionMethodInfo, annotation.Value),

SqlServerAnnotationNames.FullTextIndex
=> new MethodCallCodeFragment(IndexHasFullTextKeyIndexMethodInfo, annotation.Value),
SqlServerAnnotationNames.FullTextCatalog
=> new MethodCallCodeFragment(IndexHasFullTextCatalogMethodInfo, annotation.Value),
SqlServerAnnotationNames.FullTextChangeTracking
=> new MethodCallCodeFragment(IndexHasFullTextChangeTrackingMethodInfo, annotation.Value),

_ => null
};

Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.SqlServer/Extensions/FullTextSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.EntityFrameworkCore;
namespace Microsoft.EntityFrameworkCore.Query;

/// <summary>
/// Represents the results from a call to
/// <see cref="SqlServerQueryableExtensions.FreeTextTable{T, TKey}(DbSet{T}, Expression{Func{T, object}}, string, string?, int?)" /> or
/// <see cref="SqlServerQueryableExtensions.ContainsTable{T, TKey}(DbSet{T}, Expression{Func{T, object}}, string, string?, int?)" />.
/// <see cref="SqlServerQueryableExtensions.FreeTextTable{T, TKey}(DbSet{T}, string, Expression{Func{T, object}}?, string?, int?)" /> or
/// <see cref="SqlServerQueryableExtensions.ContainsTable{T, TKey}(DbSet{T}, string, Expression{Func{T, object}}?, string?, int?)" />.
/// </summary>
/// <typeparam name="TKey">The type of the full-text key column for the table being searched.</typeparam>
public readonly struct FullTextSearchResult<TKey>(TKey key, int rank)
Expand Down
166 changes: 14 additions & 152 deletions src/EFCore.SqlServer/Extensions/SqlServerIndexBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,54 +572,20 @@ public static bool CanSetDataCompression(
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="keyIndexName">The name of the KEY INDEX.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder HasFullTextKeyIndex(this IndexBuilder indexBuilder, string keyIndexName)
{
Check.NotEmpty(keyIndexName);

indexBuilder.Metadata.SetFullTextKeyIndex(keyIndexName);

return indexBuilder;
}

/// <summary>
/// Configures the KEY INDEX for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="keyIndexName">The name of the KEY INDEX.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> HasFullTextKeyIndex<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
string keyIndexName)
=> (IndexBuilder<TEntity>)HasFullTextKeyIndex((IndexBuilder)indexBuilder, keyIndexName);

/// <summary>
/// Configures the KEY INDEX for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="keyIndexName">The name of the KEY INDEX.</param>
/// <param name="keyIndex">The name of the KEY INDEX.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionIndexBuilder? HasFullTextKeyIndex(
this IConventionIndexBuilder indexBuilder,
string? keyIndexName,
string? keyIndex,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetFullTextKeyIndex(keyIndexName, fromDataAnnotation))
if (indexBuilder.CanSetFullTextKeyIndex(keyIndex, fromDataAnnotation))
{
indexBuilder.Metadata.SetFullTextKeyIndex(keyIndexName, fromDataAnnotation);
indexBuilder.Metadata.SetFullTextKeyIndex(keyIndex, fromDataAnnotation);

return indexBuilder;
}
Expand All @@ -635,48 +601,14 @@ public static IndexBuilder<TEntity> HasFullTextKeyIndex<TEntity>(
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="keyIndexName">The name of the KEY INDEX.</param>
/// <param name="keyIndex">The name of the KEY INDEX.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the index can be configured with the specified KEY INDEX when targeting SQL Server.</returns>
public static bool CanSetFullTextKeyIndex(
this IConventionIndexBuilder indexBuilder,
string? keyIndexName,
string? keyIndex,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.FullTextIndex, keyIndexName, fromDataAnnotation);

/// <summary>
/// Configures the full-text catalog for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="catalogName">The name of the full-text catalog.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder HasFullTextCatalog(this IndexBuilder indexBuilder, string catalogName)
{
Check.NotEmpty(catalogName);

indexBuilder.Metadata.SetFullTextCatalog(catalogName);

return indexBuilder;
}

/// <summary>
/// Configures the full-text catalog for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="catalogName">The name of the full-text catalog.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> HasFullTextCatalog<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
string catalogName)
=> (IndexBuilder<TEntity>)HasFullTextCatalog((IndexBuilder)indexBuilder, catalogName);
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.FullTextIndex, keyIndex, fromDataAnnotation);

/// <summary>
/// Configures the full-text catalog for the full-text index when targeting SQL Server.
Expand All @@ -686,20 +618,20 @@ public static IndexBuilder<TEntity> HasFullTextCatalog<TEntity>(
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="catalogName">The name of the full-text catalog.</param>
/// <param name="catalog">The name of the full-text catalog.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>
/// The same builder instance if the configuration was applied,
/// <see langword="null" /> otherwise.
/// </returns>
public static IConventionIndexBuilder? HasFullTextCatalog(
this IConventionIndexBuilder indexBuilder,
string? catalogName,
string? catalog,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetFullTextCatalog(catalogName, fromDataAnnotation))
if (indexBuilder.CanSetFullTextCatalog(catalog, fromDataAnnotation))
{
indexBuilder.Metadata.SetFullTextCatalog(catalogName, fromDataAnnotation);
indexBuilder.Metadata.SetFullTextCatalog(catalog, fromDataAnnotation);

return indexBuilder;
}
Expand All @@ -715,46 +647,14 @@ public static IndexBuilder<TEntity> HasFullTextCatalog<TEntity>(
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="catalogName">The name of the full-text catalog.</param>
/// <param name="catalog">The name of the full-text catalog.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the index can be configured with the specified full-text catalog when targeting SQL Server.</returns>
public static bool CanSetFullTextCatalog(
this IConventionIndexBuilder indexBuilder,
string? catalogName,
string? catalog,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.FullTextCatalog, catalogName, fromDataAnnotation);

/// <summary>
/// Configures the change tracking mode for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="changeTracking">The change tracking mode.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder HasFullTextChangeTracking(this IndexBuilder indexBuilder, FullTextChangeTracking changeTracking)
{
indexBuilder.Metadata.SetFullTextChangeTracking(changeTracking);

return indexBuilder;
}

/// <summary>
/// Configures the change tracking mode for the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="changeTracking">The change tracking mode.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> HasFullTextChangeTracking<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
FullTextChangeTracking changeTracking)
=> (IndexBuilder<TEntity>)HasFullTextChangeTracking((IndexBuilder)indexBuilder, changeTracking);
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.FullTextCatalog, catalog, fromDataAnnotation);

/// <summary>
/// Configures the change tracking mode for the full-text index when targeting SQL Server.
Expand Down Expand Up @@ -805,44 +705,6 @@ public static bool CanSetFullTextChangeTracking(
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(SqlServerAnnotationNames.FullTextChangeTracking, changeTracking, fromDataAnnotation);

/// <summary>
/// Configures the language for a specific property in the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyName">The name of the property.</param>
/// <param name="language">The language term (e.g. "English", "1033").</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder HasFullTextLanguage(this IndexBuilder indexBuilder, string propertyName, string language)
{
Check.NotEmpty(propertyName);
Check.NotEmpty(language);

indexBuilder.Metadata.SetFullTextLanguage(propertyName, language);

return indexBuilder;
}

/// <summary>
/// Configures the language for a specific property in the full-text index when targeting SQL Server.
/// </summary>
/// <remarks>
/// See <see href="https://learn.microsoft.com/sql/relational-databases/search/full-text-search">Full-Text Search</see>
/// for more information on SQL Server full-text search.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="propertyName">The name of the property.</param>
/// <param name="language">The language term (e.g. "English", "1033").</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> HasFullTextLanguage<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
string propertyName,
string language)
=> (IndexBuilder<TEntity>)HasFullTextLanguage((IndexBuilder)indexBuilder, propertyName, language);

/// <summary>
/// Configures the languages for properties in the full-text index when targeting SQL Server.
/// </summary>
Expand Down
Loading
Loading