diff --git a/src/MongoDB.Driver/Search/SearchHighlight.cs b/src/MongoDB.Driver/Search/SearchHighlight.cs index d4790e3699e..204584359a0 100644 --- a/src/MongoDB.Driver/Search/SearchHighlight.cs +++ b/src/MongoDB.Driver/Search/SearchHighlight.cs @@ -24,23 +24,37 @@ namespace MongoDB.Driver.Search public sealed class SearchHighlight { /// - /// Gets or sets the document field which returned a match. + /// Initializes a new instance of the class. /// - [BsonElement("path")] - public string Path { get; private set; } + /// document field which returned a match. + /// Score assigned to this result. + /// Objects containing the matching text and the surrounding text. + public SearchHighlight(string path, double score, SearchHighlightText[] texts) + { + Path = path; + Score = score; + Texts = texts; + } /// - /// Gets or sets one or more objects containing the matching text and the surrounding text - /// (if any). + /// Gets the document field which returned a match. /// - [BsonElement("texts")] - public SearchHighlightText[] Texts { get; private set; } + [BsonElement("path")] + public string Path { get; } /// - /// Gets or sets the score assigned to this result. + /// Gets the score assigned to this result. /// [BsonElement("score")] - public double Score { get; private set; } + public double Score { get; } + + /// + /// Gets one or more objects containing the matching text and the surrounding text + /// (if any). + /// + [BsonDefaultValue(null)] + [BsonElement("texts")] + public SearchHighlightText[] Texts { get; } } /// @@ -49,17 +63,28 @@ public sealed class SearchHighlight public sealed class SearchHighlightText { /// - /// Gets or sets the text from the field which returned a match. + /// Initializes a new instance of the class. /// - [BsonElement("value")] - public string Value { get; private set; } + /// Type of search highlight. + /// Text from the field which returned a match. + public SearchHighlightText(HighlightTextType type, string value) + { + Type = type; + Value = value; + } /// /// Gets or sets the type of text, matching or surrounding. /// [BsonElement("type")] [BsonRepresentation(BsonType.String)] - public HighlightTextType Type { get; private set; } + public HighlightTextType Type { get; } + + /// + /// Gets the text from the field which returned a match. + /// + [BsonElement("value")] + public string Value { get; } } /// diff --git a/src/MongoDB.Driver/Search/SearchMetaResult.cs b/src/MongoDB.Driver/Search/SearchMetaResult.cs index 3c150654aec..7f57dc35123 100644 --- a/src/MongoDB.Driver/Search/SearchMetaResult.cs +++ b/src/MongoDB.Driver/Search/SearchMetaResult.cs @@ -25,16 +25,29 @@ namespace MongoDB.Driver.Search public sealed class SearchMetaCountResult { /// - /// Gets or sets the lower bound for this result set. + /// Initializes a new instance of the class. /// + /// Lower bound for this result set. + /// Total for this result set. + public SearchMetaCountResult(long? lowerBound, long? total) + { + LowerBound = lowerBound; + Total = total; + } + + /// + /// Gets the lower bound for this result set. + /// + [BsonDefaultValue(null)] [BsonElement("lowerBound")] - public long? LowerBound { get; private set; } + public long? LowerBound { get; } /// - /// Gets or sets the total for this result set. + /// Gets the total for this result set. /// + [BsonDefaultValue(null)] [BsonElement("total")] - public long? Total { get; private set; } + public long? Total { get; } } /// @@ -43,16 +56,27 @@ public sealed class SearchMetaCountResult public sealed class SearchMetaFacetBucketResult { /// - /// Gets or sets the count of documents in this facet bucket. + /// Initializes a new instance of the class. + /// + /// count of documents in this facet bucket. + /// Unique identifier that identifies this facet bucket. + public SearchMetaFacetBucketResult(long count, BsonValue id) + { + Count = count; + Id = id; + } + + /// + /// Gets the count of documents in this facet bucket. /// [BsonElement("count")] - public long Count { get; private set; } + public long Count { get; } /// - /// Gets or sets the unique identifier that identifies this facet bucket. + /// Gets the unique identifier that identifies this facet bucket. /// [BsonId] - public BsonValue Id { get; private set; } + public BsonValue Id { get; } } /// @@ -61,10 +85,19 @@ public sealed class SearchMetaFacetBucketResult public sealed class SearchMetaFacetResult { /// - /// Gets or sets a list of bucket result sets. + /// Initializes a new instance of the class. + /// + /// An array of bucket result sets. + public SearchMetaFacetResult(SearchMetaFacetBucketResult[] buckets) + { + Buckets = buckets; + } + + /// + /// Gets an array of bucket result sets. /// [BsonElement("buckets")] - public List Buckets { get; private set; } + public SearchMetaFacetBucketResult[] Buckets { get; } } /// @@ -73,15 +106,28 @@ public sealed class SearchMetaFacetResult public sealed class SearchMetaResult { /// - /// Gets or sets the count result set. + /// Initializes a new instance of the class. + /// + /// Count result set. + /// Facet result sets. + public SearchMetaResult(SearchMetaCountResult count, IReadOnlyDictionary facet) + { + Count = count; + Facet = facet; + } + + /// + /// Gets the count result set. /// + [BsonDefaultValue(null)] [BsonElement("count")] - public SearchMetaCountResult Count { get; private set; } + public SearchMetaCountResult Count { get; } /// - /// Gets or sets the facet result sets. + /// Gets the facet result sets. /// + [BsonDefaultValue(null)] [BsonElement("facet")] - public Dictionary Facet { get; private set; } + public IReadOnlyDictionary Facet { get; } } } diff --git a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs index 7b284ae8bbc..dbfb795ef7f 100644 --- a/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs +++ b/tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs @@ -370,7 +370,6 @@ public void SearchMeta_facet() .Single(); result.Should().NotBeNull(); - result.Facet.Should().NotBeNull().And.ContainKeys("date", "number", "string"); var bucket = result.Facet["string"].Buckets.Should().NotBeNull().And.ContainSingle().Subject; bucket.Id.Should().Be((BsonString)"machine");