package com.ruoyi.novel.service.impl;

import com.ruoyi.novel.domain.Novel;
import com.ruoyi.novel.service.NovelSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// NovelSearchService.java
@Service
public class NovelSearchServiceImpl implements NovelSearchService {

    @Autowired
    private ElasticsearchRestTemplate elasticTemplate;

    public List<Novel> searchNovels(String keyword) {
        NativeSearchQuery query = new NativeSearchQueryBuilder()
                .withQuery(QueryBuilders.multiMatchQuery(keyword, "title", "author", "description"))
                .build();
        return elasticTemplate.search(query, Novel.class).getContent();
    }
}
