package tech.easyflow.ai.service.impl;

import com.easyagents.search.engine.service.DocumentSearcher;
import org.springframework.beans.factory.annotation.Autowired;
import tech.easyflow.ai.config.SearcherFactory;
import tech.easyflow.ai.entity.DocumentChunk;
import tech.easyflow.ai.entity.DocumentCollection;
import tech.easyflow.ai.mapper.DocumentChunkMapper;
import tech.easyflow.ai.service.DocumentChunkService;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.math.BigInteger;

/**
 *  服务层实现。
 *
 * @author michael
 * @since 2024-08-23
 */
@Service
public class DocumentChunkServiceImpl extends ServiceImpl<DocumentChunkMapper, DocumentChunk> implements DocumentChunkService {

    @Autowired
    private SearcherFactory searcherFactory;

    @Override
    public boolean removeChunk(DocumentCollection knowledge, BigInteger chunkId) {
        DocumentSearcher searcher = searcherFactory.getSearcher();
        // 删除搜索引擎中的数据
        if (searcher == null){
            return true;
        }
        return  searcher.deleteDocument(chunkId);
    }
}
