fix docker path bug
This commit is contained in:
parent
fe74eb879d
commit
f423a9df10
@ -13,9 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -38,7 +36,8 @@ public abstract class AbstractBaseFileImporter implements DocumentImporter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void importDocuments() throws IOException {
|
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)
|
Files.walk(basePath)
|
||||||
.filter(p -> p.toString().toLowerCase().endsWith(getFileSuffix()))
|
.filter(p -> p.toString().toLowerCase().endsWith(getFileSuffix()))
|
||||||
@ -50,15 +49,19 @@ public abstract class AbstractBaseFileImporter implements DocumentImporter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === 生成 filepath ===
|
Path absPath = path.toAbsolutePath().normalize();
|
||||||
String absPath = path.toAbsolutePath().toString().replace("\\", "/");
|
Path relativePathObj;
|
||||||
String cleanedPrefix = excludePrefix.replace("\\", "/");
|
|
||||||
if (!cleanedPrefix.endsWith("/")) {
|
if (absPath.startsWith(excludeBase)) {
|
||||||
cleanedPrefix += "/";
|
relativePathObj = excludeBase.relativize(absPath);
|
||||||
|
} else {
|
||||||
|
logger.warn("路径未匹配 exclude.prefix,使用全路径: {}", absPath);
|
||||||
|
relativePathObj = absPath;
|
||||||
}
|
}
|
||||||
String relativePath = absPath.startsWith(cleanedPrefix)
|
|
||||||
? absPath.substring(cleanedPrefix.length())
|
String relativePath = relativePathObj.toString().replace("\\", "/");
|
||||||
: absPath;
|
logger.info("absPath: {}", absPath.toString().replace("\\", "/"));
|
||||||
|
logger.info("rerelativePath: {}", relativePath);
|
||||||
|
|
||||||
// 以 relativePath 作为文档 ID
|
// 以 relativePath 作为文档 ID
|
||||||
GetRequest getRequest = new GetRequest(INDEX_NAME, relativePath);
|
GetRequest getRequest = new GetRequest(INDEX_NAME, relativePath);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user