Tìm kiếm 3 loại khác nhau: user (LIKE), post (Pinecone AI hoặc MySQL FULLTEXT), hashtag (Topic table). Response thống nhất format.
| # | Task | Chi tiết | Status |
|---|---|---|---|
| 01 | GET /search?q=&type=user Tìm user theo tên | MySQL LIKE trên username và name. Return: avatar, name, username, followersCount. Pagination limit 20. | stub |
| 02 | GET /search?q=&type=post Tìm bài theo nội dung | Phase 1: content LIKE '%q%'. Phase 2: MySQL FULLTEXT MATCH...AGAINST. Phase 3: Pinecone semantic search. | stub |
| 03 | GET /search?q=&type=hashtag Tìm hashtag | Query bảng Topic: name ILIKE '%q%', count bài liên quan qua TopicsPost. Sort theo postCount. | stub |
| 04 | Pinecone query integration | Dự án đã có addToPineconeQueue để index bài. Cần thêm query endpoint: embed query → search Pinecone → fetch posts by IDs. | todo |
| 05 | Autocomplete / suggest | Khi user gõ → gợi ý nhanh. Dùng Redis sorted set cache top queries + MySQL LIKE 'q%' (prefix match). Debounce 300ms phía FE. | todo |
| 06 | Search history | Lưu lịch sử tìm kiếm per user (max 20 gần nhất). API: GET + DELETE search history. | todo |
| 07 | FULLTEXT index | MySQL FULLTEXT index trên content cho full-text search nhanh. Migration thêm ALTER TABLE Post ADD FULLTEXT(content). | todo |
LIKE '%keyword%' không dùng index, full table scan. OK cho <50K rows. Cần FULLTEXT index hoặc ngram parser cho scale.ngram parser cho CJK/Vietnamese. Cấu hình ngram_token_size=2 trong my.cnf. Pinecone xử lý tốt hơn nhờ multilingual embedding model.q cần sanitize: trim, remove SQL special chars, escape %_ cho LIKE. Zod validate min 1 char, max 100 char.