Add support for filtering search results by tags in the main search endpoint. Changes: - Add tags parameter to SearchQueryDto (comma-separated tag slugs) - Implement tag filtering in SearchService.search() method - Update SQL query to join with knowledge_entry_tags when tags provided - Entries must have ALL specified tags (AND logic) - Add tests for tag filtering (2 controller tests, 2 service tests) - Update endpoint documentation - Fix non-null assertion linting error The search endpoint now supports: - Full-text search with ranking (ts_rank) - Snippet generation with highlighting (ts_headline) - Status filtering - Tag filtering (new) - Pagination Example: GET /api/knowledge/search?q=api&tags=documentation,tutorial All tests pass (25 total), type checking passes, linting passes. Fixes #66 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2.3 KiB
2.3 KiB
Issue #66: [KNOW-014] Search API Endpoint
Objective
Implement a full-text search API endpoint for the knowledge module with ranking, highlighting, filtering, and pagination capabilities.
Acceptance Criteria
- ✅ Create GET /api/knowledge/search?q=... endpoint
- ✅ Return ranked results with snippets
- ✅ Highlight matching terms in results
- ✅ Add filter by tags and status
- ✅ Implement pagination
- ✅ Ensure response time < 200ms
Approach
- Review existing knowledge module structure (controller, service, entities)
- Review full-text search setup from issue #65
- Write tests first (TDD - RED phase)
- Implement minimal code to pass tests (GREEN phase)
- Refactor and optimize (REFACTOR phase)
- Performance testing
- Quality gates and code review
Current State Analysis
The search endpoint already exists with most features implemented:
- ✅ GET /api/knowledge/search endpoint exists
- ✅ Full-text search with ts_rank for ranking
- ✅ Snippet generation with ts_headline
- ✅ Term highlighting with tags
- ✅ Status filter implemented
- ✅ Pagination implemented
- ⚠️ Tag filtering NOT implemented in main search endpoint
- ❓ Performance not tested
Gap: The main search endpoint doesn't support filtering by tags. There's a separate endpoint /by-tags that only does tag filtering without text search.
Solution: Add tags parameter to SearchQueryDto and modify the search service to combine full-text search with tag filtering.
Progress
- Review existing code structure
- Write failing tests for tag filter in search endpoint (TDD - RED)
- Update SearchQueryDto to include tags parameter
- Implement tag filtering in search service (TDD - GREEN)
- Refactor and optimize (TDD - REFACTOR)
- Run all tests - 25 tests pass (16 service + 9 controller)
- TypeScript type checking passes
- Linting passes (fixed non-null assertion)
- Performance testing (< 200ms)
- Code review
- QA checks
- Commit changes
Testing
- Unit tests for service methods
- Integration tests for controller endpoint
- Performance tests for response time
- Target: 85%+ coverage
Notes
- Use PostgreSQL full-text search from issue #65
- Follow NestJS conventions
- Use existing DTOs and entities
- Ensure type safety (no explicit any)