Authored by mali

商品池模糊搜索需要返回product_pool_orderby

... ... @@ -3,7 +3,10 @@ package com.yoho.search.service.index.ufo;
import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.UfoSearchRequestParams;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -52,15 +55,15 @@ public class UfoProductIndexBaseService {
return results;
}
public List<Map<String, Object>> buildProductReturnInfoList(List<Map<String, Object>> productEsSourceList) {
public List<Map<String, Object>> buildProductReturnInfoList(List<Map<String, Object>> productEsSourceList, Map<String, String> paramMap) {
List<Map<String, Object>> results = new ArrayList<>(productEsSourceList.size());
for (Map<String, Object> productEsSource : productEsSourceList) {
results.add(this.getProductMapFromEsSource(productEsSource));
results.add(this.getProductMapFromEsSource(productEsSource, paramMap));
}
return results;
}
private Map<String, Object> getProductMapFromEsSource(Map<String, Object> map) {
private Map<String, Object> getProductMapFromEsSource(Map<String, Object> map, Map<String, String> paramMap) {
Map<String, Object> productMap = new HashMap<>();
productMap.put("id", MapUtils.getIntValue(map, UfoProductIndexEsField.id, 0));
productMap.put("product_name", MapUtils.getString(map, UfoProductIndexEsField.productName, ""));
... ... @@ -78,16 +81,17 @@ public class UfoProductIndexBaseService {
productMap.put("available_now_price", availableNowPrice == null || availableNowPrice == -1d ? null : availableNowPrice);
productMap.put("is_yoho", MapUtils.getString(map, UfoProductIndexEsField.isYoho, "N"));
productMap.put("pool_order_by", getPoolOrderBy(map, paramMap));
productMap.put("pool_ids", MapUtils.getString(map, UfoProductIndexEsField.poolIds, ""));
return productMap;
}
public Map<Integer,Map<String,Object>> queryUfoProductMapByProductIds(final Collection<?> ufoProductIds) {
List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds);
public Map<Integer,Map<String,Object>> queryUfoProductMapByProductIds(final Collection<?> ufoProductIds, Map<String, String> paramMap) {
List<Map<String, Object>> resultList = this.queryListByProductIds(ufoProductIds, paramMap);
return resultList.stream().collect(Collectors.toMap(a->MapUtils.getIntValue(a,"id",0),p->p));
}
public List<Map<String, Object>> queryListByProductIds(final Collection<?> ufoProductIds) {
public List<Map<String, Object>> queryListByProductIds(final Collection<?> ufoProductIds, Map<String, String> paramMap) {
List<Map<String, Object>> resultList = new ArrayList<>();
try {
if (ufoProductIds == null || ufoProductIds.isEmpty()) {
... ... @@ -95,7 +99,7 @@ public class UfoProductIndexBaseService {
}
List<Map<String, Object>> queryResults = searchCommonService.doMultiGetCommon(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, ufoProductIds);
for (Map<String, Object> results : queryResults) {
resultList.add(this.getProductMapFromEsSource(results));
resultList.add(this.getProductMapFromEsSource(results, paramMap));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ... @@ -103,5 +107,26 @@ public class UfoProductIndexBaseService {
return resultList;
}
private int getPoolOrderBy(Map<String, Object> map, Map<String, String> paramMap) {
try {
String inputPoolId = MapUtils.getString(paramMap, UfoSearchRequestParams.UFO_PARAM_POOL, "");
if (StringUtils.isBlank(inputPoolId)) {
return 0;
}
List<Map<String, Object>> poolList = (List<Map<String, Object>>) map.get(UfoProductIndexEsField.pools);
if (CollectionUtils.isEmpty(poolList)) {
return 0;
}
for (Map<String, Object> poolMap : poolList) {
Integer poolId = MapUtils.getIntValue(poolMap, "poolId", 0);
if (Integer.valueOf(inputPoolId).equals(poolId)) {
return MapUtils.getIntValue(poolMap, "orderBy", 0);
}
}
return 0;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return 0;
}
}
}
... ...
... ... @@ -71,7 +71,7 @@ public class UfoFavoriteService {
// 5、执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 6、构造返回结果
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 7、添加自定义标签
customizeTagBaseService.fillCustomizeTag(returnInfoList, false);
// 8、按id顺序排序
... ...
... ... @@ -77,7 +77,7 @@ public class UfoFuzzySceneService {
// 执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 构造返回结果
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 返回结果为空时,针对货号进行模糊纠错匹配
if (CollectionUtils.isEmpty(returnInfoList)) {
return fuzzySearchForProductCode(paramMap);
... ... @@ -111,7 +111,7 @@ public class UfoFuzzySceneService {
// 执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 构造返回结果
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 添加变价计划
productPricePlanIndexBaseService.fillProductPricePlanForUfo(returnInfoList);
JSONObject dataMap = new JSONObject();
... ...
... ... @@ -69,7 +69,7 @@ public class UfoHotSaleListService {
// 3、执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 4、处理返回结果
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 5、添加排行序列号
this.addNumberTag(returnInfoList, page, pageSize);
// 6、构造返回结果【限制返回总数100个】
... ...
... ... @@ -67,7 +67,7 @@ public class UfoProductListService {
// 执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 构造返回结果
List<Map<String, Object>> productList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> productList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 添加变价计划
productPricePlanIndexBaseService.fillProductPricePlanForUfo(productList);
// 添加自定义标签
... ...
... ... @@ -159,7 +159,7 @@ public class UfoSecondhandSkupService {
Map<Integer, Double> storageAvailableNowPriceMap = this.queryAvailableNowPriceByStorageIds(ufoStorageIds);
// 6、根据productIds查询商品信息
Map<Integer, Map<String, Object>> ufoProductMap = ufoProductIndexBaseService.queryUfoProductMapByProductIds(ufoProductIds);
Map<Integer, Map<String, Object>> ufoProductMap = ufoProductIndexBaseService.queryUfoProductMapByProductIds(ufoProductIds, paramMap);
// 9、处理结果
for (Map<String, Object> skupResult : skupResultList) {
... ...
... ... @@ -66,7 +66,7 @@ public class UfoSoonSaleService {
// 执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
// 处理返回结果
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList());
List<Map<String, Object>> returnInfoList = ufoProductIndexBaseService.buildProductReturnInfoList(searchResult.getResultList(), paramMap);
// 构造返回结果
JSONObject result = new JSONObject();
result.put("total", searchResult.getTotal());
... ...