|
|
@@ -10,20 +10,19 @@ 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;
|
|
|
-import io.swagger.annotations.ApiImplicitParam;
|
|
|
-import io.swagger.annotations.ApiImplicitParams;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
+import io.swagger.annotations.*;
|
|
|
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.PathVariable;
|
|
|
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;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
|
* es查询控制器
|
|
|
@@ -51,12 +50,7 @@ public class ElasticSearchController {
|
|
|
*/
|
|
|
@GetMapping("/query")
|
|
|
@ApiOperation("模糊查询")
|
|
|
- @ApiImplicitParams({
|
|
|
- @ApiImplicitParam(name = "type", value = "空间类型(1.公共空间 2.部门空间 3.个人空间", required = true),
|
|
|
- @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true),
|
|
|
- @ApiImplicitParam(name = "page", value = "当前页码", required = true),
|
|
|
- @ApiImplicitParam(name = "size", value = "每页条数", required = true)
|
|
|
- })
|
|
|
+ @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "空间类型(1.公共空间 2.部门空间 3.个人空间", required = true), @ApiImplicitParam(name = "keyword", value = "搜索关键字", required = true), @ApiImplicitParam(name = "page", value = "当前页码", required = true), @ApiImplicitParam(name = "size", value = "每页条数", required = true)})
|
|
|
public AjaxResult query(String type, String keyword, int page, int size) {
|
|
|
//因为es查询是从第0页开始,所以页码要-1才行
|
|
|
page = page - 1;
|
|
|
@@ -96,4 +90,23 @@ public class ElasticSearchController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 模糊查询ik分词器分词的content字段
|
|
|
+ */
|
|
|
+ @GetMapping("/query/{docId}")
|
|
|
+ @ApiOperation("根据ID查询文本内容")
|
|
|
+ public AjaxResult queryByDocId(@ApiParam(value = "文件ID", required = true) @PathVariable Long docId) {
|
|
|
+ DocInfo docInfo = infoService.selectDocInfoByDocId(docId);
|
|
|
+ String indexName = "docs_" + docInfo.getSpaceId();
|
|
|
+ esConfig.setIndexName(indexName);
|
|
|
+ Optional<EsDocInfo> optional = esDocInfoService.findById(docId);
|
|
|
+ if (optional.isPresent()) {
|
|
|
+ EsDocInfo info = optional.get();
|
|
|
+ info.setDocInfo(docInfo);
|
|
|
+ return AjaxResult.success(optional.get());
|
|
|
+ } else {
|
|
|
+ return AjaxResult.success(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|