rev:lucene路径

This commit is contained in:
2024-01-10 12:31:57 +08:00
parent 2e22fbee6e
commit 80c0cf6d46

View File

@@ -12,6 +12,9 @@ import org.apache.lucene.search.*;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import org.nl.config.lucene.service.LuceneService;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
@@ -33,7 +36,13 @@ public class LuceneServiceImpl implements LuceneService {
public Map<String, Object> getAll(Map whereJson, Pageable page) {
//获取要查询的路径,也就是索引所在的位置
try {
FSDirectory directory = FSDirectory.open(Paths.get("C:\\acs\\lucene\\index"));
Resource resource = new ClassPathResource("config/application.yml");
YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean();
yamlPropertiesFactoryBean.setResources(resource);
Properties properties = yamlPropertiesFactoryBean.getObject();
// 获取配置值
String luceneDir = properties.getProperty("lucene.index.path");
FSDirectory directory = FSDirectory.open(Paths.get(luceneDir));
DirectoryReader open = DirectoryReader.open(directory);
IndexSearcher searcher = new IndexSearcher(open);
// 实际上Lucene本身不支持分页。因此我们需要自己进行逻辑分页。我们要准备分页参数