package cn.reghao.tnb.search.app;

import cn.reghao.tnb.search.app.es.ElasticService;
import cn.reghao.tnb.search.app.es.QueryService;
import cn.reghao.tnb.search.app.model.po.Wenshu;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @author reghao
 * @date 2025-03-17 09:49:48
 */
@Service
public class EsSearch {
    private final QueryService<Wenshu> queryService;
    private String index = "wenshu";

    public EsSearch(ElasticService elasticService) {
        this.queryService = new QueryService<>(elasticService);
    }

    public Page<Wenshu> search(String keyword, Pageable pageable) {
        int pn = pageable.getPageNumber()+1;
        int ps = pageable.getPageSize();
        Page<Wenshu> page = queryService.queryWithHighlight(index, keyword, pn, ps, Wenshu.class);
        return page;
    }

    public Wenshu getById(String id) {
        Wenshu wenshu = queryService.queryById(Wenshu.class, index, id);
        return wenshu;
    }
}
