package cn.reghao.tnb.search.esapp.hibernate;

import cn.reghao.tnb.search.esapp.blog.model.po.Article;
import cn.reghao.tnb.search.esapp.model.po.WenshuDoc;
import org.hibernate.search.mapper.orm.Search;
import org.hibernate.search.mapper.orm.session.SearchSession;
import org.springframework.stereotype.Service;

import jakarta.persistence.EntityManagerFactory;
import java.util.List;

/**
 * @author reghao
 * @date 2025-04-02 09:49:21
 */
@Service
public class HibernateLucene {
    private final SearchSession searchSession;

    public HibernateLucene(EntityManagerFactory entityManagerFactory) {
        this.searchSession = Search.session(entityManagerFactory.createEntityManager());
    }

    public void createIndex() {
        List<Class<?>> classList = List.of(WenshuDoc.class, Article.class);
        searchSession.massIndexer(classList).start();
    }

    public void resetIndex() {
        createIndex();
    }
}
