fix docker path bug

This commit is contained in:
luke 2025-05-25 15:33:25 +08:00
parent fe74eb879d
commit f423a9df10

View File

@ -13,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.*;
import java.util.HashMap;
import java.util.Map;
@ -38,7 +36,8 @@ public abstract class AbstractBaseFileImporter implements DocumentImporter {
@Override
public void importDocuments() throws IOException {
Path basePath = Paths.get(getDirectoryPath());
Path basePath = Paths.get(getDirectoryPath()).toAbsolutePath().normalize();
Path excludeBase = Paths.get(excludePrefix).toAbsolutePath().normalize();
Files.walk(basePath)
.filter(p -> p.toString().toLowerCase().endsWith(getFileSuffix()))
@ -50,15 +49,19 @@ public abstract class AbstractBaseFileImporter implements DocumentImporter {
return;
}
// === 生成 filepath ===
String absPath = path.toAbsolutePath().toString().replace("\\", "/");
String cleanedPrefix = excludePrefix.replace("\\", "/");
if (!cleanedPrefix.endsWith("/")) {
cleanedPrefix += "/";
Path absPath = path.toAbsolutePath().normalize();
Path relativePathObj;
if (absPath.startsWith(excludeBase)) {
relativePathObj = excludeBase.relativize(absPath);
} else {
logger.warn("路径未匹配 exclude.prefix使用全路径: {}", absPath);
relativePathObj = absPath;
}
String relativePath = absPath.startsWith(cleanedPrefix)
? absPath.substring(cleanedPrefix.length())
: absPath;
String relativePath = relativePathObj.toString().replace("\\", "/");
logger.info("absPath: {}", absPath.toString().replace("\\", "/"));
logger.info("rerelativePath: {}", relativePath);
// relativePath 作为文档 ID
GetRequest getRequest = new GetRequest(INDEX_NAME, relativePath);