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 @@ -883,88 +883,6 @@ public static bool CanSetDefaultTimeToLive(
bool fromDataAnnotation = false)
=> entityTypeBuilder.CanSetAnnotation(CosmosAnnotationNames.DefaultTimeToLive, seconds, fromDataAnnotation);

/// <summary>
/// Configures a default language to use for full-text search at container scope.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="language">The default language.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static EntityTypeBuilder HasDefaultFullTextLanguage(
this EntityTypeBuilder entityTypeBuilder,
string? language)
{
entityTypeBuilder.Metadata.SetDefaultFullTextSearchLanguage(language);

return entityTypeBuilder;
}

/// <summary>
/// Configures a default language to use for full-text search at container scope.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="language">The default language.</param>
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
public static EntityTypeBuilder<TEntity> HasDefaultFullTextLanguage<TEntity>(
this EntityTypeBuilder<TEntity> entityTypeBuilder,
string? language)
where TEntity : class
=> (EntityTypeBuilder<TEntity>)HasDefaultFullTextLanguage((EntityTypeBuilder)entityTypeBuilder, language);

/// <summary>
/// Configures a default language to use for full-text search at container scope.
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="language">The default language.</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 IConventionEntityTypeBuilder? HasDefaultFullTextLanguage(
this IConventionEntityTypeBuilder entityTypeBuilder,
string? language,
bool fromDataAnnotation = false)
{
if (!entityTypeBuilder.CanSetDefaultFullTextLanguage(language, fromDataAnnotation))
{
return null;
}

entityTypeBuilder.Metadata.SetDefaultFullTextSearchLanguage(language, fromDataAnnotation);

return entityTypeBuilder;
}

/// <summary>
/// Returns a value indicating whether the default full-text language can be set
/// from the current configuration source
/// </summary>
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="entityTypeBuilder">The builder for the entity type being configured.</param>
/// <param name="language">The default language.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns><see langword="true" /> if the configuration can be applied.</returns>
public static bool CanSetDefaultFullTextLanguage(
this IConventionEntityTypeBuilder entityTypeBuilder,
string? language,
bool fromDataAnnotation = false)
=> entityTypeBuilder.CanSetAnnotation(CosmosAnnotationNames.DefaultFullTextSearchLanguage, language, fromDataAnnotation);

/// <summary>
/// Configures the manual provisioned throughput offering.
/// </summary>
Expand Down
44 changes: 0 additions & 44 deletions src/EFCore.Cosmos/Extensions/CosmosEntityTypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -586,48 +586,4 @@ public static void SetThroughput(this IMutableEntityType entityType, int? throug
public static ConfigurationSource? GetThroughputConfigurationSource(this IConventionEntityType entityType)
=> entityType.FindAnnotation(CosmosAnnotationNames.Throughput)
?.GetConfigurationSource();

/// <summary>
/// Returns the default language for the full-text search at container scope.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <returns>The default language for the full-text search.</returns>
public static string? GetDefaultFullTextSearchLanguage(this IReadOnlyEntityType entityType)
=> entityType.BaseType != null
? entityType.GetRootType().GetDefaultFullTextSearchLanguage()
: (string?)entityType[CosmosAnnotationNames.DefaultFullTextSearchLanguage];

/// <summary>
/// Sets the default language for the full-text search at container scope.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="language">The default language for the full-text search.</param>
public static void SetDefaultFullTextSearchLanguage(this IMutableEntityType entityType, string? language)
=> entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.DefaultFullTextSearchLanguage,
language);

/// <summary>
/// Sets the default language for the full-text search at container scope.
/// </summary>
/// <param name="entityType">The entity type.</param>
/// <param name="language">The default language for the full-text search.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
public static string? SetDefaultFullTextSearchLanguage(
this IConventionEntityType entityType,
string? language,
bool fromDataAnnotation = false)
=> (string?)entityType.SetOrRemoveAnnotation(
CosmosAnnotationNames.DefaultFullTextSearchLanguage,
language,
fromDataAnnotation)?.Value;

/// <summary>
/// Gets the <see cref="ConfigurationSource" /> for the default full-text search language at container scope.
/// </summary>
/// <param name="entityType">The entity type to find configuration source for.</param>
/// <returns>The <see cref="ConfigurationSource" /> for the default full-text search language.</returns>
public static ConfigurationSource? GetDefaultFullTextSearchLanguageConfigurationSource(this IConventionEntityType entityType)
=> entityType.FindAnnotation(CosmosAnnotationNames.DefaultFullTextSearchLanguage)
?.GetConfigurationSource();
}
36 changes: 21 additions & 15 deletions src/EFCore.Cosmos/Extensions/CosmosIndexBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public static class CosmosIndexBuilderExtensions
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="indexType">The type of vector index to create.</param>
/// <param name="vectorIndex">The value indicating whether the index is configured as a vector index.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IsVectorIndex(this IndexBuilder indexBuilder, VectorIndexType? indexType)
public static IndexBuilder IsVectorIndex(
this IndexBuilder indexBuilder,
VectorIndexType? indexType,
bool vectorIndex = true)
{
indexBuilder.Metadata.SetVectorIndexType(indexType);
indexBuilder.Metadata.SetVectorIndexType(indexType, vectorIndex);

return indexBuilder;
}
Expand All @@ -43,10 +47,12 @@ public static IndexBuilder IsVectorIndex(this IndexBuilder indexBuilder, VectorI
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="indexType">The type of vector index to create.</param>
/// <param name="vectorIndex">The value indicating whether the index is configured as a vector index.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IsVectorIndex<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
VectorIndexType? indexType)
VectorIndexType? indexType,
bool vectorIndex = true)
=> (IndexBuilder<TEntity>)IsVectorIndex((IndexBuilder)indexBuilder, indexType);

/// <summary>
Expand Down Expand Up @@ -104,11 +110,11 @@ public static bool CanSetVectorIndexType(
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="value">The value indicating whether the index is configured for Full-text search.</param>
/// <param name="fullTextIndex">The value indicating whether the index is configured for Full-text search.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder IsFullTextIndex(this IndexBuilder indexBuilder, bool? value = true)
public static IndexBuilder IsFullTextIndex(this IndexBuilder indexBuilder, bool fullTextIndex = true)
{
indexBuilder.Metadata.SetIsFullTextIndex(value);
indexBuilder.Metadata.SetIsFullTextIndex(fullTextIndex);

return indexBuilder;
}
Expand All @@ -122,12 +128,12 @@ public static IndexBuilder IsFullTextIndex(this IndexBuilder indexBuilder, bool?
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="value">The value indicating whether the index is configured for Full-text search.</param>
/// <param name="fullTextIndex">The value indicating whether the index is configured for Full-text search.</param>
/// <returns>A builder to further configure the index.</returns>
public static IndexBuilder<TEntity> IsFullTextIndex<TEntity>(
this IndexBuilder<TEntity> indexBuilder,
bool? value = true)
=> (IndexBuilder<TEntity>)IsFullTextIndex((IndexBuilder)indexBuilder, value);
bool fullTextIndex = true)
=> (IndexBuilder<TEntity>)IsFullTextIndex((IndexBuilder)indexBuilder, fullTextIndex);

/// <summary>
/// Configures the index as a full-text index.
Expand All @@ -138,20 +144,20 @@ public static IndexBuilder<TEntity> IsFullTextIndex<TEntity>(
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="value">The value indicating whether the index is configured for Full-text search.</param>
/// <param name="fullTextIndex">The value indicating whether the index is configured for Full-text search.</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? IsFullTextIndex(
this IConventionIndexBuilder indexBuilder,
bool? value,
bool? fullTextIndex,
bool fromDataAnnotation = false)
{
if (indexBuilder.CanSetIsFullTextIndex(fromDataAnnotation))
{
indexBuilder.Metadata.SetIsFullTextIndex(value, fromDataAnnotation);
indexBuilder.Metadata.SetIsFullTextIndex(fullTextIndex, fromDataAnnotation);
return indexBuilder;
}

Expand All @@ -166,12 +172,12 @@ public static IndexBuilder<TEntity> IsFullTextIndex<TEntity>(
/// <see href="https://aka.ms/efcore-docs-cosmos">Accessing Azure Cosmos DB with EF Core</see> for more information and examples.
/// </remarks>
/// <param name="indexBuilder">The builder for the index being configured.</param>
/// <param name="value">The value indicating whether the index is configured for Full-text search.</param>
/// <param name="fullTextIndex">The value indicating whether the index is configured for Full-text search.</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 as a Full-text index.</returns>
public static bool CanSetIsFullTextIndex(
this IConventionIndexBuilder indexBuilder,
bool? value,
bool? fullTextIndex,
bool fromDataAnnotation = false)
=> indexBuilder.CanSetAnnotation(CosmosAnnotationNames.FullTextIndex, value, fromDataAnnotation);
=> indexBuilder.CanSetAnnotation(CosmosAnnotationNames.FullTextIndex, fullTextIndex, fromDataAnnotation);
}
30 changes: 21 additions & 9 deletions src/EFCore.Cosmos/Extensions/CosmosIndexExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,32 @@ public static class CosmosIndexExtensions
/// </summary>
/// <param name="index">The index.</param>
/// <param name="indexType">The index type to use.</param>
public static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType)
=> index.SetAnnotation(CosmosAnnotationNames.VectorIndexType, indexType);
/// <param name="vectorIndex">The value indicating whether the index is configured as a vector index.</param>
public static void SetVectorIndexType(this IMutableIndex index, VectorIndexType? indexType, bool? vectorIndex)
{
if (vectorIndex == true)
{
index.SetAnnotation(CosmosAnnotationNames.VectorIndexType, indexType);
}
else
{
index.RemoveAnnotation(CosmosAnnotationNames.VectorIndexType);
}
}

/// <summary>
/// Sets the vector index type to use, such as "flat", "diskANN", or "quantizedFlat".
/// See <see href="https://aka.ms/ef-cosmos-vectors">Vector Search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="indexType">The index type to use.</param>
/// <param name="index">The index.</param>
/// <param name="indexType">The index type to use.</param>
/// <param name="vectorIndex">The value indicating whether the index is configured as a vector index.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetVectorIndexType(
this IConventionIndex index,
VectorIndexType? indexType,
bool? vectorIndex,
bool fromDataAnnotation = false)
=> (string?)index.SetAnnotation(
CosmosAnnotationNames.VectorIndexType,
Expand Down Expand Up @@ -76,25 +88,25 @@ public static void SetVectorIndexType(this IMutableIndex index, VectorIndexType?
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="value">The value indicating whether the index is configured for full-text search.</param>
public static void SetIsFullTextIndex(this IMutableIndex index, bool? value)
=> index.SetAnnotation(CosmosAnnotationNames.FullTextIndex, value);
/// <param name="fullTextIndex">The value indicating whether the index is configured for full-text search.</param>
public static void SetIsFullTextIndex(this IMutableIndex index, bool? fullTextIndex)
=> index.SetAnnotation(CosmosAnnotationNames.FullTextIndex, fullTextIndex);

/// <summary>
/// Configures the index for full-text search.
/// See <see href="https://learn.microsoft.com/azure/cosmos-db/gen-ai/full-text-search">Full-text search in Azure Cosmos DB for NoSQL</see> for more information.
/// </summary>
/// <param name="index">The index.</param>
/// <param name="value">The value indicating whether the index is configured for full-text search.</param>
/// <param name="fullTextIndex">The value indicating whether the index is configured for full-text search.</param>
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
/// <returns>The configured value.</returns>
public static string? SetIsFullTextIndex(
this IConventionIndex index,
bool? value,
bool? fullTextIndex,
bool fromDataAnnotation = false)
=> (string?)index.SetAnnotation(
CosmosAnnotationNames.FullTextIndex,
value,
fullTextIndex,
fromDataAnnotation)?.Value;

/// <summary>
Expand Down
Loading
Loading