Browse Source

快速检索相关任务处理。我发送的文件和我接收的文件BUG修改。

wukai 2 years ago
parent
commit
5492a593c0

+ 35 - 13
lzga-modules/lzga-doc/src/main/java/com/jjt/doc/controller/ElasticSearchController.java

@@ -1,10 +1,11 @@
 package com.jjt.doc.controller;
 
 import com.alibaba.fastjson2.JSON;
+import com.jjt.doc.domain.DocInfo;
 import com.jjt.doc.domain.EsDocInfo;
 import com.jjt.doc.domain.HelloEntity;
-import com.jjt.doc.domain.PageDTO;
-import com.jjt.doc.service.EsDocInfoService;
+import com.jjt.doc.service.IDocInfoService;
+import com.jjt.doc.service.IEsDocInfoService;
 import com.jjt.doc.service.HelloDao;
 import org.elasticsearch.index.query.MatchQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilders;
@@ -35,7 +36,9 @@ public class ElasticSearchController {
     @Resource
     private HelloDao helloDao;
     @Resource
-    private EsDocInfoService esDocInfoService;
+    private IEsDocInfoService esDocInfoService;
+    @Resource
+    private IDocInfoService infoService;
 
     /**
      * 创建索引 hello
@@ -124,12 +127,13 @@ public class ElasticSearchController {
     /**
      * 分页查询
      *
-     * @param pageDTO
+     * @param page
+     * @param size
      * @return
      */
-    @GetMapping
-    public String getAll(@RequestBody PageDTO pageDTO) {
-        PageRequest pageable = PageRequest.of(pageDTO.getPage(), pageDTO.getSize());
+    @GetMapping("/getAll")
+    public String getAll(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
+        PageRequest pageable = PageRequest.of(page, size);
         Page<HelloEntity> all = helloDao.findAll(pageable);
         return JSON.toJSONString(all);
     }
@@ -176,8 +180,28 @@ public class ElasticSearchController {
      * @return
      */
     @GetMapping("/findByContent")
-    public String queryContent(@RequestParam(value = "content", required = false) String content) {
-        List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(content);
+    public String queryContent(@RequestParam(value = "content", required = true) String content) {
+        List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(content, PageRequest.of(1, 2));
+        return JSON.toJSONString(all);
+    }
+
+    /**
+     * 模糊查询ik分词器分词的content字段
+     *
+     * @return
+     */
+    @GetMapping("/query")
+    public String query(@RequestParam(value = "content", required = true) String content, @RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
+        List<SearchHit<EsDocInfo>> all = esDocInfoService.findByContent(content, PageRequest.of(page, size));
+        for (SearchHit<EsDocInfo> re : all) {
+            EsDocInfo esDocInfo = re.getContent();
+            DocInfo docInfo = new DocInfo();
+            docInfo.setDocId(esDocInfo.getId());
+            docInfo.setCreateYear(esDocInfo.getYear());
+            docInfo = infoService.selectDocInfoByDocInfo(docInfo);
+            esDocInfo.setInfo(docInfo);
+//            re.getContent().
+        }
         return JSON.toJSONString(all);
     }
 
@@ -207,11 +231,9 @@ public class ElasticSearchController {
         goodsNameField.postTags("</span>");
 
         //创建条件组装器并组装条件然后构建出封装了所有条件的对象
-        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
-                .withQuery(matchQuery)
+        NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery)
                 //组装配置的高亮字段
-                .withHighlightFields(goodsNameField)
-                .build();
+                .withHighlightFields(goodsNameField).build();
 
         //查询
         SearchHits<HelloEntity> searchHits = elasticsearchRestTemplate.search(searchQuery, HelloEntity.class);

+ 4 - 0
lzga-modules/lzga-doc/src/main/java/com/jjt/doc/domain/EsDocInfo.java

@@ -25,6 +25,10 @@ public class EsDocInfo {
 
     @Field(type = FieldType.Long)
     private Long year;
+    /**
+     * 文件信息
+     */
+    private DocInfo info;
 
     public EsDocInfo(Long id, String content, Long year) {
         this.id = id;

+ 14 - 4
lzga-modules/lzga-doc/src/main/java/com/jjt/doc/service/EsDocInfoService.java → lzga-modules/lzga-doc/src/main/java/com/jjt/doc/service/IEsDocInfoService.java

@@ -1,9 +1,7 @@
 package com.jjt.doc.service;
 
 import com.jjt.doc.domain.EsDocInfo;
-import com.jjt.doc.domain.HelloEntity;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.elasticsearch.annotations.Highlight;
 import org.springframework.data.elasticsearch.annotations.HighlightField;
 import org.springframework.data.elasticsearch.core.SearchHit;
@@ -15,7 +13,19 @@ import java.util.List;
 /**
  * @author wukai
  */
-public interface EsDocInfoService extends ElasticsearchRepository<EsDocInfo, Long> {
+public interface IEsDocInfoService extends ElasticsearchRepository<EsDocInfo, Long> {
+
+    /**
+     * 模糊查询content
+     *
+     * @param content  查询内容
+     * @param pageable 分页参数
+     * @return
+     */
+    @Highlight(fields = {
+            @HighlightField(name = "content")
+    })
+    List<SearchHit<EsDocInfo>> findByContent(String content, Pageable pageable);
 
     /**
      * 模糊查询content

+ 1 - 1
lzga-modules/lzga-doc/src/main/java/com/jjt/doc/service/impl/DocInfoServiceImpl.java

@@ -39,7 +39,7 @@ public class DocInfoServiceImpl implements IDocInfoService {
     @Resource
     private RemoteFileService remoteFileService;
     @Resource
-    private EsDocInfoService esDocInfoService;
+    private IEsDocInfoService esDocInfoService;
     @Resource
     private IDocVersionService docVersionService;
     @Resource

+ 2 - 2
lzga-modules/lzga-doc/src/main/resources/mapper/doc/DocShareMapper.xml

@@ -53,7 +53,7 @@
     </select>
 
     <select id="selectDocShareSend" resultType="com.jjt.doc.domain.DocShare">
-        select a.doc_id, a.UPDATE_TIME, b.doc_name, b.doc_type, b.doc_path
+        select a.*, b.doc_name, b.doc_type, b.doc_path
         from doc_share a,
              doc_info b
         where a.doc_id = b.doc_id
@@ -61,7 +61,7 @@
         order by a.update_time desc
     </select>
     <select id="selectDocShareReceive" resultType="com.jjt.doc.domain.DocShare">
-        select a.doc_id, a.UPDATE_TIME, b.doc_name, b.doc_type, b.doc_path
+        select a.*, b.doc_name, b.doc_type, b.doc_path
         from (select t.*
               from doc_share t,
                    doc_share_accepter t1