|
@@ -8,15 +8,17 @@ 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;
|
|
|
+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.core.ElasticsearchRestTemplate;
|
|
|
import org.springframework.data.elasticsearch.core.SearchHit;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
@@ -26,10 +28,10 @@ import java.util.List;
|
|
|
*
|
|
|
* @author wukai
|
|
|
*/
|
|
|
+@Api(tags = "全文搜索")
|
|
|
@RestController
|
|
|
-@RequestMapping("es")
|
|
|
+@RequestMapping("/es")
|
|
|
public class ElasticSearchController {
|
|
|
-
|
|
|
@Resource
|
|
|
private IEsDocInfoService esDocInfoService;
|
|
|
@Resource
|
|
@@ -46,7 +48,16 @@ public class ElasticSearchController {
|
|
|
* @return
|
|
|
*/
|
|
|
@GetMapping("/query")
|
|
|
- public String query(@RequestParam(value = "type", required = true) String type, @RequestParam(value = "content", required = true) String content, @RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
|
|
|
+ @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)
|
|
|
+ })
|
|
|
+ public String query(String type, String keyword, int page, int size) {
|
|
|
+ //因为es查询是从第0页开始,所以页码要-1才行
|
|
|
+ page = page - 1;
|
|
|
DocSpace space = new DocSpace();
|
|
|
space.setSpaceType(type);
|
|
|
|
|
@@ -60,7 +71,7 @@ public class ElasticSearchController {
|
|
|
String indexName = "docs_" + list.get(0).getSpaceId();
|
|
|
esConfig.setIndexName(indexName);
|
|
|
try {
|
|
|
- List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(content, PageRequest.of(page, size));
|
|
|
+ List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(keyword, PageRequest.of(page, size));
|
|
|
for (SearchHit<EsDocInfo> re : all) {
|
|
|
EsDocInfo esDocInfo = re.getContent();
|
|
|
DocInfo docInfo = new DocInfo();
|
|
@@ -71,10 +82,10 @@ public class ElasticSearchController {
|
|
|
return JSON.toJSONString(all);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- return null;
|
|
|
+ return "error";
|
|
|
}
|
|
|
} else {
|
|
|
- return null;
|
|
|
+ return "error";
|
|
|
}
|
|
|
}
|
|
|
|