Authored by all4you

update

... ... @@ -9,6 +9,8 @@ import com.yohomars.search.es.IElasticsearchClient;
import com.yohomars.search.index.model.ESBluk;
import com.yohomars.search.utils.JsonUtil;
import com.yohomars.search.utils.SearchParamUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.ActionResponse;
... ... @@ -603,6 +605,9 @@ public class ElasticsearchClientImpl implements IElasticsearchClient {
List<Map<String, Object>> resultList = new ArrayList<>();
for (SearchHit outHit : hits.getHits()) {
Map<String, Object> map;
if(MapUtils.isEmpty(outHit.getInnerHits())){
continue;
}
// 获取innerHits的结果
SearchHits innerHits = outHit.getInnerHits().get(searchParam.getNestedPath());
if(total==0L){
... ...
... ... @@ -3,8 +3,7 @@ package com.yohomars.search.model;
import com.yoho.tools.common.beans.BaseBean;
import org.apache.commons.collections.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
/**
* @author gris.wang
... ... @@ -16,7 +15,7 @@ public class SocialUserResponse extends BaseBean {
private Integer page;
private List<User> users;
private Set<User> users;
public Integer getRule() {
return rule;
... ... @@ -34,17 +33,17 @@ public class SocialUserResponse extends BaseBean {
this.page = page;
}
public List<User> getUsers() {
public Set<User> getUsers() {
return users;
}
public void setUsers(List<User> users) {
public void setUsers(Set<User> users) {
this.users = users;
}
public void addUsers(List<User> users){
public void addUsers(Collection<User> users){
if(CollectionUtils.isEmpty(this.users)){
this.users = new ArrayList<>();
this.users = new HashSet<>();
}
this.users.addAll(users);
}
... ... @@ -79,5 +78,28 @@ public class SocialUserResponse extends BaseBean {
public void setHeadPic(String headPic) {
this.headPic = headPic;
}
@Override
public boolean equals(Object obj) {
if(!(obj instanceof User)){
return false;
}
if(obj == this){
return true;
}
User that = (User)obj;
return that.getUid().equals(this.getUid())
&& that.getNickName().equals(this.getNickName())
&& that.getHeadPic().equals(this.getHeadPic());
}
@Override
public int hashCode() {
int hash = 17;
hash = hash * 31 + getNickName().hashCode();
hash = hash * 31 + getHeadPic().hashCode();
hash = hash * 31 + getUid();
return hash;
}
}
}
... ...
... ... @@ -4,6 +4,8 @@ import com.yoho.tools.common.beans.ApiResponse;
import com.yohomars.search.model.SocialUserRequest;
import com.yohomars.search.model.SocialUserResponse;
import com.yohomars.search.service.SocialUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
... ... @@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class SocialUserController extends BaseController{
private static final Logger LOGGER = LoggerFactory.getLogger(SocialUserController.class);
@Autowired
private SocialUserService socialUserService;
... ... @@ -32,6 +35,7 @@ public class SocialUserController extends BaseController{
SocialUserResponse response = socialUserService.search(request);
return new ApiResponse<>(200,"搜索用户列表",response);
} catch (Exception e) {
LOGGER.error("search socialUser error,cause:",e);
return new ApiResponse(400, e.getMessage());
}
}
... ...
... ... @@ -171,8 +171,8 @@ public class SocialUserService extends BaseService {
return searchResult;
}
private List<SocialUserResponse.User> transfer(int rule, List<Map<String, Object>> resultList){
List<SocialUserResponse.User> userList = new ArrayList<>();
private Set<SocialUserResponse.User> transfer(int rule, List<Map<String, Object>> resultList){
Set<SocialUserResponse.User> userSet = new HashSet<>();
LOGGER.debug("rule={},resultList={}",rule,resultList);
switch (rule){
case RULE_MATCH_EQUALLY:
... ... @@ -186,7 +186,7 @@ public class SocialUserService extends BaseService {
user.setNickName(nickName==null?null:nickName.toString());
Object headPic = map.get(ISearchConstans.SOCIAL_USER_S_HEAD_PIC);
user.setHeadPic(headPic==null?null:headPic.toString());
userList.add(user);
userSet.add(user);
}
}
}break;
... ... @@ -199,14 +199,14 @@ public class SocialUserService extends BaseService {
user.setNickName(nickName==null?null:nickName.toString());
Object headPic = map.get(ISearchConstans.SOCIAL_USER_T_HEAD_PIC);
user.setHeadPic(headPic==null?null:headPic.toString());
userList.add(user);
userSet.add(user);
}
}
}break;
default:
break;
}
return userList;
return userSet;
}
private boolean hasMoreData(SearchResult searchResult){
... ... @@ -267,6 +267,7 @@ public class SocialUserService extends BaseService {
calculated = true;
break;
}
searchParam = new SearchParam();
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
... ...