Pārlūkot izejas kodu

update search-service

reghao 7 mēneši atpakaļ
vecāks
revīzija
478fff33f2

+ 3 - 1
search/search-api/src/main/java/cn/reghao/tnb/search/api/dto/VideoSummary.java

@@ -22,11 +22,13 @@ public class VideoSummary implements Serializable {
     private String title;
     private String description;
     private Integer scope;
+    private Long publishTime;
 
-    public VideoSummary(String videoId, String title, int scope) {
+    public VideoSummary(String videoId, String title, int scope, long publishTime) {
         this.videoId = videoId;
         this.title = title;
         this.description = title;
         this.scope = scope;
+        this.publishTime = publishTime;
     }
 }

+ 2 - 2
search/search-service/pom.xml

@@ -140,11 +140,11 @@
             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
         </dependency>
 
-        <dependency>
+        <!--<dependency>
             <groupId>com.alibaba.cloud</groupId>
             <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
             <version>2021.0.6.0</version>
-        </dependency>
+        </dependency>-->
     </dependencies>
 
     <profiles>

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

@@ -1,7 +1,6 @@
 package cn.reghao.tnb.search.app.es;
 
 import cn.reghao.tnb.search.app.log.model.NginxLog;
-import cn.reghao.tnb.search.app.model.po.VideoText;
 import cn.reghao.tnb.search.app.model.po.Wenshu;
 import cn.reghao.jutil.tool.id.SnowFlake;
 import co.elastic.clients.elasticsearch.ElasticsearchAsyncClient;
@@ -120,38 +119,4 @@ public class DocumentService {
             System.out.println(success.version());
         });
     }
-
-    public void addVideoText(String indexName, VideoText videoText) throws IOException {
-        videoText.setId(""+idGenerator.nextId());
-        IndexResponse indexResponse = esClient.index(i -> i.index(indexName).id(videoText.getId()).document(videoText));
-        String jsonResult = indexResponse.result().jsonValue();
-    }
-
-    public void batchAddText(String indexName, List<VideoText> videoTextList) {
-        videoTextList.forEach(videoText -> {
-            videoText.setId(""+idGenerator.nextId());
-        });
-
-        List<BulkOperation> bulkOperations = new ArrayList<>();
-        videoTextList.forEach(p -> bulkOperations.add(BulkOperation.of(b -> b.index(c -> c.id(p.getId()).document(p)))));
-        try {
-            BulkResponse bulkResponse = esClient.bulk(s -> s.index(indexName).operations(bulkOperations));
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        //bulkResponse.items().forEach(b -> log.info("bulk response result = {}", b.result()));
-        //log.error("bulk response.error() = {}", bulkResponse.errors());
-    }
-
-    public void updateVideoText(String index, VideoText videoText) throws IOException {
-        String id = videoText.getId();
-        IndexResponse response = esClient.index(i -> i.index(index).document(videoText).id(id));
-        Result result = response.result();
-        System.out.println(result.jsonValue());
-    }
-
-    public void deleteVideoText(String index, VideoText videoText) throws IOException {
-        String id = videoText.getId();
-        DeleteResponse deleteResponse = esClient.delete(s -> s.index(index).id(id));
-    }
 }

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

@@ -15,6 +15,8 @@ import org.elasticsearch.client.RestClient;
 import org.elasticsearch.client.RestClientBuilder;
 import org.springframework.stereotype.Service;
 
+import java.util.concurrent.TimeUnit;
+
 /**
  * @author reghao
  * @date 2025-03-12 10:41:52
@@ -40,11 +42,12 @@ public class ElasticService {
         final SSLContext sslContext = sslBuilder.build();*/
 
         HttpHost httpHost = new HttpHost(host, port);
-        //HttpHost httpHost = new HttpHost("192.168.0.212", 9200, "https");
         // 创建 low-level client
         RestClientBuilder builder = RestClient.builder(httpHost)
                 .setHttpClientConfigCallback(httpClientBuilder ->
                         httpClientBuilder
+                                // 超时 10 分钟
+                                .setConnectionTimeToLive(600, TimeUnit.SECONDS)
                                 .setDefaultCredentialsProvider(credentialsProvider))
                                 /*.setSSLContext(sslContext)
                                 .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE))*/;

+ 21 - 19
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/IndexService.java

@@ -31,15 +31,15 @@ public class IndexService {
         this.esClient = elasticService.getElasticsearchClient();
     }
 
-    public void createIndex(String index, Map<String, Property> propertyMap) throws IOException {
+    public void createIndex(String indexName, Map<String, Property> propertyMap) throws IOException {
         String type = "_doc";
         ExistsRequest existsRequest = new ExistsRequest.Builder()
-                .index(index)
+                .index(indexName)
                 .local(false)
                 .build();
         BooleanResponse exists = esClient.indices().exists(existsRequest);
         if(exists.value()) {
-            System.out.println("索引 " + index + " 已存在!");
+            log.info("索引 {} 已存在!", indexName);
             return;
         }
 
@@ -58,18 +58,18 @@ public class IndexService {
                 .properties(propertyMap)
                 .build();
         CreateIndexRequest createIndexRequest = new CreateIndexRequest.Builder()
-                .index(index)
+                .index(indexName)
                 .settings(indexSettings)
                 .mappings(typeMapping)
                 //.aliases("ngxlog", new Alias.Builder().isWriteIndex(true).build())
                 .build();
         CreateIndexResponse createIndexResponse = esClient.indices().create(createIndexRequest);
         if (createIndexResponse.acknowledged()) {
-            System.out.println("索引 " + index + " 创建成功!");
+            log.info("索引 {} 创建成功!", indexName);
         }
     }
 
-    public void updateMapping(String index) throws IOException {
+    public void updateMapping(String indexName) throws IOException {
         Map<String, Property> propertyMap = new HashMap<>();
         Property intProp = Property.of(builder -> builder.integer(IntegerNumberProperty.of(pro -> pro.index(true))));
         propertyMap.put("member", intProp);
@@ -80,38 +80,40 @@ public class IndexService {
         /*Property textProp = Property.of(builder -> builder.text(TextProperty.of(pro -> pro.index(true).analyzer("ik_max_word"))));
         propertyMap.put("requestUri", textProp);*/
 
-        PutMappingRequest putMappingRequest = PutMappingRequest.of(m -> m.index(index).properties(propertyMap));
+        PutMappingRequest putMappingRequest = PutMappingRequest.of(m -> m.index(indexName).properties(propertyMap));
         PutMappingResponse putMappingResponse = esClient.indices().putMapping(putMappingRequest);
         boolean acknowledged = putMappingResponse.acknowledged();
         log.info("update mappings ack: {}", acknowledged);
     }
 
-    public void deleteIndex(String index) throws IOException {
+    public void deleteIndex(String indexName) throws IOException {
         ExistsRequest existsRequest = new ExistsRequest.Builder()
-                .index(index)
+                .index(indexName)
                 .local(false)
                 .build();
         BooleanResponse exists = esClient.indices().exists(existsRequest);
         if(!exists.value()) {
-            System.out.println("索引 " + index + " 不存在!");
+            log.info("索引 {} 不存在!", indexName);
             return;
         }
 
-        DeleteIndexResponse response = esClient.indices().delete(i -> i.index(index));
-        System.out.println(response.acknowledged());
+        DeleteIndexResponse response = esClient.indices().delete(i -> i.index(indexName));
+        if (!response.acknowledged()) {
+
+        }
     }
 
-    public void getMapping(String index) throws IOException {
-        GetMappingRequest request = GetMappingRequest.of(builder -> builder.index(index));
+    public void getMapping(String indexName) throws IOException {
+        GetMappingRequest request = GetMappingRequest.of(builder -> builder.index(indexName));
         GetMappingResponse response = esClient.indices().getMapping(request);
         Map<String, IndexMappingRecord> result = response.result();
-        log.info("{} mapping message: {}", index, result);
+        log.info("{} mapping message: {}", indexName, result);
     }
 
-    public void getIndex(String index) throws IOException {
-        List<String> indexName = new ArrayList<>();
-        indexName.add(index);
-        GetIndexRequest request = GetIndexRequest.of(builder -> builder.index(indexName));
+    public void getIndex(String indexName) throws IOException {
+        List<String> indexNames = new ArrayList<>();
+        indexNames.add(indexName);
+        GetIndexRequest request = GetIndexRequest.of(builder -> builder.index(indexNames));
         GetIndexResponse getIndexResponse = esClient.indices().get(request);
         Map<String, IndexState> result = getIndexResponse.result();
         result.entrySet().forEach(entry -> {

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

@@ -1,5 +1,6 @@
 package cn.reghao.tnb.search.app.es;
 
+import cn.reghao.tnb.search.app.model.po.VideoText;
 import co.elastic.clients.elasticsearch._types.mapping.*;
 import org.springframework.stereotype.Service;
 
@@ -70,12 +71,13 @@ public class MappingService {
     }
 
     public Map<String, Property> getVideoTextPropertyMap() {
+        String className = VideoText.class.getSimpleName();
         Map<String, Property> propertyMap = new HashMap<>();
         propertyMap.put("id", keywordProp);
-        propertyMap.put("video", keywordProp);
         propertyMap.put("title", textPropIk);
         propertyMap.put("description", textPropIk);
         propertyMap.put("scope", intProp);
+        propertyMap.put("publishTime", longProp);
         return propertyMap;
     }
 }

+ 80 - 0
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/VideoTextDocument.java

@@ -0,0 +1,80 @@
+package cn.reghao.tnb.search.app.es;
+
+import cn.reghao.jutil.tool.id.SnowFlake;
+import cn.reghao.tnb.search.app.model.po.VideoText;
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
+import co.elastic.clients.elasticsearch._types.Result;
+import co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery;
+import co.elastic.clients.elasticsearch.core.*;
+import co.elastic.clients.elasticsearch.core.bulk.BulkOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author reghao
+ * @date 2025-03-12 10:45:58
+ */
+@Slf4j
+@Service
+public class VideoTextDocument {
+    private String indexName = "video_text";
+    private int pageSize = 12;
+    private final ElasticsearchClient esClient;
+    private final SnowFlake idGenerator;
+
+    public VideoTextDocument(ElasticService elasticService) {
+        this.esClient = elasticService.getElasticsearchClient();
+        this.idGenerator = new SnowFlake(1, 1);
+    }
+
+    public void addVideoText(VideoText videoText) throws IOException {
+        //videoText.setId(""+idGenerator.nextId());
+        IndexResponse indexResponse = esClient.index(i -> i.index(indexName).id(videoText.getId()).document(videoText));
+        String jsonResult = indexResponse.result().jsonValue();
+    }
+
+    public void batchAddVideoText(List<VideoText> videoTextList) {
+        videoTextList.forEach(videoText -> {
+            //videoText.setId(""+idGenerator.nextId());
+            //videoText.setId(videoText.getVideoId());
+        });
+
+        List<BulkOperation> bulkOperations = new ArrayList<>();
+        videoTextList.forEach(p -> bulkOperations.add(BulkOperation.of(b -> b.index(c -> c.id(p.getId()).document(p)))));
+        try {
+            BulkResponse bulkResponse = esClient.bulk(s -> s.index(indexName).operations(bulkOperations));
+            bulkResponse.items().forEach(b -> log.info("bulk response result = {}", b.result()));
+            log.error("bulk response.error() = {}", bulkResponse.errors());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void updateVideoText(VideoText videoText) throws IOException {
+        String id = videoText.getId();
+        IndexResponse response = esClient.index(i -> i.index(indexName).document(videoText).id(id));
+        Result result = response.result();
+        System.out.println(result.jsonValue());
+    }
+
+    public void deleteVideoText(VideoText videoText) throws IOException {
+        String id = videoText.getId();
+        DeleteResponse deleteResponse = esClient.delete(s -> s.index(indexName).id(id));
+    }
+
+    public void deleteAllDocument() {
+        try {
+            DeleteByQueryRequest deleteByQueryRequest = DeleteByQueryRequest.of(s -> s.index(indexName)
+                    .query(m -> m.matchAll(new MatchAllQuery.Builder().build()))
+            );
+            DeleteByQueryResponse deleteByQueryResponse = esClient.deleteByQuery(deleteByQueryRequest);
+            log.info("del doc result: {}", deleteByQueryResponse.total());
+        } catch (IOException e) {
+            log.error("del doc failed, error: ", e);
+        }
+    }
+}

+ 59 - 8
search/search-service/src/main/java/cn/reghao/tnb/search/app/es/VideoTextQuery.java

@@ -3,14 +3,15 @@ package cn.reghao.tnb.search.app.es;
 import cn.reghao.tnb.search.app.model.po.VideoText;
 import co.elastic.clients.elasticsearch.ElasticsearchClient;
 import co.elastic.clients.elasticsearch._types.FieldValue;
-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._types.SortOrder;
+import co.elastic.clients.elasticsearch._types.query_dsl.*;
 import co.elastic.clients.elasticsearch.core.SearchRequest;
 import co.elastic.clients.elasticsearch.core.SearchResponse;
 import co.elastic.clients.elasticsearch.core.search.Highlight;
 import co.elastic.clients.elasticsearch.core.search.HighlightField;
+import co.elastic.clients.elasticsearch.core.search.Hit;
 import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
+import co.elastic.clients.json.JsonData;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -30,14 +32,19 @@ import java.util.stream.Collectors;
 @Slf4j
 @Service
 public class VideoTextQuery {
-    private String indexName = "videotext";
+    private String indexName = "video_text";
+    private int pageSize = 12;
     private final ElasticsearchClient esClient;
 
     public VideoTextQuery(ElasticService elasticService) {
         this.esClient = elasticService.getElasticsearchClient();
     }
 
-    public Page<VideoText> queryWithHighlight(String keyword, List<Integer> scopes, int pn, int ps) {
+    public Page<VideoText> queryWithHighlight(String keyword, List<Integer> scopes, int pageNumber) {
+        if (pageNumber > 100) {
+            pageNumber = 100;
+        }
+
         String fieldName = "title";
         String fieldValue = keyword;
         QueryStringQuery stringQuery = new QueryStringQuery.Builder()
@@ -48,8 +55,11 @@ public class VideoTextQuery {
 
         BoolQuery.Builder builder = new BoolQuery.Builder();
         for (int scope : scopes) {
+            // filter 表示 list 中的值全部都要满足
+            //builder.filter(m -> m.term(t -> t.field("scope").value(FieldValue.of(scope))));
             builder.should(m -> m.term(t -> t.field("scope").value(FieldValue.of(scope))));
         }
+        builder.minimumShouldMatch("1");
         builder.must(m -> m.queryString(stringQuery));
         BoolQuery boolQuery = builder.build();
         Query query = new Query.Builder()
@@ -75,11 +85,11 @@ public class VideoTextQuery {
                 .build();
 
         // 3.搜索请求
-        int start = (pn-1)*ps;
+        int start = (pageNumber-1)*pageSize;
         SearchRequest searchRequest = new SearchRequest.Builder()
                 .index(indexName)
                 .from(start)
-                .size(ps)
+                .size(pageSize)
                 .query(query)
                 .highlight(highlight)
                 .build();
@@ -107,11 +117,52 @@ public class VideoTextQuery {
                 }
                 return mapper.source();
             }).collect(Collectors.toList());
-            return new PageImpl<>(list, PageRequest.of(pn-1, ps), total);
+
+            if (total > pageSize*100L) {
+                total = pageSize*100L;
+            }
+
+            return new PageImpl<>(list, PageRequest.of(pageNumber-1, pageSize), total);
         } catch (IOException e) {
             log.error("search By Query Highlight error: {}", e.getMessage());
         }
 
         return Page.empty();
     }
+
+    public List<VideoText> queryByPage(int pageNumber) {
+        String sortField = "publishTime";
+        Query query = RangeQuery.of(r -> r.field("age").gte(JsonData.of(8)))._toQuery();
+        String fieldName = "host";
+        String searchText = "api.iquizoo.com";
+        Query matchQuery = MatchQuery.of(m -> m.field(fieldName).query(searchText))._toQuery();
+        Query matchQuery1 = MatchQuery.of(m -> m.field(fieldName).query(searchText))._toQuery();
+
+        Query matchAllQuery = new Query.Builder()
+                .matchAll(new MatchAllQuery.Builder().build())
+                .build();
+
+        int start = (pageNumber-1)*pageSize;
+        SearchRequest searchRequest = SearchRequest.of(s -> s
+                .index(indexName)
+                .query(matchAllQuery)
+                .from(start)
+                .size(pageSize)
+                // 按指定字段降序排列
+                .sort(f -> f.field(o -> o.field(sortField).order(SortOrder.Desc)))
+        );
+
+        try {
+            SearchResponse<VideoText> searchResponse = esClient.search(searchRequest, VideoText.class);
+        /*List<Hit<NginxLog>> hits = searchResponse.hits().hits();
+        for (Hit<NginxLog> hit : hits) {
+            NginxLog product = hit.source();
+            log.info("search page result: {}", product);
+        }*/
+            return searchResponse.hits().hits().stream().map(Hit::source).collect(Collectors.toList());
+        } catch (Exception e) {
+            log.error("{}", e.getMessage());
+        }
+        return Collections.emptyList();
+    }
 }

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

@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
 @Service
 public class NginxLogSearch {
     private final ElasticsearchClient esClient;
-    private final String indexName = "NginxLog";
+    private final String indexName = "nginx_log";
 
     public NginxLogSearch(ElasticService elasticService) throws Exception {
         this.esClient = elasticService.getElasticsearchClient();

+ 1 - 1
search/search-service/src/main/java/cn/reghao/tnb/search/app/lucene/LuceneDocument.java

@@ -51,7 +51,7 @@ public class LuceneDocument {
     public Document getVideoTextDoc(VideoText videoText) {
         Document doc = new Document();
         doc.add(new StringField("id", videoText.getId(), org.apache.lucene.document.Field.Store.YES));
-        doc.add(new StringField("videoId", videoText.getVideoId(), org.apache.lucene.document.Field.Store.YES));
+        //doc.add(new StringField("videoId", videoText.getVideoId(), org.apache.lucene.document.Field.Store.YES));
         doc.add(new TextField("title", videoText.getTitle(), org.apache.lucene.document.Field.Store.YES));
         doc.add(new TextField("description", videoText.getDescription(), org.apache.lucene.document.Field.Store.NO));
         doc.add(new StringField("scope", ""+videoText.getScope(), org.apache.lucene.document.Field.Store.YES));

+ 2 - 1
search/search-service/src/main/java/cn/reghao/tnb/search/app/lucene/LuceneQuery.java

@@ -88,7 +88,8 @@ public class LuceneQuery {
                 String title = document.get("title");
                 String htmlTitle = highlighter.getBestFragment(luceneAnalyzer, field, title);
                 int scope = Integer.parseInt(document.get("scope"));
-                list.add(new VideoText(videoId, htmlTitle, scope));
+                long publishTime = Long.parseLong(document.get("publishTime"));
+                list.add(new VideoText(videoId, htmlTitle, scope, publishTime));
             }
 
             PageRequest pageRequest = PageRequest.of(pn-1, ps);

+ 7 - 4
search/search-service/src/main/java/cn/reghao/tnb/search/app/model/po/VideoText.java

@@ -13,23 +13,26 @@ import lombok.Setter;
 @Setter
 @Getter
 public class VideoText {
+    // videoId
     private String id;
-    private String videoId;
     private String title;
     private String description;
     private Integer scope;
+    private Long publishTime;
 
     public VideoText(VideoSummary videoSummary) {
-        this.videoId = videoSummary.getVideoId();
+        this.id = videoSummary.getVideoId();
         this.title = videoSummary.getTitle();
         this.description = videoSummary.getDescription();
         this.scope = videoSummary.getScope();
+        this.publishTime = videoSummary.getPublishTime();
     }
 
-    public VideoText(String videoId, String title, int scope) {
-        this.videoId = videoId;
+    public VideoText(String videoId, String title, int scope, long publishTime) {
+        this.id = videoId;
         this.title = title;
         this.description = title;
         this.scope = scope;
+        this.publishTime = publishTime;
     }
 }

+ 14 - 15
search/search-service/src/main/java/cn/reghao/tnb/search/app/rpc/DataSearchServiceImpl.java

@@ -2,8 +2,8 @@ package cn.reghao.tnb.search.app.rpc;
 
 import cn.reghao.tnb.search.api.dto.VideoSummary;
 import cn.reghao.tnb.search.api.iface.DataSearchService;
-import cn.reghao.tnb.search.app.es.DocumentService;
 import cn.reghao.tnb.search.app.es.ElasticService;
+import cn.reghao.tnb.search.app.es.VideoTextDocument;
 import cn.reghao.tnb.search.app.es.VideoTextQuery;
 import cn.reghao.tnb.search.app.lucene.LuceneIndex;
 import cn.reghao.tnb.search.app.lucene.LuceneQuery;
@@ -32,14 +32,14 @@ import java.util.stream.Collectors;
 @Service
 public class DataSearchServiceImpl implements DataSearchService {
     private final String indexName = VideoText.class.getSimpleName().toLowerCase(Locale.ROOT);
-    private int ps = 12;
-    private final DocumentService documentService;
+    private int pageSize = 12;
+    private final VideoTextDocument videoTextDocument;
     private final LuceneIndex luceneIndex;
     private final VideoTextQuery videoTextQuery;
 
     public DataSearchServiceImpl(ElasticService elasticService, LuceneQuery luceneQuery,
                                  LuceneIndex luceneIndex, VideoTextQuery videoTextQuery) {
-        this.documentService = new DocumentService(elasticService);
+        this.videoTextDocument = new VideoTextDocument(elasticService);
         this.luceneIndex = luceneIndex;
         this.videoTextQuery = videoTextQuery;
     }
@@ -48,11 +48,8 @@ public class DataSearchServiceImpl implements DataSearchService {
         int type = 1;
         try {
             VideoText videoText = new VideoText(videoSummary);
-            if (type == 1) {
-                documentService.addVideoText(indexName, videoText);
-            } else{
-                luceneIndex.createVideoTextIndex(videoText);
-            }
+            videoTextDocument.addVideoText(videoText);
+            //luceneIndex.createVideoTextIndex(videoText);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -62,7 +59,7 @@ public class DataSearchServiceImpl implements DataSearchService {
         List<VideoText> videoTextList = list.stream()
                 .map(VideoText::new)
                 .collect(Collectors.toList());
-        documentService.batchAddText(indexName, videoTextList);
+        videoTextDocument.batchAddVideoText(videoTextList);
     }
 
     @Override
@@ -74,16 +71,18 @@ public class DataSearchServiceImpl implements DataSearchService {
     }
 
     @Override
-    public PageList<VideoSummary> searchVideo(String keyword, List<Integer> scopes, int pn) {
-        Page<VideoText> page = videoTextQuery.queryWithHighlight(keyword, scopes, pn, ps);
+    public PageList<VideoSummary> searchVideo(String keyword, List<Integer> scopes, int pageNumber) {
+        Page<VideoText> page = videoTextQuery.queryWithHighlight(keyword, scopes, pageNumber);
+        int pageSize = page.getSize();
         List<VideoSummary> list = page.stream().map(videoText -> {
-            String videoId = videoText.getVideoId();
+            String videoId = videoText.getId();
             String title = videoText.getTitle();
             String description = videoText.getDescription();
             int scope = videoText.getScope();
-            return new VideoSummary(videoId, title, description, scope);
+            long publishTime = videoText.getPublishTime();
+            return new VideoSummary(videoId, title, description, scope, publishTime);
         }).collect(Collectors.toList());
-        return PageList.pageList(pn, ps, (int) page.getTotalElements(), list);
+        return PageList.pageList(pageNumber, pageSize, (int) page.getTotalElements(), list);
     }
 
     /**

+ 17 - 9
search/search-service/src/test/java/SearchTest.java

@@ -107,10 +107,20 @@ public class SearchTest {
         }
     }
 
+    @Test
     public void indexTest() throws IOException {
-        Map<String, Property> propertyMap = mappingService.getWenshuPropertyMap();
-        indexService.deleteIndex(index);
-        indexService.createIndex(index, propertyMap);
+        String indexName = "video_text";
+
+        indexService.deleteIndex(indexName);
+        Map<String, Property> propertyMap = mappingService.getVideoTextPropertyMap();
+        indexService.createIndex(indexName, propertyMap);
+    }
+
+    @Autowired
+    VideoTextDocument videoTextDocument;
+    @Test
+    public void documentTest() {
+        videoTextDocument.deleteAllDocument();
     }
 
     void setLogLevel() {
@@ -260,15 +270,16 @@ public class SearchTest {
     VideoTextQuery videoTextQuery;
     @Test
     public void searchTest() {
-        int pn = 1;
-        int ps = 1000;
+        int pageNumber = 1;
         String keyword = "大奶";
 
         List<Integer> scopes = List.of(PostScope.PUBLIC.getCode(), PostScope.PROTECT.getCode());
-        Page<VideoText> page = videoTextQuery.queryWithHighlight(keyword, scopes, pn, ps);
+        Page<VideoText> page = videoTextQuery.queryWithHighlight(keyword, scopes, pageNumber);
         //Page<VideoText> page1 = esQuery.queryByPage(index, "query", pn, ps, VideoText.class);
         long total = page.getTotalElements();
         List<VideoText> list = page.getContent();
+
+        List<VideoText> list1 = videoTextQuery.queryByPage(pageNumber);
         System.out.println();
     }
 
@@ -285,8 +296,5 @@ public class SearchTest {
         /*ElasticsearchClient esClient = elasticService.getElasticsearchClient();
         AnalyzeResponse analyzeResponse = esClient.indices().analyze(analyzeRequest);
         List<AnalyzeToken> tokens = analyzeResponse.tokens();*/
-
-        String index = "videotext";
-        documentService.deleteAllDocument(index);
     }
 }