Browse Source

更新 search-service 中裁判文书相关的接口

reghao 7 months ago
parent
commit
81fecc6acf

+ 28 - 16
search/search-service/src/main/java/cn/reghao/tnb/search/app/controller/SearchController.java

@@ -2,15 +2,16 @@ package cn.reghao.tnb.search.app.controller;
 
 import cn.reghao.jutil.jdk.db.PageList;
 import cn.reghao.jutil.web.WebResult;
-import cn.reghao.tnb.search.app.es.WenshuSearch;
+import cn.reghao.tnb.search.app.es.QueryService;
 import cn.reghao.tnb.search.app.model.po.Wenshu;
+import cn.reghao.tnb.search.app.model.vo.ElasticQuery;
+import cn.reghao.tnb.search.app.model.vo.WenshuResult;
 import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.domain.Sort;
+import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 裁判文书搜索接口
@@ -21,28 +22,39 @@ import java.util.List;
 @RestController
 @RequestMapping("/api/search1/wenshu")
 public class SearchController {
-    private final WenshuSearch wenshuSearch;
+    private String indexName = "wenshu";
+    private int pageSize = 12;
+    private final QueryService<Wenshu> queryService;
 
-    public SearchController(WenshuSearch wenshuSearch) {
-        this.wenshuSearch = wenshuSearch;
+    public SearchController(QueryService<Wenshu> queryService) {
+        this.queryService = queryService;
     }
 
-    @GetMapping("/query")
-    public String searchWenshu(@RequestParam(value = "search") String keyword) {
-        Pageable pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime"));
-        Page<Wenshu> page = wenshuSearch.search(keyword, pageable);
+    @GetMapping(value = "/query", produces = MediaType.APPLICATION_JSON_VALUE)
+    public String searchWenshu(@RequestParam(value = "pn") int pn,
+                               @RequestParam(value = "keyword") String keyword) {
+        ElasticQuery elasticQuery = new ElasticQuery.Builder()
+                .pageSize(pageSize)
+                .pageNumber(pn)
+                .indexName(indexName)
+                .highlightFieldName("caseName")
+                .otherFiledNames(List.of("caseName", "cause", "parties"))
+                .queryString(keyword)
+                .build();
 
+        Page<Wenshu> page = queryService.queryWithHighlight(elasticQuery, Wenshu.class);
+//        Pageable pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime"));
         int pageNumber = page.getNumber();
         int pageSize = page.getSize();
         int total = (int) page.getTotalElements();
-        List<Wenshu> list = page.getContent();
-        PageList<Wenshu> pageList = PageList.pageList(pageNumber, pageSize, total, list);
+        List<WenshuResult> list = page.getContent().stream().map(WenshuResult::new).collect(Collectors.toList());
+        PageList<WenshuResult> pageList = PageList.pageList(pageNumber, pageSize, total, list);
         return WebResult.success(pageList);
     }
 
-    @GetMapping("/detail/{id}")
+    @GetMapping(value = "/detail/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
     public String getWenshuDetail(@PathVariable("id") String id) {
-        Wenshu wenshuResult = wenshuSearch.getById(id);
-        return WebResult.success(wenshuResult);
+        Wenshu wenshu = queryService.queryById(indexName, id, Wenshu.class);
+        return WebResult.success(wenshu);
     }
 }

+ 1 - 1
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/DocumentService.java

@@ -44,7 +44,7 @@ public class DocumentService {
         //log.error("bulk response.error() = {}", bulkResponse.errors());
     }
 
-    public void batchAddDocument1(String indexName, List<Wenshu> wenshuList) throws IOException {
+    public void batchAddWenshu(String indexName, List<Wenshu> wenshuList) throws IOException {
         List<BulkOperation> bulkOperations = new ArrayList<>();
         wenshuList.forEach(p -> bulkOperations.add(BulkOperation.of(b -> b.index(c -> c.id(p.getId()).document(p)))));
         BulkResponse bulkResponse = esClient.bulk(s -> s.index(indexName).operations(bulkOperations));

+ 1 - 1
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/MappingService.java

@@ -50,7 +50,7 @@ public class MappingService {
         return propertyMap;
     }
 
-    public Map<String, Property> getWenshuPropertyMap() {
+    public Map<String, Property> getPropertyMapByWenshu() {
         Map<String, Property> propertyMap = new HashMap<>();
         propertyMap.put("id", keywordProp);
         propertyMap.put("originalUrl", keywordProp);

+ 14 - 11
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/QueryService.java

@@ -1,6 +1,7 @@
 package cn.reghao.tnb.search.app.es;
 
 import cn.reghao.tnb.content.api.constant.PostScope;
+import cn.reghao.tnb.search.app.model.vo.ElasticQuery;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.FieldValue;
 import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
@@ -38,11 +39,13 @@ public class QueryService<T> {
         this.esClient = elasticService.getElasticsearchClient();
     }
 
-    public Page<T> queryWithHighlight(String index, String queryString, int pn, int ps, Class<T> clazz) {
-        String highlightFieldName1 = "title";
-        String highlightFieldName = "caseName";
-        List<String> otherFiledNames = List.of("caseName", "cause", "parties");
-        List<String> otherFiledNames1 = List.of();
+    public Page<T> queryWithHighlight(ElasticQuery elasticQuery, Class<T> clazz) {
+        int pageSize = elasticQuery.getPageSize();
+        int pageNumber = elasticQuery.getPageNumber();
+        String indexName = elasticQuery.getIndexName();
+        String highlightFieldName = elasticQuery.getHighlightFieldName();
+        List<String> otherFiledNames = elasticQuery.getOtherFiledNames();
+        String queryString = elasticQuery.getQueryString();
 
         // 1.构建查询的对象
         QueryStringQuery stringQuery = new QueryStringQuery.Builder()
@@ -72,11 +75,11 @@ public class QueryService<T> {
                 .build();
 
         // 3.搜索请求
-        int start = (pn-1)*ps;
+        int start = (pageNumber-1)*pageSize;
         SearchRequest searchRequest = new SearchRequest.Builder()
-                .index(index)
+                .index(indexName)
                 .from(start)
-                .size(ps)
+                .size(pageSize)
                 .query(query)
                 .highlight(highlight)
                 .build();
@@ -111,7 +114,7 @@ public class QueryService<T> {
             }).collect(Collectors.toList());
 
             //return list;
-            PageRequest pageRequest = PageRequest.of(pn-1, ps);
+            PageRequest pageRequest = PageRequest.of(pageNumber-1, pageSize);
             return new PageImpl<>(list, pageRequest, total);
         } catch (IOException e) {
             log.error("search By Query Highlight error", e);
@@ -283,13 +286,13 @@ public class QueryService<T> {
         return Page.empty();
     }
 
-    public T queryById(Class<T> clazz, String index, String id) {
+    public T queryById(String indexName, String id, Class<T> clazz) {
         Query query = TermQuery.of(t -> t
                 .field("id").value(FieldValue.of(id))
         )._toQuery();
 
         SearchRequest searchRequest = SearchRequest.of(s -> s
-                .index(index)
+                .index(indexName)
                 .query(query)
         );
 

+ 2 - 8
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/WenshuSearch.java

@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
  */
 @Service
 public class WenshuSearch {
-    private final QueryService<Wenshu> queryService;
+    private QueryService<Wenshu> queryService;
     private String index = "wenshu";
 
     public WenshuSearch(ElasticService elasticService) {
@@ -21,12 +21,6 @@ public class WenshuSearch {
     public Page<Wenshu> search(String keyword, Pageable pageable) {
         int pn = pageable.getPageNumber()+1;
         int ps = pageable.getPageSize();
-        Page<Wenshu> page = queryService.queryWithHighlight(index, keyword, pn, ps, Wenshu.class);
-        return page;
-    }
-
-    public Wenshu getById(String id) {
-        Wenshu wenshu = queryService.queryById(Wenshu.class, index, id);
-        return wenshu;
+        return Page.empty();
     }
 }

+ 1 - 1
search/search-service/src/main/java/cn/reghao/tnb/search/app/log/consumer/RabbitListeners.java

@@ -39,7 +39,7 @@ public class RabbitListeners {
         logHandler.pushGatewayLog(gatewayLog);
         log.info("{} -> {}", gatewayLog.getRequestId(), gatewayLog.getRequestUrl());
         AccessLog accessLog = new AccessLog(gatewayLog);
-        accessLogMongo.save(accessLog);
+        //accessLogMongo.save(accessLog);
     }
 
     @RabbitListener(bindings =@QueueBinding(

+ 79 - 0
search/search-service/src/main/java/cn/reghao/tnb/search/app/model/vo/ElasticQuery.java

@@ -0,0 +1,79 @@
+package cn.reghao.tnb.search.app.model.vo;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2025-08-20 14:27:11
+ */
+@Getter
+@Setter
+public class ElasticQuery {
+    private int pageSize;
+    private int pageNumber;
+    private String indexName;
+    private String highlightFieldName;
+    private List<String> otherFiledNames;
+    private String queryString;
+
+    public ElasticQuery() {
+        this.pageSize = 10;
+        this.pageNumber = 1;
+        this.otherFiledNames = List.of();
+    }
+
+    private ElasticQuery(Builder builder) {
+        this.pageSize = builder.pageSize;
+        this.pageNumber = builder.pageNumber;
+        this.indexName = builder.indexName;
+        this.highlightFieldName = builder.highlightFieldName;
+        this.otherFiledNames = builder.otherFiledNames;
+        this.queryString = builder.queryString;
+    }
+
+    public static final class Builder {
+        private int pageSize;
+        private int pageNumber;
+        private String indexName;
+        private String highlightFieldName;
+        private List<String> otherFiledNames;
+        private String queryString;
+
+        public Builder pageSize(int pageSize) {
+            this.pageSize = pageSize;
+            return this;
+        }
+
+        public Builder pageNumber(int pageNumber) {
+            this.pageNumber = pageNumber;
+            return this;
+        }
+
+        public Builder indexName(String indexName) {
+            this.indexName = indexName;
+            return this;
+        }
+
+        public Builder highlightFieldName(String highlightFieldName) {
+            this.highlightFieldName = highlightFieldName;
+            return this;
+        }
+
+        public Builder otherFiledNames(List<String> otherFiledNames) {
+            this.otherFiledNames = otherFiledNames;
+            return this;
+        }
+
+        public Builder queryString(String queryString) {
+            this.queryString = queryString;
+            return this;
+        }
+
+        public ElasticQuery build() {
+            return new ElasticQuery(this);
+        }
+    }
+}

+ 61 - 0
search/search-service/src/main/java/cn/reghao/tnb/search/app/model/vo/WenshuResult.java

@@ -0,0 +1,61 @@
+package cn.reghao.tnb.search.app.model.vo;
+
+import cn.reghao.tnb.search.app.model.po.Wenshu;
+import lombok.Getter;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2025-08-20 14:52:09
+ */
+@Getter
+public class WenshuResult {
+    private long id;
+    // 原始链接
+    private String originalUrl;
+    // 案号
+    private String caseId;
+    // 案件名称
+    private String caseName;
+    // 法院
+    private String court;
+    // 所属地区
+    private String region;
+    // 案件类型
+    private String caseType;
+    // 案件类型编码
+    private String caseTypeId;
+    // 审理程序
+    private String procedure;
+    // 裁判日期
+    private String judgmentDate;
+    // 发布日期
+    private String publicDate;
+    // 当事人
+    private String parties;
+    // 案由
+    private String cause;
+    // 法律依据
+    private String legalBasis;
+    private List<String> legalBasisList;
+
+    public WenshuResult(Wenshu wenshu) {
+        this.id = Long.parseLong(wenshu.getId());
+        this.caseName = wenshu.getCaseName();
+        this.originalUrl = wenshu.getOriginalUrl();
+        this.caseId = wenshu.getCaseId();
+        this.court = wenshu.getCourt();
+        this.region = wenshu.getRegion();
+        this.caseType = wenshu.getCaseType();
+        this.caseTypeId = wenshu.getCaseTypeId();
+        this.procedure = wenshu.getProcedure();
+        this.judgmentDate = wenshu.getJudgmentDate();
+        this.publicDate = wenshu.getPublicDate();
+        this.parties = wenshu.getParties();
+        this.cause = wenshu.getCause();
+        this.legalBasis = wenshu.getLegalBasis();
+        this.legalBasisList = Arrays.asList(this.legalBasis.split(";"));
+    }
+}

+ 6 - 163
search/search-service/src/test/java/SearchTest.java

@@ -3,24 +3,14 @@ import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
 import cn.reghao.jutil.tool.id.SnowFlake;
 import cn.reghao.tnb.content.api.constant.PostScope;
-import cn.reghao.tnb.search.api.dto.VideoSummary;
 import cn.reghao.tnb.search.app.SearchApplication;
 import cn.reghao.tnb.search.app.es.*;
 import cn.reghao.tnb.search.app.lucene.LuceneDocument;
 import cn.reghao.tnb.search.app.lucene.LuceneIndex;
 import cn.reghao.tnb.search.app.lucene.LuceneQuery;
 import cn.reghao.tnb.search.app.model.po.VideoText;
-import cn.reghao.tnb.search.app.model.po.Wenshu;
-import cn.reghao.tnb.search.app.util.ClassUtil;
-import co.elastic.clients.elasticsearch.ElasticsearchClient;
-import co.elastic.clients.elasticsearch._types.FieldValue;
 import co.elastic.clients.elasticsearch._types.mapping.Property;
-import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
-import co.elastic.clients.elasticsearch._types.query_dsl.Query;
-import co.elastic.clients.elasticsearch._types.query_dsl.QueryStringQuery;
 import co.elastic.clients.elasticsearch.indices.AnalyzeRequest;
-import co.elastic.clients.elasticsearch.indices.AnalyzeResponse;
-import co.elastic.clients.elasticsearch.indices.analyze.AnalyzeToken;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
 import org.slf4j.LoggerFactory;
@@ -30,11 +20,7 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.test.context.ActiveProfiles;
 
-import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel;
 import java.util.*;
 
 /**
@@ -45,6 +31,12 @@ import java.util.*;
 @ActiveProfiles("dev")
 @SpringBootTest(classes = SearchApplication.class)
 public class SearchTest {
+    void setLogLevel() {
+        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
+        Logger rootLogger = loggerContext.getLogger("ROOT");
+        rootLogger.setLevel(Level.INFO);
+    }
+
     SnowFlake idGenerator = new SnowFlake(1, 1);
     @Autowired
     ElasticService elasticService;
@@ -54,58 +46,6 @@ public class SearchTest {
     MappingService mappingService;
     @Autowired
     DocumentService documentService;
-    @Autowired
-    QueryService<Wenshu> queryService;
-    String index = Wenshu.class.getSimpleName().toLowerCase(Locale.ROOT);
-
-    void readByFileChannel(String filePath, DocumentService documentService) {
-        List<Wenshu> list = new ArrayList<>();
-        File file = new File(filePath);
-        try {
-            FileInputStream fis = new FileInputStream(file);
-            FileChannel fileChannel = fis.getChannel();
-
-            int total = 0;
-            // 10MB
-            int capacity = 10*1024*1024;
-            ByteBuffer byteBuffer = ByteBuffer.allocate(capacity);
-            StringBuffer buffer = new StringBuffer();
-            while(fileChannel.read(byteBuffer) != -1) {
-                //读取后,将位置置为0,将limit置为容量, 以备下次读入到字节缓冲中,从0开始存储
-                byteBuffer.clear();
-                byte[] bytes = byteBuffer.array();
-
-                String str = new String(bytes);
-                buffer.append(str);
-                String[] strArray = buffer.toString().split(System.lineSeparator());
-                for (int i = 0; i < strArray.length-1; i++) {
-                    String line = strArray[i];
-                    Wenshu wenshu = parseLine(line);
-                    if (wenshu != null) {
-                        list.add(wenshu);
-                    } else {
-                        log.error("error parse line: {}", ++total);
-                    }
-
-                    if (list.size() > 10_000) {
-                        documentService.batchAddDocument1(index, list);
-                        log.info("add {} documents to es", list.size());
-                        list.clear();
-                    }
-                }
-
-                String lastLine = strArray[strArray.length-1];
-                if (!lastLine.endsWith("}")) {
-                    buffer = new StringBuffer();
-                    buffer.append(strArray[strArray.length-1]);
-                }
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        } finally {
-            // TODO close 处理
-        }
-    }
 
     @Test
     public void indexTest() throws IOException {
@@ -123,103 +63,6 @@ public class SearchTest {
         videoTextDocument.deleteAllDocument();
     }
 
-    void setLogLevel() {
-        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
-        Logger rootLogger = loggerContext.getLogger("ROOT");
-        rootLogger.setLevel(Level.INFO);
-    }
-
-    public void addDocTest() {
-        setLogLevel();
-        documentService.deleteAllDocument(index);
-        String filePath = "/home/reghao/Downloads/2021年01月裁判文书数据.csv";
-        readByFileChannel(filePath, documentService);
-    }
-
-    private Wenshu parseLine(String line) {
-        String[] arr = line.split(",");
-        try {
-            List<String> fields = new ArrayList<>();
-            String id = idGenerator.nextId()+"";
-            fields.add(id);
-
-            String originalUrl = arr[0];
-            String caseId = arr[1];
-            String caseName = arr[2];
-            String court = arr[3];
-            String region = arr[4];
-            String caseType = arr[5];
-            String caseTypeId = arr[6];
-            fields.addAll(Arrays.asList(arr).subList(0, 7));
-            String procedure = arr[8];
-            fields.add(procedure);
-            String judgmentDate = arr[9];
-            fields.add(judgmentDate);
-            String publicDate = arr[10];
-            fields.add(publicDate);
-            String parties = arr[11];
-            fields.add(parties);
-
-            String cause = "";
-            String legalBasis = "";
-            String fullText = "";
-            if (arr.length == 13) {
-                cause = arr[12];
-            } else if (arr.length == 14) {
-                cause = arr[12];
-                legalBasis = arr[13];
-            } else if (arr.length == 15) {
-                cause = arr[12];
-                legalBasis = arr[13];
-                fullText = arr[14];
-            } else if (arr.length > 15) {
-                cause = arr[12];
-                legalBasis = arr[13];
-                String str = line.split(legalBasis)[1];
-                fullText = str.substring(1);
-            }
-
-            fields.add(cause);
-            fields.add(legalBasis);
-            fields.add(fullText);
-
-            Object object = ClassUtil.getObject(Wenshu.class, fields.toArray(new String[0]));
-            if (object instanceof  Wenshu) {
-                return (Wenshu) object;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return null;
-    }
-
-    @Test
-    public void queryTest() {
-        setLogLevel();
-
-        int pn = 1;
-        int ps = 10;
-        String queryString = "拐卖";
-        /*List<Wenshu> page = queryService.queryWithHighlight(index, queryString, pn, ps, Wenshu.class);
-        while (!page.isEmpty()) {
-            pn++;
-            page = queryService.queryWithHighlight(index, queryString, pn, ps, Wenshu.class);
-        }*/
-        Page<Wenshu> page = queryService.queryWithHighlight(index, queryString, pn, ps, Wenshu.class);
-        long total = page.getTotalElements();
-        int totalPages = page.getTotalPages();
-        while (pn <= totalPages) {
-            page = queryService.queryWithHighlight(index, queryString, pn, ps, Wenshu.class);
-            List<Wenshu> list = page.getContent();
-            Wenshu wenshu = list.get(0);
-            String id = wenshu.getId();
-            String caseName = wenshu.getCaseName();
-            System.out.println(caseName);
-            pn++;
-        }
-    }
-
     @Autowired
     LuceneQuery luceneQuery;
     @Autowired

+ 210 - 0
search/search-service/src/test/java/WenshuTest.java

@@ -0,0 +1,210 @@
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import cn.reghao.jutil.tool.id.SnowFlake;
+import cn.reghao.tnb.content.api.constant.PostScope;
+import cn.reghao.tnb.search.app.SearchApplication;
+import cn.reghao.tnb.search.app.es.*;
+import cn.reghao.tnb.search.app.lucene.LuceneDocument;
+import cn.reghao.tnb.search.app.lucene.LuceneIndex;
+import cn.reghao.tnb.search.app.lucene.LuceneQuery;
+import cn.reghao.tnb.search.app.model.po.VideoText;
+import cn.reghao.tnb.search.app.model.po.Wenshu;
+import cn.reghao.tnb.search.app.model.vo.ElasticQuery;
+import cn.reghao.tnb.search.app.util.ClassUtil;
+import co.elastic.clients.elasticsearch._types.mapping.Property;
+import co.elastic.clients.elasticsearch.indices.AnalyzeRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.util.*;
+
+/**
+ * @author reghao
+ * @date 2025-03-18 15:51:21
+ */
+@Slf4j
+@ActiveProfiles("dev")
+@SpringBootTest(classes = SearchApplication.class)
+public class WenshuTest {
+    void setLogLevel() {
+        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
+        Logger rootLogger = loggerContext.getLogger("ROOT");
+        rootLogger.setLevel(Level.INFO);
+    }
+
+    SnowFlake idGenerator = new SnowFlake(1, 1);
+    @Autowired
+    ElasticService elasticService;
+    @Autowired
+    IndexService indexService;
+    @Autowired
+    MappingService mappingService;
+    @Autowired
+    DocumentService documentService;
+    @Autowired
+    QueryService<Wenshu> queryService;
+    String indexName = Wenshu.class.getSimpleName().toLowerCase(Locale.ROOT);
+
+    void readByFileChannel(String filePath, DocumentService documentService) {
+        List<Wenshu> list = new ArrayList<>();
+        File file = new File(filePath);
+        try {
+            FileInputStream fis = new FileInputStream(file);
+            FileChannel fileChannel = fis.getChannel();
+
+            int total = 0;
+            // 10MB
+            int capacity = 10*1024*1024;
+            ByteBuffer byteBuffer = ByteBuffer.allocate(capacity);
+            StringBuffer buffer = new StringBuffer();
+            while(fileChannel.read(byteBuffer) != -1) {
+                //读取后,将位置置为0,将limit置为容量, 以备下次读入到字节缓冲中,从0开始存储
+                byteBuffer.clear();
+                byte[] bytes = byteBuffer.array();
+
+                String str = new String(bytes);
+                buffer.append(str);
+                String[] strArray = buffer.toString().split(System.lineSeparator());
+                for (int i = 0; i < strArray.length-1; i++) {
+                    String line = strArray[i];
+                    Wenshu wenshu = parseLine(line);
+                    if (wenshu != null) {
+                        list.add(wenshu);
+                    } else {
+                        log.error("error parse line: {}", ++total);
+                    }
+
+                    if (list.size() > 10_000) {
+                        documentService.batchAddWenshu(indexName, list);
+                        log.info("add {} documents to es", list.size());
+                        list.clear();
+                    }
+                }
+
+                String lastLine = strArray[strArray.length-1];
+                if (!lastLine.endsWith("}")) {
+                    buffer = new StringBuffer();
+                    buffer.append(strArray[strArray.length-1]);
+                }
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            // TODO close 处理
+        }
+    }
+
+    private Wenshu parseLine(String line) {
+        String[] arr = line.split(",");
+        try {
+            List<String> fields = new ArrayList<>();
+            String id = idGenerator.nextId()+"";
+            fields.add(id);
+
+            String originalUrl = arr[0];
+            String caseId = arr[1];
+            String caseName = arr[2];
+            String court = arr[3];
+            String region = arr[4];
+            String caseType = arr[5];
+            String caseTypeId = arr[6];
+            fields.addAll(Arrays.asList(arr).subList(0, 7));
+            String procedure = arr[8];
+            fields.add(procedure);
+            String judgmentDate = arr[9];
+            fields.add(judgmentDate);
+            String publicDate = arr[10];
+            fields.add(publicDate);
+            String parties = arr[11];
+            fields.add(parties);
+
+            String cause = "";
+            String legalBasis = "";
+            String fullText = "";
+            if (arr.length == 13) {
+                cause = arr[12];
+            } else if (arr.length == 14) {
+                cause = arr[12];
+                legalBasis = arr[13];
+            } else if (arr.length == 15) {
+                cause = arr[12];
+                legalBasis = arr[13];
+                fullText = arr[14];
+            } else if (arr.length > 15) {
+                cause = arr[12];
+                legalBasis = arr[13];
+                String str = line.split(legalBasis)[1];
+                fullText = str.substring(1);
+            }
+
+            fields.add(cause);
+            fields.add(legalBasis);
+            fields.add(fullText);
+
+            Object object = ClassUtil.getObject(Wenshu.class, fields.toArray(new String[0]));
+            if (object instanceof  Wenshu) {
+                return (Wenshu) object;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    @Test
+    public void addDocTest() throws IOException {
+        String indexName = "wenshu";
+        /*indexService.deleteIndex(indexName);
+        Map<String, Property> propertyMap = mappingService.getPropertyMapByWenshu();
+        indexService.createIndex(indexName, propertyMap);*/
+
+        //documentService.deleteAllDocument(indexName);
+
+        String filePath = "/home/reghao/Downloads/2021年07月裁判文书数据.csv";
+        readByFileChannel(filePath, documentService);
+    }
+
+    @Test
+    public void queryTest() {
+        setLogLevel();
+
+        int pn = 1;
+        int ps = 10;
+        String queryString = "贩毒";
+        ElasticQuery elasticQuery = new ElasticQuery.Builder()
+                .pageSize(10)
+                .pageNumber(1)
+                .indexName(indexName)
+                .highlightFieldName("caseName")
+                .otherFiledNames(List.of("caseName", "cause", "parties"))
+                .queryString(queryString)
+                .build();
+
+        Page<Wenshu> page = queryService.queryWithHighlight(elasticQuery, Wenshu.class);
+        long total = page.getTotalElements();
+        int totalPages = page.getTotalPages();
+        while (pn <= totalPages) {
+            elasticQuery.setPageNumber(pn);
+            page = queryService.queryWithHighlight(elasticQuery, Wenshu.class);
+            List<Wenshu> list = page.getContent();
+            Wenshu wenshu = list.get(0);
+            String id = wenshu.getId();
+            String caseName = wenshu.getCaseName();
+            System.out.printf("%s -> %s\n", id, caseName);
+            pn++;
+        }
+    }
+}