26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
4.8 KiB
4.8 KiB
Implement Search Processing
Summary
Implement the search processing subsystem that executes user-defined filter queries against the SQL Server cache database. This phase replaces the legacy T4 text template (QueryTemplate.tt) with a SqlKata fluent query builder, providing type-safe query construction, parameterized SQL generation, and composable filter handling.
Scope
In Scope
ISearchQueryBuilderinterface andSqlKataSearchQueryBuilderimplementation- Filter handler pattern with individual handlers per filter type:
WorkOrderFilterHandlerItemNumberFilterHandlerProfitCenterFilterHandlerWorkCenterFilterHandlerOperatorFilterHandlerComponentLotFilterHandlerItemOperationMisFilterHandlerTimespanFilterHandler
ISearchProcessorinterface andSearchProcessorservice implementationIWorkOrderTraversalServiceinterface for downstream work order traversalSearchModelclass (reporting model with enriched filter entries)- Filter entry record types (immutable DTOs with output attributes)
- Result record types:
SearchResult,MisSearchResult,MisNonMatchSearchResult - Table-valued parameter creation helpers
- MIS data extraction query building
SearchProcessingOptionsconfiguration classAddSearchProcessingservice registration extension method- Unit tests with xUnit, Shouldly, and NSubstitute
Out of Scope
- Background job scheduling (handled by Phase 5 data-sync or separate worker phase)
- Excel export generation (Phase 7: excel-export)
- API endpoints for search submission (Phase 8: web-api-auth)
- SignalR real-time status updates (Phase 8: web-api-auth)
- Database schema changes (Phase 1: migrate-database-schema)
Motivation
The legacy T4 text template approach has significant limitations:
- SDK incompatibility: T4 templates are poorly supported in modern .NET SDK-style projects
- Untestable: Generated SQL cannot be unit tested without database execution
- Fragile: String concatenation prone to SQL injection and syntax errors
- Untyped: No compile-time validation of query structure
SqlKata provides:
- Fluent API: Readable, composable query building with IntelliSense support
- Parameterized by default: SQL injection protection built-in
- Testable: Unit test query building without database
- Type-safe: Compile-time checking of method calls
- SQL Server optimized: SqlServerCompiler generates optimized T-SQL
Acceptance Criteria
ISearchQueryBuilderinterface defined withBuildSearchQuery(SearchModel)methodSqlKataSearchQueryBuildergenerates equivalent SQL to legacyQueryTemplate.tt- All 8 filter handlers implemented with conditional join/where clause generation
SearchProcessororchestrates:- Filter entry enrichment via repository lookups
- Query building via SqlKata
- Query execution via Dapper
- Result aggregation into
SearchModel.Results - MIS data extraction when
ExtractMisData = true
- Downstream work order traversal calls stored procedure
dbo.TraverseWorkOrders - Table-valued parameters created correctly for all filter types
- All result types include
OutputColumnAttributeandOutputTableAttributefor Excel export - Unit tests verify:
- Query builder generates expected SQL structure
- Filter handlers apply correct joins and conditions
- Parameter binding works for all TVP types
AddSearchProcessingregisters all services with appropriate lifetimesopenspec validate implement-search-processing --strictpasses
Dependencies
- Phase 1: migrate-database-schema - Database tables, TVP types, stored procedures
- Phase 3: implement-domain-models - Core domain entities (Search, SearchCriteria, etc.)
- Phase 4: implement-data-access -
IDbConnectionFactory,ILotFinderRepositoryfor lookups - NuGet packages:
SqlKata,SqlKata.Execution,Dapper,Microsoft.Data.SqlClient
Risks
| Risk | Mitigation |
|---|---|
| Query logic drift from legacy | Codex MCP review comparing generated SQL against QueryTemplate.tt output |
| Complex filter combinations | Comprehensive unit test matrix covering all filter permutations |
| MIS extraction query complexity | Retain MIS extraction as separate stored procedure if needed |
| Performance regression | Benchmark query execution time against legacy implementation |
| Downstream traversal correctness | Stored procedure dbo.TraverseWorkOrders encapsulates iterative logic |
Related Specs
search-processing- Primary specification for query building and search executiondomain-models- Entity types used in search criteria and resultsdata-access- Repository interfaces for filter enrichment lookupsdatabase-schema- SQL Server tables and TVP types for search execution