...
|
...
|
@@ -3,7 +3,6 @@ package com.yoho.search.service.service; |
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -18,10 +17,8 @@ import org.springframework.context.ApplicationEventPublisher; |
|
|
import org.springframework.context.ApplicationEventPublisherAware;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.yoho.error.event.SearchEvent;
|
|
|
import com.yoho.search.base.utils.EventReportEnum;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.core.es.IElasticsearchClient;
|
|
|
import com.yoho.search.core.es.impl.YohoIndexHelper;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
...
|
...
|
@@ -160,84 +157,5 @@ public class SearchCommonService implements ApplicationEventPublisherAware { |
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过id获取内容
|
|
|
*
|
|
|
* @param indexName
|
|
|
* @param idList
|
|
|
* @param fields
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray doMultiGet(final String indexName, final String[] idList, final List<String> fields) {
|
|
|
try {
|
|
|
JSONArray list = new JSONArray();
|
|
|
if (idList == null || idList.length == 0) {
|
|
|
return list;
|
|
|
}
|
|
|
Set<String> idSet = new HashSet<String>();
|
|
|
for (String id : idList) {
|
|
|
idSet.add(id);
|
|
|
}
|
|
|
return this.doMultiGet(indexName, idSet, fields);
|
|
|
} catch (Exception e) {
|
|
|
return new JSONArray();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 通过id获取内容
|
|
|
*
|
|
|
* @param indexName
|
|
|
* @param fields
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONArray doMultiGet(final String indexName, final Set<String> idSet, final List<String> fields) throws Exception {
|
|
|
JSONArray result = new JSONArray();
|
|
|
if (idSet == null || idSet.size() == 0) {
|
|
|
return result;
|
|
|
}
|
|
|
IElasticsearchClient client = esClientMgr.getClient(indexName);
|
|
|
List<String> realIndexNames = yohoIndexHelper.getRealIndexNames(indexName, client);
|
|
|
if (realIndexNames == null || realIndexNames.isEmpty()) {
|
|
|
return null;
|
|
|
}
|
|
|
MultiGetResponse response = client.multiGet(realIndexNames.get(0), indexName, idSet, fields);
|
|
|
return makeResponse(response, indexName);
|
|
|
}
|
|
|
|
|
|
private JSONArray makeResponse(final MultiGetResponse response, final String indexName) {
|
|
|
// 构造返回结果
|
|
|
JSONArray list = new JSONArray();
|
|
|
Map<String, Object> tmpMap;
|
|
|
if (indexName.equals(ISearchConstants.INDEX_NAME_SHOPS)) {
|
|
|
for (MultiGetItemResponse item : response.getResponses()) {
|
|
|
if (item.getResponse().isExists()) {
|
|
|
tmpMap = item.getResponse().getSource();
|
|
|
list.add(getShopMap(tmpMap));
|
|
|
}
|
|
|
}
|
|
|
}else {
|
|
|
for (MultiGetItemResponse item : response.getResponses()) {
|
|
|
if (item.getResponse().isExists()) {
|
|
|
tmpMap = item.getResponse().getSource();
|
|
|
list.add(tmpMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> getShopMap(Map<String, Object> esMap) {
|
|
|
Map<String, Object> map = new HashMap<String, Object>();
|
|
|
map.put("shop_id", esMap.get("shopsId"));
|
|
|
map.put("shop_domain", esMap.get("shopDomain"));
|
|
|
map.put("shop_type", esMap.get("shopsType"));
|
|
|
map.put("shop_name", esMap.get("shopName"));
|
|
|
map.put("shop_logo", esMap.get("shopLogo"));
|
|
|
map.put("decorator_template_type", esMap.get("decoratorTemplateType"));
|
|
|
map.put("status", esMap.get("status"));
|
|
|
map.put("blk_status", esMap.get("blkStatus"));
|
|
|
map.put("check_status", esMap.get("checkStatus"));
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|