Skip to content

Commit d8c45b5

Browse files
committed
Return TRecord instead of object in GoogleTextSearch.GetSearchResultsAsync
Changes: - Update GoogleTextSearch.GetSearchResultsAsync to return KernelSearchResults<GoogleWebPage> instead of KernelSearchResults<object> - Remove wasteful .Cast<object>() call - Update test to use strongly-typed GoogleWebPage instead of casting from object Benefits: - Eliminates runtime casting overhead - Provides compile-time type safety - Improves IntelliSense for consumers This change aligns with PR #13318 interface fix that changed ITextSearch<TRecord>.GetSearchResultsAsync to return KernelSearchResults<TRecord>.
1 parent cbd1265 commit d8c45b5

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

dotnet/src/Plugins/Plugins.UnitTests/Web/Google/GoogleTextSearchTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ public async Task GenericGetSearchResultsReturnsSuccessfullyAsync()
303303
searchEngineId: "SearchEngineId");
304304

305305
// Act - Use generic interface with GoogleWebPage
306-
KernelSearchResults<object> results = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new TextSearchOptions<GoogleWebPage> { Top = 10, Skip = 0 });
306+
KernelSearchResults<GoogleWebPage> results = await textSearch.GetSearchResultsAsync("What is the Semantic Kernel?", new TextSearchOptions<GoogleWebPage> { Top = 10, Skip = 0 });
307307

308308
// Assert
309309
Assert.NotNull(results);
310310
Assert.NotNull(results.Results);
311311
var resultList = await results.Results.ToListAsync();
312312
Assert.NotNull(resultList);
313313
Assert.Equal(4, resultList.Count);
314-
foreach (GoogleWebPage result in resultList.Cast<GoogleWebPage>())
314+
foreach (GoogleWebPage result in resultList)
315315
{
316316
Assert.NotNull(result.Title);
317317
Assert.NotNull(result.Snippet);

dotnet/src/Plugins/Plugins.Web/Google/GoogleTextSearch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public async Task<KernelSearchResults<string>> SearchAsync(string query, TextSea
9494
#region ITextSearch<GoogleWebPage> Implementation
9595

9696
/// <inheritdoc/>
97-
public async Task<KernelSearchResults<object>> GetSearchResultsAsync(string query, TextSearchOptions<GoogleWebPage>? searchOptions = null, CancellationToken cancellationToken = default)
97+
public async Task<KernelSearchResults<GoogleWebPage>> GetSearchResultsAsync(string query, TextSearchOptions<GoogleWebPage>? searchOptions = null, CancellationToken cancellationToken = default)
9898
{
9999
var legacyOptions = ConvertToLegacyOptions(searchOptions);
100100
var searchResponse = await this.ExecuteSearchAsync(query, legacyOptions, cancellationToken).ConfigureAwait(false);
101101

102102
long? totalCount = searchOptions?.IncludeTotalCount == true ? long.Parse(searchResponse.SearchInformation.TotalResults) : null;
103103

104-
return new KernelSearchResults<object>(this.GetResultsAsGoogleWebPageAsync(searchResponse, cancellationToken).Cast<object>(), totalCount, GetResultsMetadata(searchResponse));
104+
return new KernelSearchResults<GoogleWebPage>(this.GetResultsAsGoogleWebPageAsync(searchResponse, cancellationToken), totalCount, GetResultsMetadata(searchResponse));
105105
}
106106

107107
/// <inheritdoc/>

0 commit comments

Comments
 (0)