Authored by all4you

update

@@ -9,6 +9,8 @@ import com.yohomars.search.es.IElasticsearchClient; @@ -9,6 +9,8 @@ import com.yohomars.search.es.IElasticsearchClient;
9 import com.yohomars.search.index.model.ESBluk; 9 import com.yohomars.search.index.model.ESBluk;
10 import com.yohomars.search.utils.JsonUtil; 10 import com.yohomars.search.utils.JsonUtil;
11 import com.yohomars.search.utils.SearchParamUtils; 11 import com.yohomars.search.utils.SearchParamUtils;
  12 +import org.apache.commons.collections.CollectionUtils;
  13 +import org.apache.commons.collections.MapUtils;
12 import org.apache.commons.lang.StringUtils; 14 import org.apache.commons.lang.StringUtils;
13 import org.elasticsearch.action.ActionFuture; 15 import org.elasticsearch.action.ActionFuture;
14 import org.elasticsearch.action.ActionResponse; 16 import org.elasticsearch.action.ActionResponse;
@@ -603,6 +605,9 @@ public class ElasticsearchClientImpl implements IElasticsearchClient { @@ -603,6 +605,9 @@ public class ElasticsearchClientImpl implements IElasticsearchClient {
603 List<Map<String, Object>> resultList = new ArrayList<>(); 605 List<Map<String, Object>> resultList = new ArrayList<>();
604 for (SearchHit outHit : hits.getHits()) { 606 for (SearchHit outHit : hits.getHits()) {
605 Map<String, Object> map; 607 Map<String, Object> map;
  608 + if(MapUtils.isEmpty(outHit.getInnerHits())){
  609 + continue;
  610 + }
606 // 获取innerHits的结果 611 // 获取innerHits的结果
607 SearchHits innerHits = outHit.getInnerHits().get(searchParam.getNestedPath()); 612 SearchHits innerHits = outHit.getInnerHits().get(searchParam.getNestedPath());
608 if(total==0L){ 613 if(total==0L){
@@ -3,8 +3,7 @@ package com.yohomars.search.model; @@ -3,8 +3,7 @@ package com.yohomars.search.model;
3 import com.yoho.tools.common.beans.BaseBean; 3 import com.yoho.tools.common.beans.BaseBean;
4 import org.apache.commons.collections.CollectionUtils; 4 import org.apache.commons.collections.CollectionUtils;
5 5
6 -import java.util.ArrayList;  
7 -import java.util.List; 6 +import java.util.*;
8 7
9 /** 8 /**
10 * @author gris.wang 9 * @author gris.wang
@@ -16,7 +15,7 @@ public class SocialUserResponse extends BaseBean { @@ -16,7 +15,7 @@ public class SocialUserResponse extends BaseBean {
16 15
17 private Integer page; 16 private Integer page;
18 17
19 - private List<User> users; 18 + private Set<User> users;
20 19
21 public Integer getRule() { 20 public Integer getRule() {
22 return rule; 21 return rule;
@@ -34,17 +33,17 @@ public class SocialUserResponse extends BaseBean { @@ -34,17 +33,17 @@ public class SocialUserResponse extends BaseBean {
34 this.page = page; 33 this.page = page;
35 } 34 }
36 35
37 - public List<User> getUsers() { 36 + public Set<User> getUsers() {
38 return users; 37 return users;
39 } 38 }
40 39
41 - public void setUsers(List<User> users) { 40 + public void setUsers(Set<User> users) {
42 this.users = users; 41 this.users = users;
43 } 42 }
44 43
45 - public void addUsers(List<User> users){ 44 + public void addUsers(Collection<User> users){
46 if(CollectionUtils.isEmpty(this.users)){ 45 if(CollectionUtils.isEmpty(this.users)){
47 - this.users = new ArrayList<>(); 46 + this.users = new HashSet<>();
48 } 47 }
49 this.users.addAll(users); 48 this.users.addAll(users);
50 } 49 }
@@ -79,5 +78,28 @@ public class SocialUserResponse extends BaseBean { @@ -79,5 +78,28 @@ public class SocialUserResponse extends BaseBean {
79 public void setHeadPic(String headPic) { 78 public void setHeadPic(String headPic) {
80 this.headPic = headPic; 79 this.headPic = headPic;
81 } 80 }
  81 +
  82 + @Override
  83 + public boolean equals(Object obj) {
  84 + if(!(obj instanceof User)){
  85 + return false;
  86 + }
  87 + if(obj == this){
  88 + return true;
  89 + }
  90 + User that = (User)obj;
  91 + return that.getUid().equals(this.getUid())
  92 + && that.getNickName().equals(this.getNickName())
  93 + && that.getHeadPic().equals(this.getHeadPic());
  94 + }
  95 +
  96 + @Override
  97 + public int hashCode() {
  98 + int hash = 17;
  99 + hash = hash * 31 + getNickName().hashCode();
  100 + hash = hash * 31 + getHeadPic().hashCode();
  101 + hash = hash * 31 + getUid();
  102 + return hash;
  103 + }
82 } 104 }
83 } 105 }
@@ -4,6 +4,8 @@ import com.yoho.tools.common.beans.ApiResponse; @@ -4,6 +4,8 @@ import com.yoho.tools.common.beans.ApiResponse;
4 import com.yohomars.search.model.SocialUserRequest; 4 import com.yohomars.search.model.SocialUserRequest;
5 import com.yohomars.search.model.SocialUserResponse; 5 import com.yohomars.search.model.SocialUserResponse;
6 import com.yohomars.search.service.SocialUserService; 6 import com.yohomars.search.service.SocialUserService;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
7 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
8 import org.springframework.stereotype.Controller; 10 import org.springframework.stereotype.Controller;
9 import org.springframework.web.bind.annotation.RequestMapping; 11 import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.ResponseBody; @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
16 @Controller 18 @Controller
17 public class SocialUserController extends BaseController{ 19 public class SocialUserController extends BaseController{
18 20
  21 + private static final Logger LOGGER = LoggerFactory.getLogger(SocialUserController.class);
19 22
20 @Autowired 23 @Autowired
21 private SocialUserService socialUserService; 24 private SocialUserService socialUserService;
@@ -32,6 +35,7 @@ public class SocialUserController extends BaseController{ @@ -32,6 +35,7 @@ public class SocialUserController extends BaseController{
32 SocialUserResponse response = socialUserService.search(request); 35 SocialUserResponse response = socialUserService.search(request);
33 return new ApiResponse<>(200,"搜索用户列表",response); 36 return new ApiResponse<>(200,"搜索用户列表",response);
34 } catch (Exception e) { 37 } catch (Exception e) {
  38 + LOGGER.error("search socialUser error,cause:",e);
35 return new ApiResponse(400, e.getMessage()); 39 return new ApiResponse(400, e.getMessage());
36 } 40 }
37 } 41 }
@@ -171,8 +171,8 @@ public class SocialUserService extends BaseService { @@ -171,8 +171,8 @@ public class SocialUserService extends BaseService {
171 return searchResult; 171 return searchResult;
172 } 172 }
173 173
174 - private List<SocialUserResponse.User> transfer(int rule, List<Map<String, Object>> resultList){  
175 - List<SocialUserResponse.User> userList = new ArrayList<>(); 174 + private Set<SocialUserResponse.User> transfer(int rule, List<Map<String, Object>> resultList){
  175 + Set<SocialUserResponse.User> userSet = new HashSet<>();
176 LOGGER.debug("rule={},resultList={}",rule,resultList); 176 LOGGER.debug("rule={},resultList={}",rule,resultList);
177 switch (rule){ 177 switch (rule){
178 case RULE_MATCH_EQUALLY: 178 case RULE_MATCH_EQUALLY:
@@ -186,7 +186,7 @@ public class SocialUserService extends BaseService { @@ -186,7 +186,7 @@ public class SocialUserService extends BaseService {
186 user.setNickName(nickName==null?null:nickName.toString()); 186 user.setNickName(nickName==null?null:nickName.toString());
187 Object headPic = map.get(ISearchConstans.SOCIAL_USER_S_HEAD_PIC); 187 Object headPic = map.get(ISearchConstans.SOCIAL_USER_S_HEAD_PIC);
188 user.setHeadPic(headPic==null?null:headPic.toString()); 188 user.setHeadPic(headPic==null?null:headPic.toString());
189 - userList.add(user); 189 + userSet.add(user);
190 } 190 }
191 } 191 }
192 }break; 192 }break;
@@ -199,14 +199,14 @@ public class SocialUserService extends BaseService { @@ -199,14 +199,14 @@ public class SocialUserService extends BaseService {
199 user.setNickName(nickName==null?null:nickName.toString()); 199 user.setNickName(nickName==null?null:nickName.toString());
200 Object headPic = map.get(ISearchConstans.SOCIAL_USER_T_HEAD_PIC); 200 Object headPic = map.get(ISearchConstans.SOCIAL_USER_T_HEAD_PIC);
201 user.setHeadPic(headPic==null?null:headPic.toString()); 201 user.setHeadPic(headPic==null?null:headPic.toString());
202 - userList.add(user); 202 + userSet.add(user);
203 } 203 }
204 } 204 }
205 }break; 205 }break;
206 default: 206 default:
207 break; 207 break;
208 } 208 }
209 - return userList; 209 + return userSet;
210 } 210 }
211 211
212 private boolean hasMoreData(SearchResult searchResult){ 212 private boolean hasMoreData(SearchResult searchResult){
@@ -267,6 +267,7 @@ public class SocialUserService extends BaseService { @@ -267,6 +267,7 @@ public class SocialUserService extends BaseService {
267 calculated = true; 267 calculated = true;
268 break; 268 break;
269 } 269 }
  270 + searchParam = new SearchParam();
270 searchParam.setPage(page); 271 searchParam.setPage(page);
271 searchParam.setOffset((page - 1) * pageSize); 272 searchParam.setOffset((page - 1) * pageSize);
272 searchParam.setSize(pageSize); 273 searchParam.setSize(pageSize);