From cedc59555ca161d0043e53fdc736ba8eb5c1712a Mon Sep 17 00:00:00 2001 From: Changan Han <167555843+changanhan@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:46:24 -0400 Subject: [PATCH] Add FullTextIndexes to IndexingPolicy and add FullTextPolicy to ContainerProperties --- .../Resource/Settings/ContainerProperties.cs | 29 ++++++++ .../Resource/Settings/FullTextIndexPath.cs | 61 ++++++++++++++++ .../src/Resource/Settings/FullTextPath.cs | 70 +++++++++++++++++++ .../src/Resource/Settings/FullTextPolicy.cs | 70 +++++++++++++++++++ .../src/Resource/Settings/IndexingPolicy.cs | 27 +++++++ 5 files changed, 257 insertions(+) create mode 100644 Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextIndexPath.cs create mode 100644 Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPath.cs create mode 100644 Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPolicy.cs diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/ContainerProperties.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/ContainerProperties.cs index fea8747a79..f8af8b5b7d 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/ContainerProperties.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/ContainerProperties.cs @@ -84,6 +84,9 @@ public class ContainerProperties [JsonProperty(PropertyName = "computedProperties", NullValueHandling = NullValueHandling.Ignore)] private Collection computedProperties; + [JsonProperty(PropertyName = "fullTextPolicy", NullValueHandling = NullValueHandling.Ignore)] + private FullTextPolicy fullTextPolicyInternal; + /// /// This contains additional values for scenarios where the SDK is not aware of new fields. /// This ensures that if resource is read and updated none of the fields will be lost in the process. @@ -360,6 +363,32 @@ Collection ComputedProperties } } + /// + /// Gets or sets the full text policy containing paths for full text paths along with path-specific settings for the item + /// used in performing full text search on the items in a collection in the Azure CosmosDB database service. + /// + /// + /// It is an optional property. + /// By default, FullTextPolicy is set to null meaning the feature is turned off for the container. + /// + /// + /// + /// The will be applied to all the items in the container as the default policy. + /// + /// + [JsonIgnore] +#if PREVIEW + public +#else + internal +#endif + FullTextPolicy FullTextPolicy + { + get => this.fullTextPolicyInternal; + + set => this.fullTextPolicyInternal = value; + } + /// /// Gets the associated with the container from the Azure Cosmos DB service. /// diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextIndexPath.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextIndexPath.cs new file mode 100644 index 0000000000..5d33954d1b --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextIndexPath.cs @@ -0,0 +1,61 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos +{ + using System.Collections.Generic; + using Microsoft.Azure.Documents; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + using Newtonsoft.Json.Linq; + + /// + /// DOM for a vector index path. A vector index path is used in a vector index. + /// + /// + /// + /// +#if PREVIEW + public +#else + internal +#endif + sealed class FullTextIndexPath + { + /// + /// Gets or sets the full path in a document used for full text indexing. + /// + [JsonProperty(PropertyName = Constants.Properties.Path)] + public string Path { get; set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + } +} \ No newline at end of file diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPath.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPath.cs new file mode 100644 index 0000000000..1d4b7cb03f --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPath.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ + +namespace Microsoft.Azure.Cosmos +{ + using System; + using System.Collections.Generic; + using Microsoft.Azure.Documents; + using Newtonsoft.Json; + using Newtonsoft.Json.Converters; + using Newtonsoft.Json.Linq; + + /// + /// Represents the embedding settings for the vector index. + /// +#if PREVIEW + public +#else + internal +#endif + class FullTextPath : IEquatable + { + /// + /// Gets or sets a string containing the path of the full text index. + /// + [JsonProperty(PropertyName = Constants.Properties.Path)] + public string Path { get; set; } + + /// + /// Gets or sets a string containing the language of the full text path. + /// + [JsonProperty(PropertyName = "language")] + public string Language { get; set; } + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + + /// + /// Ensures that the paths specified in the full text policy are valid. + /// + public void ValidateFullTextPath() + { + if (string.IsNullOrEmpty(this.Path)) + { + throw new ArgumentException("Argument {0} can't be null or empty.", nameof(this.Path)); + } + + if (string.IsNullOrEmpty(this.Language)) + { + throw new ArgumentException("Argument {0} can't be null or empty.", nameof(this.Language)); + } + + if (this.Path[0] != '/') + { + throw new ArgumentException("The argument {0} is not a valid path.", this.Path); + } + } + + /// + public bool Equals(FullTextPath that) + { + return this.Path.Equals(that.Path) && this.Language.Equals(that.Language); + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPolicy.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPolicy.cs new file mode 100644 index 0000000000..913b883191 --- /dev/null +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPolicy.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +//------------------------------------------------------------ +namespace Microsoft.Azure.Cosmos +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using Newtonsoft.Json; + using Newtonsoft.Json.Linq; + + /// + /// Represents the full text policy configuration for specifying the full text paths on documents in the collection in the Azure Cosmos DB service. + /// + /// +#if PREVIEW + public +#else + internal +#endif + sealed class FullTextPolicy + { + /// + /// Initializes a new instance of the class. + /// + /// String of the default language of the container. + /// List of full text paths to include in the policy definition. + public FullTextPolicy(string defaultLanguage, Collection fullTextPaths) + { + if (fullTextPaths != null) + { + FullTextPolicy.ValidateFullTextPaths(fullTextPaths); + } + + this.DefaultLanguage = defaultLanguage; + this.FullTextPaths = fullTextPaths; + } + + /// + /// Gets or sets a string containing the default language of the container. + /// + [JsonProperty(PropertyName = "defaultLanguage", NullValueHandling=NullValueHandling.Ignore)] + public string DefaultLanguage { get; set; } + + /// + /// Gets a collection of that contains the full text paths of documents in collection in the Azure Cosmos DB service. + /// + [JsonProperty(PropertyName = "fullTextPaths", NullValueHandling=NullValueHandling.Ignore)] + public readonly Collection FullTextPaths; + + /// + /// This contains additional values for scenarios where the SDK is not aware of new fields. + /// This ensures that if resource is read and updated none of the fields will be lost in the process. + /// + [JsonExtensionData] + internal IDictionary AdditionalProperties { get; private set; } + + /// + /// Ensures that the specified full text paths in the policy are valid. + /// + private static void ValidateFullTextPaths( + IEnumerable fullTextPaths) + { + foreach (FullTextPath item in fullTextPaths) + { + item.ValidateFullTextPath(); + } + } + } +} diff --git a/Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs b/Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs index b8e0323b76..3f0ff274b6 100644 --- a/Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs +++ b/Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs @@ -147,6 +147,33 @@ public IndexingPolicy() #endif Collection VectorIndexes { get; set; } = new Collection(); + /// + /// Gets the full text indexes + /// + /// + /// + /// + [JsonProperty(PropertyName = "fullTextIndexes", NullValueHandling = NullValueHandling.Ignore)] +#if PREVIEW + + public +#else + internal +#endif + Collection FullTextIndexes { get; set; } = new Collection(); + /// /// This contains additional values for scenarios where the SDK is not aware of new fields. /// This ensures that if resource is read and updated none of the fields will be lost in the process.