Skip to content

Commit 0ed29a8

Browse files
committed
Tweaks
1 parent 5e486cb commit 0ed29a8

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/MongoDB.Driver/CreateSearchIndexModel.cs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,44 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System;
1617
using MongoDB.Bson;
1718

1819
namespace MongoDB.Driver
1920
{
2021
/// <summary>
21-
/// Defines a vector search index model using a <see cref="BsonDocument"/> definition. Consider using
22-
/// <see cref="CreateVectorIndexModel{TDocument}"/> to build Atlas indexes without specifying the BSON directly.
22+
/// Defines a search index model using a <see cref="BsonDocument"/> definition. Consider using
23+
/// <see cref="CreateVectorIndexModel{TDocument}"/> to build vector indexes without specifying the BSON directly.
2324
/// </summary>
2425
public class CreateSearchIndexModel
2526
{
27+
private readonly BsonDocument _definition;
28+
private readonly SearchIndexType? _type;
29+
private readonly string _name;
30+
2631
/// <summary>Gets the index name.</summary>
2732
/// <value>The index name.</value>
28-
public string Name { get; }
33+
public string Name => _name;
2934

3035
/// <summary>Gets the index type.</summary>
3136
/// <value>The index type.</value>
32-
public SearchIndexType? Type { get; }
37+
public SearchIndexType? Type => _type;
3338

34-
/// <summary>Gets the index definition.</summary>
39+
/// <summary>
40+
/// Gets the index definition, if one was passed to a constructor of this class, otherwise throws.
41+
/// </summary>
3542
/// <value>The definition.</value>
36-
public virtual BsonDocument Definition { get; }
43+
public BsonDocument Definition
44+
=> _definition ?? throw new NotSupportedException(
45+
"This method should not be called on this subtype. Instead, call 'Render' to create a BSON document for the index model.");
3746

3847
/// <summary>
3948
/// Initializes a new instance of the <see cref="CreateSearchIndexModel"/> class, passing the index
4049
/// model as a <see cref="BsonDocument"/>.
4150
/// </summary>
4251
/// <remarks>
43-
/// Consider using <see cref="CreateVectorIndexModel{TDocument}"/> to build Atlas indexes without specifying the
44-
/// BSON directly.
52+
/// Consider using <see cref="CreateVectorIndexModel{TDocument}"/> to build vector indexes without specifying
53+
/// the BSON directly.
4554
/// </remarks>
4655
/// <param name="name">The index name.</param>
4756
/// <param name="definition">The index definition.</param>
@@ -55,18 +64,17 @@ public CreateSearchIndexModel(string name, BsonDocument definition)
5564
/// model as a <see cref="BsonDocument"/>.
5665
/// </summary>
5766
/// <remarks>
58-
/// Consider using <see cref="CreateVectorIndexModel{TDocument}"/> to build indexes without specifying the
59-
/// BSON directly.
67+
/// Consider using <see cref="CreateVectorIndexModel{TDocument}"/> to build vector indexes without specifying
68+
/// the BSON directly.
6069
/// </remarks>
6170
/// <param name="name">The index name.</param>
6271
/// <param name="type">The index type.</param>
6372
/// <param name="definition">The index definition.</param>
6473
public CreateSearchIndexModel(string name, SearchIndexType? type, BsonDocument definition)
6574
{
66-
Name = name;
67-
Type = type;
68-
Definition = definition;
69-
75+
_name = name;
76+
_type = type;
77+
_definition = definition;
7078
}
7179

7280
/// <summary>
@@ -76,8 +84,8 @@ public CreateSearchIndexModel(string name, SearchIndexType? type, BsonDocument d
7684
/// <param name="type">The index type.</param>
7785
protected CreateSearchIndexModel(string name, SearchIndexType? type)
7886
{
79-
Name = name;
80-
Type = type;
87+
_name = name;
88+
_type = type;
8189
}
8290
}
8391
}

src/MongoDB.Driver/CreateVectorIndexModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ public sealed class CreateVectorIndexModel<TDocument> : CreateSearchIndexModel
6161
/// </summary>
6262
public int? HnswNumEdgeCandidates { get; init; }
6363

64-
/// <summary>
65-
/// This method should not be called on this subtype. Instead, call <see cref="Render"/> to create a BSON
66-
/// document for the index model.
67-
/// </summary>
68-
public override BsonDocument Definition
69-
=> throw new NotSupportedException(
70-
"This method should not be called on this subtype. Instead, call 'Render' to create a BSON document for the index model.");
71-
7264
/// <summary>
7365
/// Initializes a new instance of the <see cref="CreateVectorIndexModel{TDocument}"/> class, passing the
7466
/// required options for <see cref="VectorSimilarity"/> and the number of vector dimensions to the constructor.

0 commit comments

Comments
 (0)