-
Notifications
You must be signed in to change notification settings - Fork 4.4k
.Net: feat: Modernize GoogleTextSearch connector with ITextSearch<TRecord> interface (microsoft#10456) #13190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
westey-m
merged 9 commits into
microsoft:feature-text-search-linq
from
alzarei:feature-text-search-linq-pr4
Nov 3, 2025
Merged
.Net: feat: Modernize GoogleTextSearch connector with ITextSearch<TRecord> interface (microsoft#10456) #13190
westey-m
merged 9 commits into
microsoft:feature-text-search-linq
from
alzarei:feature-text-search-linq-pr4
Nov 3, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87cc4ba to
7576d94
Compare
westey-m
reviewed
Oct 10, 2025
dotnet/src/Plugins/Plugins.UnitTests/Web/Google/GoogleTextSearchTests.cs
Show resolved
Hide resolved
westey-m
reviewed
Oct 10, 2025
westey-m
reviewed
Oct 10, 2025
westey-m
reviewed
Oct 10, 2025
westey-m
reviewed
Oct 10, 2025
westey-m
reviewed
Oct 10, 2025
westey-m
approved these changes
Oct 21, 2025
9466ecb to
96a241b
Compare
Author
|
Rebased on top of feature branch to resolve conflicts. Ready for review. |
…rchResults<TRecord> - Change interface return type from KernelSearchResults<object> to KernelSearchResults<TRecord> - Update VectorStoreTextSearch implementation with new GetResultsAsTRecordAsync helper - Keep GetResultsAsRecordAsync for legacy ITextSearch interface backward compatibility - Update 3 unit tests to use strongly-typed DataModel instead of object Benefits: - Improved type safety - no more casting required - Better IntelliSense and developer experience - Zero breaking changes to legacy ITextSearch interface - All 19 unit tests pass This is Part 2.1 of the Issue microsoft#10456 multi-PR chain, refining the API .
…c interface tests - Fix CS0121 compilation errors by explicitly specifying TextSearchOptions instead of new() - Add 3 comprehensive tests for ITextSearch<GoogleWebPage> generic interface: * GenericSearchAsyncReturnsSuccessfullyAsync * GenericGetTextSearchResultsReturnsSuccessfullyAsync * GenericGetSearchResultsReturnsSuccessfullyAsync - All 22 Google tests now pass (19 legacy + 3 generic) - Validates both backward compatibility and new type-safe functionality
- Add Contains() operation support for string properties (Title, Snippet, Link) - Implement intelligent mapping: Contains() -> orTerms for flexible matching - Add 2 new test methods to validate LINQ filtering with Contains and equality - Fix method ambiguity (CS0121) in GoogleTextSearchTests by using explicit TextSearchOptions types - Fix method ambiguity in Google_TextSearch.cs sample by specifying explicit option types - Enhance error messages with clear guidance on supported LINQ patterns and properties This enhancement extends the basic LINQ filtering (equality only) to include string Contains operations, providing more natural and flexible filtering patterns while staying within Google Custom Search API capabilities. All tests passing: 25/25 Google tests (22 existing + 3 new)
- Add ITextSearch<GoogleWebPage> interface implementation - Support equality, contains, NOT operations, and compound AND expressions - Map LINQ expressions to Google Custom Search API parameters - Add GoogleWebPage strongly-typed model for search results - Support FileFormat filtering via Google's fileType parameter - Add comprehensive test coverage (29 tests) for all filtering patterns - Include practical examples demonstrating enhanced filtering capabilities - Maintain backward compatibility with existing ITextSearch interface Resolves enhanced LINQ filtering requirements for Google Text Search plugin.
- Add UsingGoogleTextSearchWithEnhancedLinqFilteringAsync method to Google_TextSearch.cs * Demonstrates 6 practical LINQ filtering patterns * Includes equality, contains, NOT operations, FileFormat, compound AND examples * Shows real-world usage of ITextSearch<GoogleWebPage> interface - Fix method ambiguity in Step1_Web_Search.cs * Explicitly specify TextSearchOptions type instead of target-typed new() * Resolves CS0121 compilation error when both legacy and generic interfaces implemented * Maintains tutorial clarity for getting started guide These enhancements complete the sample code demonstrating the new LINQ filtering capabilities while ensuring all existing tutorials continue to compile correctly.
1. Added LINQ Filter Verification Tests - Added 7 test methods verifying LINQ expressions produce correct Google API URLs - Tests cover equality, contains, inequality, compound filters with URL validation - Expanded test suite from 29 to 36 tests (all passing) - Addresses reviewer comment: 'Some tests to verify the filter url that is created from the different linq expressions would be good' 2. Fixed Documentation Standards - Updated all property summaries in GoogleWebPage.cs to use 'Gets or sets the' convention - Applied to all 11 properties following .NET documentation standards - Addresses reviewer comment: 'These property summaries should start with Gets or sets the to conform to the documentation standard' 3. Performance Optimization - Added static readonly s_supportedPatterns array to avoid allocations in error paths - Moved error messages from inline array allocation to static field - Addresses reviewer comment: 'Consider making this a static field on the class. No need to allocate a new array of strings for each failed invocation' 4. Code Consolidation - Extracted shared LINQ processing logic into helper methods - Eliminated duplication between ConvertLinqExpressionToGoogleFilter and CollectAndCombineFilters - Applied DRY principles throughout LINQ expression processing - Addresses reviewer comment: 'This code seems very similar to that in CollectAndCombineFilters. Can this be consolidated?' Validation: - Build: Release configuration successful - Tests: 36/36 passing - Format: dotnet format compliance verified - Regression: All existing functionality preserved Note: API design question about return type consistency deferred for architectural discussion
…ions Enhance GoogleTextSearch LINQ filter processing to explicitly detect and reject collection Contains operations (e.g., array.Contains(page.Property)) with a clear, actionable error message. Changes: - Added IsMemoryExtensionsContains helper method to detect C# 14+ span-based Contains resolution - Enhanced TryProcessSingleExpression to distinguish between: * String.Contains (supported for substring search) * Enumerable.Contains / MemoryExtensions.Contains (not supported - now explicitly rejected) - Throws NotSupportedException with guidance on alternatives when collection Contains is detected - Handles both C# 13- (Enumerable.Contains) and C# 14+ (MemoryExtensions.Contains) resolution paths Test Coverage: - Added CollectionContainsFilterThrowsNotSupportedExceptionAsync test - Verifies exception is thrown for collection Contains operations - Validates error message contains actionable guidance about OR logic limitations - Ensures consistent behavior across C# language versions (13 vs 14 Contains resolution) Rationale: Google Custom Search API does not support OR logic across multiple values. Collection Contains filters would require OR semantics that cannot be expressed via Google's query parameters. This change provides clear, early feedback to developers attempting to use unsupported filter patterns. Related to reviewer feedback on LINQ expression filter validation and C# 14 compatibility. Fixes microsoft#10456
…Async 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 microsoft#13318 interface fix that changed ITextSearch<TRecord>.GetSearchResultsAsync to return KernelSearchResults<TRecord>.
96a241b to
d8c45b5
Compare
westey-m
approved these changes
Nov 3, 2025
7 tasks
This was referenced Nov 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kernel.core
kernel
Issues or pull requests impacting the core kernel
.NET
Issue or Pull requests regarding .NET code
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modernize GoogleTextSearch connector with ITextSearch interface
Problem Statement
The GoogleTextSearch connector currently only implements the legacy ITextSearch interface, forcing users to use clause-based TextSearchFilter instead of modern type-safe LINQ expressions. This creates runtime errors from property name typos and lacks compile-time validation for Google search operations.
Technical Approach
This PR modernizes the GoogleTextSearch connector to implement the generic ITextSearch interface alongside the existing legacy interface. The implementation provides LINQ-to-Google-API conversion with support for equality, contains, NOT operations, FileFormat filtering, and compound AND expressions.
Implementation Details
Core Changes
Property Mapping Strategy
The Google Custom Search API supports substantial filtering through predefined parameters:
Code Examples
Before (Legacy Interface)
After (Generic Interface)
Implementation Benefits
Type Safety & Developer Experience
Enhanced Filtering Capabilities
Validation Results
Build Verification
dotnet build --configuration Release --interactiveTest Results
Full Test Suite:
Core Unit Tests:
Test Failure Analysis
The 2,421 test failures are infrastructure/configuration issues, not code defects:
These failures are expected in development environments without external API configurations.
Method Ambiguity Resolution
Fixed compilation issues when both legacy and generic interfaces are implemented:
Files Modified
Breaking Changes
None. All existing GoogleTextSearch functionality preserved. Method ambiguity issues resolved through explicit typing.
Multi-PR Context
This is PR 4 of 6 in the structured implementation approach for Issue #10456. This PR extends LINQ filtering support to the GoogleTextSearch connector, following the established pattern from BingTextSearch modernization.