...
|
...
|
@@ -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));
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|