Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions Microsoft.Azure.Cosmos/src/Fluent/Settings/ContainerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ContainerBuilder : ContainerDefinition<ContainerBuilder>
private ChangeFeedPolicy changeFeedPolicy;
private ClientEncryptionPolicy clientEncryptionPolicy;
private VectorEmbeddingPolicy vectorEmbeddingPolicy;
private FullTextPolicy fullTextPolicy;

/// <summary>
/// Creates an instance for unit-testing
Expand Down Expand Up @@ -136,6 +137,28 @@ VectorEmbeddingPolicyDefinition WithVectorEmbeddingPolicy(
(embeddingPolicy) => this.AddVectorEmbeddingPolicy(embeddingPolicy));
}

/// <summary>
/// Defined the vector embedding policy for this Azure Cosmos container
/// </summary>
/// <param name="defaultLanguage">blablan.</param>
/// <param name="fullTextPaths">List of vector embeddings to include in the policy definition.</param>
/// <returns>An instance of <see cref="VectorEmbeddingPolicyDefinition"/>.</returns>
#if PREVIEW
public
#else
internal
#endif
FullTextPolicyDefinition WithFullTextPolicy(
string defaultLanguage,
Collection<FullTextPath> fullTextPaths)
{
return new FullTextPolicyDefinition(
this,
defaultLanguage,
fullTextPaths,
(fullTextPolicy) => this.AddFullTextSearchPolicy(fullTextPolicy));
}

/// <summary>
/// Creates a container with the current fluent definition.
/// </summary>
Expand Down Expand Up @@ -286,5 +309,10 @@ private void AddVectorEmbeddingPolicy(VectorEmbeddingPolicy embeddingPolicy)
{
this.vectorEmbeddingPolicy = embeddingPolicy;
}

private void AddFullTextSearchPolicy(FullTextPolicy fullTextPolicy)
{
this.fullTextPolicy = fullTextPolicy;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Fluent
{
using System;

/// <summary>
/// Full Text index fluent definition.
/// </summary>
/// <seealso cref="FullTextIndexPath"/>
#if PREVIEW
public
#else
internal
#endif
class FullTextIndexDefinition<T>
{
private readonly FullTextIndexPath fullTextIndexPath = new ();
private readonly T parent;
private readonly Action<FullTextIndexPath> attachCallback;

/// <summary>
/// Initializes a new instance of the <see cref="FullTextIndexDefinition{T}"/> class.
/// </summary>
/// <param name="parent">The original instance of <see cref="ContainerBuilder"/>.</param>
/// <param name="attachCallback">A callback delegate to be used at a later point of time.</param>
public FullTextIndexDefinition(
T parent,
Action<FullTextIndexPath> attachCallback)
{
this.parent = parent;
this.attachCallback = attachCallback;
}

/// <summary>
/// Add a path to the current <see cref="FullTextIndexPath"/> definition.
/// </summary>
/// <param name="path">Property path for the current definition. Example: /property</param>
/// <returns>An instance of the current <see cref="FullTextIndexDefinition{T}"/>.</returns>
public FullTextIndexDefinition<T> Path(
string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(nameof(path));
}

this.fullTextIndexPath.Path = path;

return this;
}

/// <summary>
/// Applies the current definition to the parent.
/// </summary>
/// <returns>An instance of the parent.</returns>
public T Attach()
{
this.attachCallback(this.fullTextIndexPath);
return this.parent;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------

namespace Microsoft.Azure.Cosmos.Fluent
{
using System;
using System.Collections.ObjectModel;

/// <summary>
/// <see cref="FullTextPolicyDefinition"/> fluent definition.
/// </summary>
#if PREVIEW
public
#else
internal
#endif
class FullTextPolicyDefinition
{
private readonly ContainerBuilder parent;
private readonly Action<FullTextPolicy> attachCallback;
private readonly string defaultLanguage;
private readonly Collection<FullTextPath> fullTextPaths;

/// <summary>
/// Initializes a new instance of the <see cref="FullTextPolicyDefinition"/> class.
/// </summary>
/// <param name="parent">The original instance of <see cref="ContainerBuilder"/>.</param>
/// <param name="defaultLanguage">blabla</param>
/// <param name="fullTextPaths">List of fullTextPaths to include in the policy definition.</param>
/// <param name="attachCallback">A callback delegate to be used at a later point of time.</param>
public FullTextPolicyDefinition(
ContainerBuilder parent,
string defaultLanguage,
Collection<FullTextPath> fullTextPaths,
Action<FullTextPolicy> attachCallback)
{
this.parent = parent ?? throw new ArgumentNullException(nameof(parent));
this.attachCallback = attachCallback ?? throw new ArgumentNullException(nameof(attachCallback));
this.fullTextPaths = fullTextPaths;
this.defaultLanguage = defaultLanguage;
}

/// <summary>
/// Applies the current definition to the parent.
/// </summary>
/// <returns>An instance of the parent.</returns>
public ContainerBuilder Attach()
{
FullTextPolicy fullTextPolicy = new (
this.defaultLanguage,
this.fullTextPaths);

this.attachCallback(fullTextPolicy);
return this.parent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ VectorIndexDefinition<IndexingPolicyDefinition<T>> WithVectorIndex()
(vectorIndex) => this.AddVectorIndexPath(vectorIndex));
}

/// <summary>
/// Defines a <see cref="VectorIndexPath"/> in the current <see cref="Container"/>'s definition.
/// </summary>
/// <returns>An instance of <see cref="VectorIndexDefinition{T}"/>.</returns>
#if PREVIEW
public
#else
internal
#endif
FullTextIndexDefinition<IndexingPolicyDefinition<T>> WithFullTextIndex()
{
return new FullTextIndexDefinition<IndexingPolicyDefinition<T>>(
this,
(fullTextIndex) => this.AddFullTextndexPath(fullTextIndex));
}

/// <summary>
/// Applies the current definition to the parent.
/// </summary>
Expand All @@ -154,6 +170,11 @@ private void AddVectorIndexPath(VectorIndexPath vectorIndexPath)
this.indexingPolicy.VectorIndexes.Add(vectorIndexPath);
}

private void AddFullTextndexPath(FullTextIndexPath fullTextIndexPath)
{
this.indexingPolicy.FullTextIndexes.Add(fullTextIndexPath);
}

private void AddIncludedPaths(IEnumerable<string> paths)
{
foreach (string path in paths)
Expand Down
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.Linq;

/// <summary>
/// DOM for a full text index path. A full text index path is used in a full text index.
/// </summary>
/// <example>
/// <![CDATA[
/// "indexingPolicy": {
/// "includedPaths": [
/// {
/// "path": "/*"
/// }
/// ],
/// "excludedPaths": [
/// {
/// "path": "/embeddings/vector/*"
/// }
/// ],
/// "fullTextIndexes": [
/// {
/// "path": "/v1/path1",
/// },
/// {
/// "path": "/v2/path2/text2",
/// },
/// {
/// "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; }
}
}
Loading