Authored by unknown

fix

... ... @@ -4,6 +4,7 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.scene.searchlike.BigdataSimilarSknService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
... ... @@ -40,6 +41,8 @@ public class SearchLikeSecneController {
private ISimilarProductService similarProductService;
@Autowired
private BigdataSimilarSknService bigdataSimilarSknService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@RequestMapping(method = RequestMethod.GET, value = "/searchLike")
@ResponseBody
... ... @@ -59,8 +62,10 @@ public class SearchLikeSecneController {
@ResponseBody
public SearchApiResult searchLikeNotInShop(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
// return searchLikeNotInShopService.searchLikeNotInShop(paramMap);
return bigdataSimilarSknService.searchLikeSimilarSknNotInShop(paramMap);
if (searchDynamicConfigService.isSearchLikeSimilarSknOpen()) {
return bigdataSimilarSknService.searchLikeSimilarSknNotInShop(paramMap);
}
return searchLikeNotInShopService.searchLikeNotInShop(paramMap);
}
/**
... ...
... ... @@ -208,5 +208,12 @@ public class SearchDynamicConfigService {
public boolean isRecommendPersionalOpen() {
return configReader.getBoolean("search.persional.recommend.open", true);
}
/**
* 找相似是否使用bigdatasimilarskn
*/
public boolean isSearchLikeSimilarSknOpen() {
return configReader.getBoolean("search.searchlike.similarskn", true);
}
}
... ...
... ... @@ -28,15 +28,13 @@ import java.util.List;
import java.util.Map;
@Service
public class BigdataSimilarSknService extends SearchLikeNotInShopService{
public class BigdataSimilarSknService {
private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknService.class);
@Autowired
private SearchLikeHelper searchLikeHelper;
@Autowired
private ProductIndexBaseService productIndexBaseService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) {
try {
... ... @@ -65,10 +63,7 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
List<String> diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(","));
searchParams.add(builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, pageSize/3));
}
int sameSortCount = searchDynamicConfigService.getSearchLikeNotInShopSameSortPercent() * pageSize / 100;
searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), sameSortCount, true));
searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize - sameSortCount, false));
searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize, true));
// 4、获取搜索结果[截取条数]
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
... ... @@ -95,11 +90,65 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
}
}
private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setQuery(builderQueryBuilder(productInfoInEs, inSameSort ? "30%" : "20%"));
searchParam.setFiter(builderFilterBuilder(productInfoInEs, productSkns, inSameSort));
// 3、设置排序规则[按打分排序]
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 4、设置分页参数
searchParam.setOffset(0);
searchParam.setSize(pageSize);
// 5)设置返回的参数【节省带宽】
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
searchParam.setIncludeFields(includeFields);
return searchParam;
}
private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) {
String queryString = searchLikeHelper.genYohoQueryStringWithOutBrandName(productInfoInEs);
String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor);
QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor);
return queryBuilder;
}
private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSameSort) {
String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
// 1)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString(ProductIndexEsField.gender);
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
if (genderList != null && !genderList.isEmpty()) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
}
// 2)设置品牌或店铺信息
Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
if (searchLikeHelper.isLegalInteger(shopId)) {
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId));
} else if (searchLikeHelper.isLegalInteger(brandId)) {
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
}
// 3)设置品类信息
Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
if (inSameSort) {
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
} else {
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.smallSort_smallSort_keyword, productInfoInEs.getString(ProductIndexEsField.smallSort)));// 有些小分类同名,要排除这种情况。
}
return boolFilter;
}
private SearchParam builderSimilarSknSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setQuery(builderSimilarSknQueryBuilder(productInfoInEs));
searchParam.setFiter(builderSimilarSknFilterBuilder(productInfoInEs, productSkns));
// 3、设置排序规则[按打分排序]
List<SortBuilder<?>> sortBuilders = new ArrayList<>();
... ... @@ -139,8 +188,4 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{
return boolFilter;
}
private QueryBuilder builderSimilarSknQueryBuilder(JSONObject productInfoInEs) {
return searchLikeHelper.genProductFeatureQueryBuilder( productInfoInEs.getString(ProductIndexEsField.productFeatureFactor));
}
}
... ...
... ... @@ -100,7 +100,7 @@ public class SearchLikeNotInShopService{
}
}
protected SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
... ...
... ... @@ -49,6 +49,8 @@ search.persional.rateLimit.open=true
search.persional.newstrategy.open=false
search.persional.recommend.open=true
#searchlike
search.searchlike.similarskn=true
search.persional.rateLimit.brand.productList=200:2
search.persional.rateLimit.brand.aggregations=100:2
... ...