Authored by hugufei

fuzzy接口shopList节点处理方式修改

... ... @@ -16,6 +16,7 @@ import com.yoho.search.service.scene.pages.selections.PageSelectionsBrandsServic
import com.yoho.search.service.scene.pages.selections.PageSelectionsService;
import com.yoho.search.service.scene.shopbrand.ShopListService;
import com.yoho.search.service.scene.suggest.RecommendWordsService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -131,36 +132,44 @@ public class FuzzySceneService extends AbstractPageSceneService {
return newMap;
}
/**
* 处理shopList节点
* @param shops
* @param dataMap
* @param paramMap
*/
private void shopList(SearchApiResult shops, JSONObject dataMap, Map<String, String> paramMap) {
dataMap.put("shop_list", Collections.emptyList());
dataMap.put("shop_list_page", Collections.emptyList());
List<JSONObject> firstShop = new ArrayList<>();
List<JSONObject> otherShops = new ArrayList<>();
if (shops != null) {
JSONObject jsonObject = (JSONObject) shops.getData();
if (jsonObject != null) {
JSONArray jsonArray = jsonObject.getJSONArray("shop_list");
if (!CollectionUtils.isEmpty(jsonArray)) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject subJsonObject = jsonArray.getJSONObject(i);
if (subJsonObject != null) {
if (i == 0) {
firstShop.add(subJsonObject);
} else {
otherShops.add(subJsonObject);
}
}
}
}
if (shops == null) {
return;
}
JSONObject jsonObject = (JSONObject) shops.getData();
if (jsonObject == null) {
return;
}
JSONArray jsonArray = jsonObject.getJSONArray("shop_list");
if (CollectionUtils.isEmpty(jsonArray)) {
return;
}
//第一个数据或ufo数据放shop_list节点,放在前面
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject subJsonObject = jsonArray.getJSONObject(i);
if (i == 0 || MapUtils.getObject(subJsonObject, "ufo_brand") != null) {
firstShop.add(subJsonObject);
} else {
otherShops.add(subJsonObject);
}
}
int page = getPage(paramMap);
dataMap.put("shop_list", firstShop);
if (CollectionUtils.isEmpty(otherShops)) {
dataMap.put("shop_list_page", Collections.emptyList());
return;
}
//剩下的店铺列表分页,每页两个
int page = getPage(paramMap);
int pageSize = 2;
List<JSONObject> subShopList = SearchCollectionUtils.safeSubList(otherShops, (page - 1) * pageSize, page * pageSize);
if (!CollectionUtils.isEmpty(subShopList)) {
... ...
... ... @@ -107,7 +107,7 @@ public class ShopListService {
BoolQueryBuilder yohoShopFilter = QueryBuilders.boolQuery();
yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isUfo, "Y"));
yohoShopFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shopId).gte(0));
yohoShopFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shopId).gt(0));
// 判断是否需要包含全球购或ufo
boolean containGlobal = searchCommonHelper.containGlobal(paramMap);
boolean containUfo = searchCommonHelper.containUFO(paramMap);
... ...