Authored by hugufei

店铺内的图片找相似必须为同一个中分类

... ... @@ -131,7 +131,7 @@ public class SearchLikeInShopService {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, productSkns));
searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, productSkns, true));
// 3、设置分页参数
searchParam.setOffset(0);
searchParam.setSize(productSkns.size());
... ... @@ -153,7 +153,7 @@ public class SearchLikeInShopService {
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setQuery(this.buildeCharactersQueryBuilder(productInfoInEs, "20%"));
searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, null));
searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, null, false));
// 3、设置排序规则[按打分排序]
List<SortBuilder<?>> sortBuilders = new ArrayList<>();
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
... ... @@ -173,14 +173,13 @@ public class SearchLikeInShopService {
return queryBuilder;
}
private BoolQueryBuilder builderSearchLikeInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns) {
private BoolQueryBuilder builderSearchLikeInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns, boolean needSameSort) {
//1) 默认参数
String productSkn = productInfoInEs.getString(ProductIndexEsField.productSkn);
String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), isGlobal);
// 2)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString(ProductIndexEsField.gender);
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
... ... @@ -202,8 +201,13 @@ public class SearchLikeInShopService {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns));
}
// 5)同品类
Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
if (needSameSort && searchLikeHelper.isLegalInteger(middleSortId)) {
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
}
return boolFilter;
}
}
... ...
... ... @@ -194,6 +194,7 @@ public class SearchLikeNotInShopService {
if (genderList != null && !genderList.isEmpty()) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
}
// 3)设置品牌或店铺信息
Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
... ... @@ -202,10 +203,12 @@ public class SearchLikeNotInShopService {
} else if (searchLikeHelper.isLegalInteger(brandId)) {
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
}
// 4)设置productskn
if (CollectionUtils.isNotEmpty(inProductSkns)) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns));
}
// 5)同品类
Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
if (searchLikeHelper.isLegalInteger(middleSortId)) {
... ...