Skip to content

Commit

Permalink
Search: Make SuggestResults.Results read only (#13003)
Browse files Browse the repository at this point in the history
* Search: Make SuggestResults.Results read only

Fixes #12936
  • Loading branch information
tg-msft authored and prmathur-microsoft committed Jul 8, 2020
1 parent 8d3f3c9 commit d527d8f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,7 @@ public static partial class SearchModelFactory
public static Azure.Search.Documents.Indexes.Models.SearchServiceLimits SearchServiceLimits(int? maxFieldsPerIndex, int? maxFieldNestingDepthPerIndex, int? maxComplexCollectionFieldsPerIndex, int? maxComplexObjectsInCollectionsPerDocument) { throw null; }
public static Azure.Search.Documents.Indexes.Models.SearchServiceStatistics SearchServiceStatistics(Azure.Search.Documents.Indexes.Models.SearchServiceCounters counters, Azure.Search.Documents.Indexes.Models.SearchServiceLimits limits) { throw null; }
public static Azure.Search.Documents.Models.SearchSuggestion<T> SearchSuggestion<T>(T document, string text) { throw null; }
public static Azure.Search.Documents.Models.SuggestResults<T> SuggestResults<T>(System.Collections.Generic.IList<Azure.Search.Documents.Models.SearchSuggestion<T>> results, double? coverage) { throw null; }
public static Azure.Search.Documents.Models.SuggestResults<T> SuggestResults<T>(System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Models.SearchSuggestion<T>> results, double? coverage) { throw null; }
}
public enum SearchQueryType
{
Expand Down Expand Up @@ -2049,7 +2049,7 @@ public partial class SuggestResults<T>
{
internal SuggestResults() { }
public double? Coverage { get { throw null; } }
public System.Collections.Generic.IList<Azure.Search.Documents.Models.SearchSuggestion<T>> Results { get { throw null; } }
public System.Collections.Generic.IReadOnlyList<Azure.Search.Documents.Models.SearchSuggestion<T>> Results { get { throw null; } }
}
public partial class ValueFacetResult<T>
{
Expand Down
24 changes: 16 additions & 8 deletions sdk/search/Azure.Search.Documents/src/Models/SuggestResults{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
Expand Down Expand Up @@ -37,8 +39,7 @@ public partial class SuggestResults<T>
/// <summary>
/// The sequence of suggestions returned by the query.
/// </summary>
public IList<SearchSuggestion<T>> Results { get; internal set; } =
new List<SearchSuggestion<T>>();
public IReadOnlyList<SearchSuggestion<T>> Results { get; internal set; }

/// <summary>
/// Initializes a new instance of the SuggestResults class.
Expand Down Expand Up @@ -86,6 +87,7 @@ await JsonDocument.ParseAsync(json, cancellationToken: cancellationToken).Config
}
else if (prop.NameEquals(Constants.ValueKeyJson.EncodedUtf8Bytes))
{
List<SearchSuggestion<T>> results = new List<SearchSuggestion<T>>();
foreach (JsonElement element in prop.Value.EnumerateArray())
{
SearchSuggestion<T> suggestion = await SearchSuggestion<T>.DeserializeAsync(
Expand All @@ -97,8 +99,9 @@ await JsonDocument.ParseAsync(json, cancellationToken: cancellationToken).Config
async,
cancellationToken)
.ConfigureAwait(false);
suggestions.Results.Add(suggestion);
results.Add(suggestion);
}
suggestions.Results = new ReadOnlyCollection<SearchSuggestion<T>>(results);
}
}
return suggestions;
Expand All @@ -109,14 +112,19 @@ public static partial class SearchModelFactory
{
/// <summary> Initializes a new instance of SearchResult. </summary>
/// <typeparam name="T">
/// The .NET type that maps to the index schema. Instances of this type can
/// be retrieved as documents from the index.
/// The .NET type that maps to the index schema. Instances of this type
/// can be retrieved as documents from the index.
/// </typeparam>
/// <param name="results"></param>
/// <param name="coverage"></param>
/// <param name="results">
/// The sequence of suggestions returned by the query.
/// </param>
/// <param name="coverage">
/// A value indicating the percentage of the index that was included in
/// the query, or null if minimumCoverage was not set in the request.
/// </param>
/// <returns>A new SuggestResults instance for mocking.</returns>
public static SuggestResults<T> SuggestResults<T>(
IList<SearchSuggestion<T>> results,
IReadOnlyList<SearchSuggestion<T>> results,
double? coverage) =>
new SuggestResults<T>() { Coverage = coverage, Results = results };
}
Expand Down

0 comments on commit d527d8f

Please sign in to comment.