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>
1.8 KiB
1.8 KiB
Issue #65: [KNOW-013] Full-Text Search Setup
Objective
Set up PostgreSQL full-text search for entries in the knowledge module with weighted fields and proper indexing.
Approach
- Examine current Prisma schema for knowledge entries
- Write tests for full-text search functionality (TDD)
- Add tsvector column to knowledge entries table
- Create GIN index for performance
- Implement trigger to maintain tsvector on insert/update
- Weight fields: title (A), summary (B), content (C)
- Verify with sample queries
Progress
- Create scratchpad
- Read Prisma schema
- Examine existing search service
- Write failing tests for tsvector column (RED)
- Create migration with tsvector column, GIN index, and triggers
- Update Prisma schema to include tsvector
- Update search service to use precomputed tsvector (GREEN)
- Run tests and verify coverage (8/8 integration tests pass, 205/225 knowledge module tests pass)
- Run quality checks (typecheck and lint pass)
- Commit changes (commit
24d59e7)
Current State
The search service already implements full-text search using to_tsvector and ts_rank
in raw SQL queries, but it calculates tsvector on-the-fly. This is inefficient for large
datasets. The migration will:
- Add a
search_vectortsvector column to knowledge_entries - Create a GIN index on search_vector for fast lookups
- Add a trigger to automatically update search_vector on insert/update
- Use weighted fields: title (A), summary (B), content (C)
Testing
- Unit tests for search query generation
- Integration tests with actual database queries
- Performance verification with sample data
Notes
- Using PostgreSQL's built-in full-text search capabilities
- GIN index for fast text search
- Automatic maintenance via triggers
- Field weights: A (title) > B (summary) > C (content)