Authored by 张帅

update

... ... @@ -6,6 +6,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@RestController
public class UserInfoController {
... ... @@ -16,12 +19,16 @@ public class UserInfoController {
@RequestMapping("/syncUserInfoToES")
public String syncArticle(@RequestParam("uid") Integer uid, @RequestParam("flag") Integer flag,@RequestParam("size") Integer size,
@RequestParam("pageSize") Integer pageSize){
return userInfoDataSyncService.sync(uid, flag,size, pageSize);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.submit(() -> {
userInfoDataSyncService.sync(uid, flag,size, pageSize);
});
executorService.shutdown();
return "success";
}
@RequestMapping("/search")
public String search(){
return userInfoDataSyncService.searchAllUserData();
public String search(@RequestParam("keyword") String keyword){
return userInfoDataSyncService.searchAllUserData(keyword);
}
}
... ...
package com.yoho.datasync.fullsync.service.impl;
import org.elasticsearch.script.Script;
import org.elasticsearch.tasks.TaskId;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import com.alibaba.fastjson.JSON;
... ... @@ -6,12 +9,15 @@ import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import com.yoho.datasync.fullsync.dal.repository.yhcommunity.model.UserInfo;
... ... @@ -77,7 +83,7 @@ public class UserInfoDataSyncServiceImpl {
result = String.valueOf(userInfoList.get(userInfoList.size()-1).getYoho_uid());
}
}
logger.info("sync userInfo success, result uid is {}", result);
return result;
}
... ... @@ -123,10 +129,14 @@ public class UserInfoDataSyncServiceImpl {
}
}
public String searchAllUserData(){
public String searchAllUserData(String keyword){
try {
BoolQueryBuilder queryBuilder = new BoolQueryBuilder();
queryBuilder.must(QueryBuilders.matchAllQuery());
// queryBuilder.must(QueryBuilders.matchAllQuery());
queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword",keyword).boost(3));
queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword",keyword+"*").boost(2));
queryBuilder.should(QueryBuilders.wildcardQuery("nick_name.keyword","*"+keyword+"*").boost(1));
queryBuilder.should(QueryBuilders.wildcardQuery("nick_name","*"+keyword+"*").boost(1));
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(queryBuilder);
... ... @@ -138,7 +148,7 @@ public class UserInfoDataSyncServiceImpl {
SearchResponse response = rhlClient.search(searchRequest, RequestOptions.DEFAULT);
logger.info("searchAllUserData: {}" , JSON.toJSONString(response));
return JSON.toJSONString(response.getHits().totalHits);
return JSON.toJSONString(response.getHits().getHits());
} catch (IOException e) {
e.printStackTrace();
}
... ...