Authored by 胡古飞

店铺推荐加上性别限制

... ... @@ -168,4 +168,14 @@ public class SearchLikeHelper {
return boolFilter;
}
public List<String> getGenderInfo(String gender) {
if ("1".equals(gender)) {
return Arrays.asList("1", "3");
}
if ("2".equals(gender)) {
return Arrays.asList("2", "3");
}
return Arrays.asList("1", "2", "3");
}
}
... ...
... ... @@ -96,6 +96,13 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
// 5、设置filter
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(Arrays.asList(productSkn));
// 1)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString("gender");
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
if (genderList != null) {
boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
}
// 2)设置品牌或店铺信息
Integer brandId = productInfoInEs.getInteger("brandId");
Integer shopId = productInfoInEs.getInteger("shopId");
if (isLegalInteger(shopId)) {
... ... @@ -127,9 +134,9 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
if (searchResult != null) {
productList = searchServiceHelper.getProductMapList(searchResult.getResultList());
}
//低于4条不返回
if(productList==null || productList.size()<4){
productList = new ArrayList<Map<String,Object>>();
// 低于4条不返回
if (productList == null || productList.size() < 4) {
productList = new ArrayList<Map<String, Object>>();
}
jsonObject = new JSONObject();
jsonObject.put("page", 1);
... ...
... ... @@ -241,21 +241,11 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
return searchLikeHelper.genSearchLikeQueryBuilder(query, minimumShouldMatch, productFeatureFactor);
}
private List<String> getGenderInfo(String gender) {
if ("1".equals(gender)) {
return Arrays.asList("1", "3");
}
if ("2".equals(gender)) {
return Arrays.asList("2", "3");
}
return Arrays.asList("1", "2", "3");
}
private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand) {
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns);
// 1)设置此SKN相关的过滤条件
String gender = productInfoInEs.getString("gender");
List<String> genderList = this.getGenderInfo(gender);
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
if (genderList != null) {
boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
}
... ...