Authored by 张帅

update

@@ -6,6 +6,9 @@ import org.springframework.web.bind.annotation.RequestMapping; @@ -6,6 +6,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
6 import org.springframework.web.bind.annotation.RequestParam; 6 import org.springframework.web.bind.annotation.RequestParam;
7 import org.springframework.web.bind.annotation.RestController; 7 import org.springframework.web.bind.annotation.RestController;
8 8
  9 +import java.util.concurrent.ExecutorService;
  10 +import java.util.concurrent.Executors;
  11 +
9 12
10 @RestController 13 @RestController
11 public class UserInfoController { 14 public class UserInfoController {
@@ -16,12 +19,16 @@ public class UserInfoController { @@ -16,12 +19,16 @@ public class UserInfoController {
16 @RequestMapping("/syncUserInfoToES") 19 @RequestMapping("/syncUserInfoToES")
17 public String syncArticle(@RequestParam("uid") Integer uid, @RequestParam("flag") Integer flag,@RequestParam("size") Integer size, 20 public String syncArticle(@RequestParam("uid") Integer uid, @RequestParam("flag") Integer flag,@RequestParam("size") Integer size,
18 @RequestParam("pageSize") Integer pageSize){ 21 @RequestParam("pageSize") Integer pageSize){
19 -  
20 - return userInfoDataSyncService.sync(uid, flag,size, pageSize); 22 + ExecutorService executorService = Executors.newSingleThreadExecutor();
  23 + executorService.submit(() -> {
  24 + userInfoDataSyncService.sync(uid, flag,size, pageSize);
  25 + });
  26 + executorService.shutdown();
  27 + return "success";
21 } 28 }
22 29
23 @RequestMapping("/search") 30 @RequestMapping("/search")
24 - public String search(){  
25 - return userInfoDataSyncService.searchAllUserData(); 31 + public String search(@RequestParam("keyword") String keyword){
  32 + return userInfoDataSyncService.searchAllUserData(keyword);
26 } 33 }
27 } 34 }
1 package com.yoho.datasync.fullsync.service.impl; 1 package com.yoho.datasync.fullsync.service.impl;
  2 +import org.elasticsearch.script.Script;
  3 +import org.elasticsearch.tasks.TaskId;
  4 +import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
2 5
3 6
4 import com.alibaba.fastjson.JSON; 7 import com.alibaba.fastjson.JSON;
@@ -6,12 +9,15 @@ import org.elasticsearch.action.delete.DeleteRequest; @@ -6,12 +9,15 @@ import org.elasticsearch.action.delete.DeleteRequest;
6 import org.elasticsearch.action.delete.DeleteResponse; 9 import org.elasticsearch.action.delete.DeleteResponse;
7 import org.elasticsearch.action.search.SearchRequest; 10 import org.elasticsearch.action.search.SearchRequest;
8 import org.elasticsearch.action.search.SearchResponse; 11 import org.elasticsearch.action.search.SearchResponse;
  12 +import org.elasticsearch.action.update.UpdateRequest;
9 import org.elasticsearch.index.query.BoolQueryBuilder; 13 import org.elasticsearch.index.query.BoolQueryBuilder;
10 import org.elasticsearch.index.query.QueryBuilder; 14 import org.elasticsearch.index.query.QueryBuilder;
11 import org.elasticsearch.index.query.QueryBuilders; 15 import org.elasticsearch.index.query.QueryBuilders;
12 import org.elasticsearch.index.reindex.BulkByScrollResponse; 16 import org.elasticsearch.index.reindex.BulkByScrollResponse;
13 import org.elasticsearch.index.reindex.DeleteByQueryRequest; 17 import org.elasticsearch.index.reindex.DeleteByQueryRequest;
14 import org.elasticsearch.search.builder.SearchSourceBuilder; 18 import org.elasticsearch.search.builder.SearchSourceBuilder;
  19 +import org.elasticsearch.search.sort.SortBuilders;
  20 +import org.elasticsearch.search.sort.SortOrder;
15 import org.springframework.data.domain.PageRequest; 21 import org.springframework.data.domain.PageRequest;
16 import org.springframework.data.domain.Pageable; 22 import org.springframework.data.domain.Pageable;
17 import com.yoho.datasync.fullsync.dal.repository.yhcommunity.model.UserInfo; 23 import com.yoho.datasync.fullsync.dal.repository.yhcommunity.model.UserInfo;
@@ -77,7 +83,7 @@ public class UserInfoDataSyncServiceImpl { @@ -77,7 +83,7 @@ public class UserInfoDataSyncServiceImpl {
77 result = String.valueOf(userInfoList.get(userInfoList.size()-1).getYoho_uid()); 83 result = String.valueOf(userInfoList.get(userInfoList.size()-1).getYoho_uid());
78 } 84 }
79 } 85 }
80 - 86 + logger.info("sync userInfo success, result uid is {}", result);
81 return result; 87 return result;
82 } 88 }
83 89
@@ -123,10 +129,14 @@ public class UserInfoDataSyncServiceImpl { @@ -123,10 +129,14 @@ public class UserInfoDataSyncServiceImpl {
123 } 129 }
124 } 130 }
125 131
126 - public String searchAllUserData(){ 132 + public String searchAllUserData(String keyword){
127 try { 133 try {
128 BoolQueryBuilder queryBuilder = new BoolQueryBuilder(); 134 BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
129 - queryBuilder.must(QueryBuilders.matchAllQuery()); 135 +// queryBuilder.must(QueryBuilders.matchAllQuery());
  136 + queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword",keyword).boost(3));
  137 + queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword",keyword+"*").boost(2));
  138 + queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword","*"+keyword+"*").boost(1));
  139 + queryBuilder.should(QueryBuilders.wildcardQuery("nick_name","*"+keyword+"*").boost(1));
130 140
131 SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); 141 SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
132 sourceBuilder.query(queryBuilder); 142 sourceBuilder.query(queryBuilder);
@@ -138,7 +148,7 @@ public class UserInfoDataSyncServiceImpl { @@ -138,7 +148,7 @@ public class UserInfoDataSyncServiceImpl {
138 148
139 SearchResponse response = rhlClient.search(searchRequest, RequestOptions.DEFAULT); 149 SearchResponse response = rhlClient.search(searchRequest, RequestOptions.DEFAULT);
140 logger.info("searchAllUserData: {}" , JSON.toJSONString(response)); 150 logger.info("searchAllUserData: {}" , JSON.toJSONString(response));
141 - return JSON.toJSONString(response.getHits().totalHits); 151 + return JSON.toJSONString(response.getHits().getHits());
142 } catch (IOException e) { 152 } catch (IOException e) {
143 e.printStackTrace(); 153 e.printStackTrace();
144 } 154 }