"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.searchService = exports.SearchService = void 0;
const models_1 = require("../../models");
/**
 * 搜索服务
 * 提供全局搜索功能（搜索书籍）
 */
class SearchService {
    /**
     * 搜索书籍
     * @param query 搜索关键词
     * @param limit 返回结果数量限制
     */
    async searchAudio(query, limit = 20) {
        if (!query || query.trim() === '') {
            return [];
        }
        const searchQuery = query.trim();
        // 搜索书籍
        const results = await models_1.prisma.book.findMany({
            where: {
                OR: [
                    { title: { contains: searchQuery } },
                    { description: { contains: searchQuery } },
                ],
            },
            orderBy: {
                createdAt: 'desc',
            },
            take: limit,
        });
        return results;
    }
}
exports.SearchService = SearchService;
// 导出单例
exports.searchService = new SearchService();
