Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FullTextIndexes to IndexingPolicy and add FullTextPolicy to ContainerProperties #4816

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -84,6 +84,9 @@ public class ContainerProperties
[JsonProperty(PropertyName = "computedProperties", NullValueHandling = NullValueHandling.Ignore)]
private Collection<ComputedProperty> computedProperties;

[JsonProperty(PropertyName = "fullTextPolicy", NullValueHandling = NullValueHandling.Ignore)]
private FullTextPolicy fullTextPolicyInternal;

/// <summary>
/// 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.
Expand Down Expand Up @@ -360,6 +363,32 @@ Collection<ComputedProperty> ComputedProperties
}
}

/// <summary>
/// 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.
/// </summary>
/// <value>
/// It is an optional property.
/// By default, FullTextPolicy is set to null meaning the feature is turned off for the container.
/// </value>
/// <remarks>
/// <para>
/// The <see cref="Cosmos.FullTextPolicy"/> will be applied to all the items in the container as the default policy.
/// </para>
/// </remarks>
[JsonIgnore]
#if PREVIEW
public
#else
internal
#endif
FullTextPolicy FullTextPolicy
{
get => this.fullTextPolicyInternal;

set => this.fullTextPolicyInternal = value;
}

/// <summary>
/// Gets the <see cref="ChangeFeedPolicy"/> associated with the container from the Azure Cosmos DB service.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// DOM for a vector index path. A vector index path is used in a vector index.
/// </summary>
/// <example>
/// <![CDATA[
/// "indexingPolicy": {
/// "includedPaths": [
/// {
/// "path": "/*"
/// }
/// ],
/// "excludedPaths": [
/// {
/// }
/// ],
/// "fullTextIndexes": [
/// {
/// "path": "/v1",
/// },
/// {
/// "path": "/v2",
/// },
/// {
/// "path": "/v3",
/// }
/// ]
/// }
/// ]]>
/// </example>
#if PREVIEW
public
#else
internal
#endif
sealed class FullTextIndexPath
{
/// <summary>
/// Gets or sets the full path in a document used for full text indexing.
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.Path)]
public string Path { get; set; }

/// <summary>
/// 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.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }
}
}
70 changes: 70 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPath.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Represents the embedding settings for the vector index.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class FullTextPath : IEquatable<FullTextPath>
{
/// <summary>
/// Gets or sets a string containing the path of the full text index.
/// </summary>
[JsonProperty(PropertyName = Constants.Properties.Path)]
public string Path { get; set; }

/// <summary>
/// Gets or sets a string containing the language of the full text path.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a override for the container language?

/// </summary>
[JsonProperty(PropertyName = "language")]
public string Language { get; set; }

/// <summary>
/// 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.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

/// <summary>
/// Ensures that the paths specified in the full text policy are valid.
/// </summary>
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);
}
}

/// <inheritdoc/>
public bool Equals(FullTextPath that)
{
return this.Path.Equals(that.Path) && this.Language.Equals(that.Language);
}
}
}
70 changes: 70 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/FullTextPolicy.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Represents the full text policy configuration for specifying the full text paths on documents in the collection in the Azure Cosmos DB service.
/// </summary>
/// <seealso cref="ContainerProperties"/>
#if PREVIEW
public
#else
internal
#endif
sealed class FullTextPolicy
{
/// <summary>
/// Initializes a new instance of the <see cref="FullTextPolicy"/> class.
/// </summary>
/// <param name="defaultLanguage">String of the default language of the container.</param>
/// <param name="fullTextPaths">List of full text paths to include in the policy definition.</param>
public FullTextPolicy(string defaultLanguage, Collection<FullTextPath> fullTextPaths)
{
if (fullTextPaths != null)
{
FullTextPolicy.ValidateFullTextPaths(fullTextPaths);
}

this.DefaultLanguage = defaultLanguage;
this.FullTextPaths = fullTextPaths;
}

/// <summary>
/// Gets or sets a string containing the default language of the container.
/// </summary>
[JsonProperty(PropertyName = "defaultLanguage", NullValueHandling=NullValueHandling.Ignore)]
public string DefaultLanguage { get; set; }

/// <summary>
/// Gets a collection of <see cref="FullTextPath"/> that contains the full text paths of documents in collection in the Azure Cosmos DB service.
/// </summary>
[JsonProperty(PropertyName = "fullTextPaths", NullValueHandling=NullValueHandling.Ignore)]
public readonly Collection<FullTextPath> FullTextPaths;

/// <summary>
/// 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.
/// </summary>
[JsonExtensionData]
internal IDictionary<string, JToken> AdditionalProperties { get; private set; }

/// <summary>
/// Ensures that the specified full text paths in the policy are valid.
/// </summary>
private static void ValidateFullTextPaths(
IEnumerable<FullTextPath> fullTextPaths)
{
foreach (FullTextPath item in fullTextPaths)
{
item.ValidateFullTextPath();
}
}
}
}
27 changes: 27 additions & 0 deletions Microsoft.Azure.Cosmos/src/Resource/Settings/IndexingPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,33 @@ public IndexingPolicy()
#endif
Collection<VectorIndexPath> VectorIndexes { get; set; } = new Collection<VectorIndexPath>();

/// <summary>
/// Gets the full text indexes
/// </summary>
/// <example>
/// <![CDATA[
/// "fullTextIndexes": [
/// {
/// "path": "/v1",
/// },
/// {
/// "path": "/v2",
/// },
/// {
/// "path": "/v3",
/// }
/// ]
/// ]]>
/// </example>
[JsonProperty(PropertyName = "fullTextIndexes", NullValueHandling = NullValueHandling.Ignore)]
#if PREVIEW

public
#else
internal
#endif
Collection<FullTextIndexPath> FullTextIndexes { get; set; } = new Collection<FullTextIndexPath>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests?


/// <summary>
/// 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.
Expand Down
Loading