|
|
@@ -8,6 +8,7 @@ import com.doc.biz.service.IDocInfoService;
|
|
|
import com.doc.biz.service.IDocSpaceService;
|
|
|
import com.doc.biz.service.IEsDocInfoService;
|
|
|
import com.doc.common.config.EsConfig;
|
|
|
+import com.doc.common.core.domain.AjaxResult;
|
|
|
import com.doc.common.enums.SpaceType;
|
|
|
import com.doc.common.utils.SecurityUtils;
|
|
|
import io.swagger.annotations.Api;
|
|
|
@@ -15,6 +16,7 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.elasticsearch.NoSuchIndexException;
|
|
|
import org.springframework.data.elasticsearch.core.SearchHit;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -55,7 +57,7 @@ public class ElasticSearchController {
|
|
|
@ApiImplicitParam(name = "page", value = "当前页码", required = true),
|
|
|
@ApiImplicitParam(name = "size", value = "每页条数", required = true)
|
|
|
})
|
|
|
- public String query(String type, String keyword, int page, int size) {
|
|
|
+ public AjaxResult query(String type, String keyword, int page, int size) {
|
|
|
//因为es查询是从第0页开始,所以页码要-1才行
|
|
|
page = page - 1;
|
|
|
DocSpace space = new DocSpace();
|
|
|
@@ -72,20 +74,23 @@ public class ElasticSearchController {
|
|
|
esConfig.setIndexName(indexName);
|
|
|
try {
|
|
|
List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(keyword, PageRequest.of(page, size));
|
|
|
- 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);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ return AjaxResult.success("查询成功", all);
|
|
|
+ } else {
|
|
|
+ return AjaxResult.success("无结果");
|
|
|
}
|
|
|
- return JSON.toJSONString(all);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return "error";
|
|
|
+ } catch (NoSuchIndexException e) {
|
|
|
+ return AjaxResult.success("无结果");
|
|
|
}
|
|
|
} else {
|
|
|
- return "error";
|
|
|
+ return AjaxResult.success("无结果");
|
|
|
}
|
|
|
}
|
|
|
|