Authored by hugufei

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

@@ -16,6 +16,7 @@ import com.yoho.search.service.scene.pages.selections.PageSelectionsBrandsServic @@ -16,6 +16,7 @@ import com.yoho.search.service.scene.pages.selections.PageSelectionsBrandsServic
16 import com.yoho.search.service.scene.pages.selections.PageSelectionsService; 16 import com.yoho.search.service.scene.pages.selections.PageSelectionsService;
17 import com.yoho.search.service.scene.shopbrand.ShopListService; 17 import com.yoho.search.service.scene.shopbrand.ShopListService;
18 import com.yoho.search.service.scene.suggest.RecommendWordsService; 18 import com.yoho.search.service.scene.suggest.RecommendWordsService;
  19 +import org.apache.commons.collections.MapUtils;
19 import org.apache.commons.lang.StringUtils; 20 import org.apache.commons.lang.StringUtils;
20 import org.slf4j.Logger; 21 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
@@ -131,36 +132,44 @@ public class FuzzySceneService extends AbstractPageSceneService { @@ -131,36 +132,44 @@ public class FuzzySceneService extends AbstractPageSceneService {
131 return newMap; 132 return newMap;
132 } 133 }
133 134
  135 + /**
  136 + * 处理shopList节点
  137 + * @param shops
  138 + * @param dataMap
  139 + * @param paramMap
  140 + */
134 private void shopList(SearchApiResult shops, JSONObject dataMap, Map<String, String> paramMap) { 141 private void shopList(SearchApiResult shops, JSONObject dataMap, Map<String, String> paramMap) {
135 dataMap.put("shop_list", Collections.emptyList()); 142 dataMap.put("shop_list", Collections.emptyList());
136 dataMap.put("shop_list_page", Collections.emptyList()); 143 dataMap.put("shop_list_page", Collections.emptyList());
137 List<JSONObject> firstShop = new ArrayList<>(); 144 List<JSONObject> firstShop = new ArrayList<>();
138 List<JSONObject> otherShops = new ArrayList<>(); 145 List<JSONObject> otherShops = new ArrayList<>();
139 - if (shops != null) {  
140 - JSONObject jsonObject = (JSONObject) shops.getData();  
141 - if (jsonObject != null) {  
142 - JSONArray jsonArray = jsonObject.getJSONArray("shop_list");  
143 - if (!CollectionUtils.isEmpty(jsonArray)) {  
144 - for (int i = 0; i < jsonArray.size(); i++) {  
145 - JSONObject subJsonObject = jsonArray.getJSONObject(i);  
146 - if (subJsonObject != null) {  
147 - if (i == 0) {  
148 - firstShop.add(subJsonObject);  
149 - } else {  
150 - otherShops.add(subJsonObject);  
151 - }  
152 - }  
153 - }  
154 - } 146 + if (shops == null) {
  147 + return;
  148 + }
  149 + JSONObject jsonObject = (JSONObject) shops.getData();
  150 + if (jsonObject == null) {
  151 + return;
  152 + }
  153 + JSONArray jsonArray = jsonObject.getJSONArray("shop_list");
  154 + if (CollectionUtils.isEmpty(jsonArray)) {
  155 + return;
  156 + }
  157 + //第一个数据或ufo数据放shop_list节点,放在前面
  158 + for (int i = 0; i < jsonArray.size(); i++) {
  159 + JSONObject subJsonObject = jsonArray.getJSONObject(i);
  160 + if (i == 0 || MapUtils.getObject(subJsonObject, "ufo_brand") != null) {
  161 + firstShop.add(subJsonObject);
  162 + } else {
  163 + otherShops.add(subJsonObject);
155 } 164 }
156 } 165 }
157 -  
158 - int page = getPage(paramMap);  
159 dataMap.put("shop_list", firstShop); 166 dataMap.put("shop_list", firstShop);
160 if (CollectionUtils.isEmpty(otherShops)) { 167 if (CollectionUtils.isEmpty(otherShops)) {
161 dataMap.put("shop_list_page", Collections.emptyList()); 168 dataMap.put("shop_list_page", Collections.emptyList());
162 return; 169 return;
163 } 170 }
  171 + //剩下的店铺列表分页,每页两个
  172 + int page = getPage(paramMap);
164 int pageSize = 2; 173 int pageSize = 2;
165 List<JSONObject> subShopList = SearchCollectionUtils.safeSubList(otherShops, (page - 1) * pageSize, page * pageSize); 174 List<JSONObject> subShopList = SearchCollectionUtils.safeSubList(otherShops, (page - 1) * pageSize, page * pageSize);
166 if (!CollectionUtils.isEmpty(subShopList)) { 175 if (!CollectionUtils.isEmpty(subShopList)) {
@@ -107,7 +107,7 @@ public class ShopListService { @@ -107,7 +107,7 @@ public class ShopListService {
107 BoolQueryBuilder yohoShopFilter = QueryBuilders.boolQuery(); 107 BoolQueryBuilder yohoShopFilter = QueryBuilders.boolQuery();
108 yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y")); 108 yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
109 yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isUfo, "Y")); 109 yohoShopFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isUfo, "Y"));
110 - yohoShopFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shopId).gte(0)); 110 + yohoShopFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shopId).gt(0));
111 // 判断是否需要包含全球购或ufo 111 // 判断是否需要包含全球购或ufo
112 boolean containGlobal = searchCommonHelper.containGlobal(paramMap); 112 boolean containGlobal = searchCommonHelper.containGlobal(paramMap);
113 boolean containUfo = searchCommonHelper.containUFO(paramMap); 113 boolean containUfo = searchCommonHelper.containUFO(paramMap);