Skip to content

Commit

Permalink
- PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisDog committed Jan 18, 2023
1 parent 41e5770 commit fee61f3
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 28 deletions.
51 changes: 38 additions & 13 deletions src/MongoDB.Driver/Search/SearchHighlight.cs
Expand Up @@ -24,23 +24,37 @@ namespace MongoDB.Driver.Search
public sealed class SearchHighlight
{
/// <summary>
/// Gets or sets the document field which returned a match.
/// Initializes a new instance of the <see cref="SearchHighlight"/> class.
/// </summary>
[BsonElement("path")]
public string Path { get; private set; }
/// <param name="path">document field which returned a match.</param>
/// <param name="score">Score assigned to this result.</param>
/// <param name="texts">Objects containing the matching text and the surrounding text.</param>
public SearchHighlight(string path, double score, SearchHighlightText[] texts)
{
Path = path;
Score = score;
Texts = texts;
}

/// <summary>
/// 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.
/// </summary>
[BsonElement("texts")]
public SearchHighlightText[] Texts { get; private set; }
[BsonElement("path")]
public string Path { get; }

/// <summary>
/// Gets or sets the score assigned to this result.
/// Gets the score assigned to this result.
/// </summary>
[BsonElement("score")]
public double Score { get; private set; }
public double Score { get; }

/// <summary>
/// Gets one or more objects containing the matching text and the surrounding text
/// (if any).
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("texts")]
public SearchHighlightText[] Texts { get; }
}

/// <summary>
Expand All @@ -49,17 +63,28 @@ public sealed class SearchHighlight
public sealed class SearchHighlightText
{
/// <summary>
/// Gets or sets the text from the field which returned a match.
/// Initializes a new instance of the <see cref="SearchHighlightText"/> class.
/// </summary>
[BsonElement("value")]
public string Value { get; private set; }
/// <param name="type">Type of search highlight.</param>
/// <param name="value">Text from the field which returned a match.</param>
public SearchHighlightText(HighlightTextType type, string value)
{
Type = type;
Value = value;
}

/// <summary>
/// Gets or sets the type of text, matching or surrounding.
/// </summary>
[BsonElement("type")]
[BsonRepresentation(BsonType.String)]
public HighlightTextType Type { get; private set; }
public HighlightTextType Type { get; }

/// <summary>
/// Gets the text from the field which returned a match.
/// </summary>
[BsonElement("value")]
public string Value { get; }
}

/// <summary>
Expand Down
74 changes: 60 additions & 14 deletions src/MongoDB.Driver/Search/SearchMetaResult.cs
Expand Up @@ -25,16 +25,29 @@ namespace MongoDB.Driver.Search
public sealed class SearchMetaCountResult
{
/// <summary>
/// Gets or sets the lower bound for this result set.
/// Initializes a new instance of the <see cref="SearchMetaCountResult"/> class.
/// </summary>
/// <param name="lowerBound">Lower bound for this result set.</param>
/// <param name="total">Total for this result set.</param>
public SearchMetaCountResult(long? lowerBound, long? total)
{
LowerBound = lowerBound;
Total = total;
}

/// <summary>
/// Gets the lower bound for this result set.
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("lowerBound")]
public long? LowerBound { get; private set; }
public long? LowerBound { get; }

/// <summary>
/// Gets or sets the total for this result set.
/// Gets the total for this result set.
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("total")]
public long? Total { get; private set; }
public long? Total { get; }
}

/// <summary>
Expand All @@ -43,16 +56,27 @@ public sealed class SearchMetaCountResult
public sealed class SearchMetaFacetBucketResult
{
/// <summary>
/// Gets or sets the count of documents in this facet bucket.
/// Initializes a new instance of the <see cref="SearchMetaFacetBucketResult"/> class.
/// </summary>
/// <param name="count">count of documents in this facet bucket.</param>
/// <param name="id">Unique identifier that identifies this facet bucket.</param>
public SearchMetaFacetBucketResult(long count, BsonValue id)
{
Count = count;
Id = id;
}

/// <summary>
/// Gets the count of documents in this facet bucket.
/// </summary>
[BsonElement("count")]
public long Count { get; private set; }
public long Count { get; }

/// <summary>
/// Gets or sets the unique identifier that identifies this facet bucket.
/// Gets the unique identifier that identifies this facet bucket.
/// </summary>
[BsonId]
public BsonValue Id { get; private set; }
public BsonValue Id { get; }
}

/// <summary>
Expand All @@ -61,10 +85,19 @@ public sealed class SearchMetaFacetBucketResult
public sealed class SearchMetaFacetResult
{
/// <summary>
/// Gets or sets a list of bucket result sets.
/// Initializes a new instance of the <see cref="SearchMetaFacetResult"/> class.
/// </summary>
/// <param name="buckets">An array of bucket result sets.</param>
public SearchMetaFacetResult(SearchMetaFacetBucketResult[] buckets)
{
Buckets = buckets;
}

/// <summary>
/// Gets an array of bucket result sets.
/// </summary>
[BsonElement("buckets")]
public List<SearchMetaFacetBucketResult> Buckets { get; private set; }
public SearchMetaFacetBucketResult[] Buckets { get; }
}

/// <summary>
Expand All @@ -73,15 +106,28 @@ public sealed class SearchMetaFacetResult
public sealed class SearchMetaResult
{
/// <summary>
/// Gets or sets the count result set.
/// Initializes a new instance of the <see cref="SearchMetaResult"/> class.
/// </summary>
/// <param name="count">Count result set.</param>
/// <param name="facet">Facet result sets.</param>
public SearchMetaResult(SearchMetaCountResult count, IReadOnlyDictionary<string, SearchMetaFacetResult> facet)
{
Count = count;
Facet = facet;
}

/// <summary>
/// Gets the count result set.
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("count")]
public SearchMetaCountResult Count { get; private set; }
public SearchMetaCountResult Count { get; }

/// <summary>
/// Gets or sets the facet result sets.
/// Gets the facet result sets.
/// </summary>
[BsonDefaultValue(null)]
[BsonElement("facet")]
public Dictionary<string, SearchMetaFacetResult> Facet { get; private set; }
public IReadOnlyDictionary<string, SearchMetaFacetResult> Facet { get; }
}
}
1 change: 0 additions & 1 deletion tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs
Expand Up @@ -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");
Expand Down

0 comments on commit fee61f3

Please sign in to comment.