Files
lcbp3/frontend/lib/services/search.service.ts
T
admin 11984bfa29
CI Pipeline / build (push) Failing after 12m41s
Build and Deploy / deploy (push) Failing after 2m44s
260322:1648 Correct Coresspondence / Doing RFA / Correct CI
2026-03-22 16:48:12 +07:00

39 lines
1.2 KiB
TypeScript

// File: lib/services/search.service.ts
import apiClient from '@/lib/api/client';
import { SearchQueryDto } from '@/types/dto/search/search-query.dto';
export const searchService = {
/**
* ค้นหาเอกสารทั้งระบบ (Full-text Search)
* ใช้ Elasticsearch ผ่าน Backend
*/
search: async (query: SearchQueryDto) => {
// ส่ง params แบบ flat ตาม DTO
// GET /search?q=...&type=...&projectId=...
const response = await apiClient.get('/search', {
params: query,
});
return response.data;
},
/**
* Suggestion (Autocomplete)
* ใช้ search endpoint แต่จำกัดจำนวน
*/
suggest: async (query: string) => {
const response = await apiClient.get('/search', {
params: { q: query, limit: 5 },
});
// Assuming backend returns { items: [], ... } or just []
return response.data.items || response.data;
},
/**
* (Optional) Re-index ข้อมูลใหม่ กรณีข้อมูลไม่ตรง (Admin Only)
*/
reindex: async (type?: string) => {
const response = await apiClient.post('/search/reindex', { type });
return response.data;
},
};