Преглед изворни кода

修复Es查询时,文档被删除的BUG。

wukai пре 2 година
родитељ
комит
c326e16479

+ 8 - 5
doc-biz/src/main/java/com/doc/biz/controller/ElasticSearchController.java

@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -73,15 +74,17 @@ public class ElasticSearchController {
             esConfig.setIndexName(indexName);
             try {
                 List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(keyword, PageRequest.of(page, size));
+                List<SearchHit<EsDocInfo>> result = new ArrayList<>();
                 if (all.size() > 0) {
                     for (SearchHit<EsDocInfo> re : all) {
                         EsDocInfo esDocInfo = re.getContent();
-                        DocInfo docInfo = new DocInfo();
-                        docInfo.setDocId(esDocInfo.getId());
-                        docInfo = infoService.selectDocInfoByDocId(esDocInfo.getId());
-                        esDocInfo.setDocInfo(docInfo);
+                        DocInfo docInfo = infoService.selectDocInfoByDocId(esDocInfo.getId());
+                        if (docInfo != null) {
+                            esDocInfo.setDocInfo(docInfo);
+                            result.add(re);
+                        }
                     }
-                    return AjaxResult.success("查询成功", all);
+                    return AjaxResult.success("查询成功", result);
                 } else {
                     return AjaxResult.success("无结果");
                 }