|
@@ -95,25 +95,28 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
|
|
|
public void taskSave(DocInfo info) {
|
|
|
String fileType = info.getFileType().toLowerCase();
|
|
|
String content = "";
|
|
|
- if (Constants.IMAGE_EXTENSION.contains(fileType)) {
|
|
|
- content = getContent(fileType, info.getFileId());
|
|
|
- } else {
|
|
|
- Map<String, Function<byte[], String>> handlerMap = createHandlerMap(fileType);
|
|
|
- content = getContent(handlerMap, fileType, info.getFileId());
|
|
|
- if (Constants.PDF_EXTENSION.contains(fileType) && StringUtils.isEmpty(content)) {
|
|
|
- //如果是PDF未解析成功,则另外进行解析工作
|
|
|
+ try {
|
|
|
+ if (Constants.IMAGE_EXTENSION.contains(fileType)) {
|
|
|
content = getContent(fileType, info.getFileId());
|
|
|
+ } else {
|
|
|
+ Map<String, Function<byte[], String>> handlerMap = createHandlerMap(fileType);
|
|
|
+ content = getContent(handlerMap, fileType, info.getFileId());
|
|
|
+ if (Constants.PDF_EXTENSION.contains(fileType) && StringUtils.isEmpty(content)) {
|
|
|
+ //如果是PDF未解析成功,则另外进行解析工作
|
|
|
+ content = getContent(fileType, info.getFileId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ if (StringUtils.isNotEmpty(content)) {
|
|
|
+ comboIndex(info.getSpaceId());
|
|
|
+ EsDocInfo esDocInfo = new EsDocInfo(info.getDocId(), content);
|
|
|
+ esDocInfoService.save(esDocInfo);
|
|
|
+ }
|
|
|
+ //执行完,删除索引任务
|
|
|
+ indexService.deleteDocIndexByDocId(info.getDocId());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析图片错误:{}", e.getMessage());
|
|
|
}
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(content)) {
|
|
|
- comboIndex(info.getSpaceId());
|
|
|
- EsDocInfo esDocInfo = new EsDocInfo(info.getDocId(), content);
|
|
|
- esDocInfoService.save(esDocInfo);
|
|
|
- }
|
|
|
- //执行完,删除索引任务
|
|
|
- indexService.deleteDocIndexByDocId(info.getDocId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -239,12 +242,12 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
|
|
|
* @param fileId 文件ID
|
|
|
* @return 解析结果
|
|
|
*/
|
|
|
- private String getContent(String fileType, String fileId) {
|
|
|
+ private String getContent(String fileType, String fileId) throws Exception {
|
|
|
if (Constants.IMAGE_EXTENSION.contains(fileType)) {
|
|
|
try {
|
|
|
return ocrService.recognition(fileId);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("解析图片错误:{}", e.getMessage());
|
|
|
+ throw new Exception(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
String pdf = ".pdf";
|
|
@@ -258,7 +261,7 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
|
|
|
try {
|
|
|
sb.append(ocrService.recognition(f));
|
|
|
} catch (Exception e) {
|
|
|
- log.error("解析图片错误:{}", e.getMessage());
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
});
|
|
|
return sb.toString();
|