Authored by 胡古飞

店铺推荐加上性别限制

@@ -168,4 +168,14 @@ public class SearchLikeHelper { @@ -168,4 +168,14 @@ public class SearchLikeHelper {
168 return boolFilter; 168 return boolFilter;
169 } 169 }
170 170
  171 + public List<String> getGenderInfo(String gender) {
  172 + if ("1".equals(gender)) {
  173 + return Arrays.asList("1", "3");
  174 + }
  175 + if ("2".equals(gender)) {
  176 + return Arrays.asList("2", "3");
  177 + }
  178 + return Arrays.asList("1", "2", "3");
  179 + }
  180 +
171 } 181 }
@@ -96,6 +96,13 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService { @@ -96,6 +96,13 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
96 96
97 // 5、设置filter 97 // 5、设置filter
98 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(Arrays.asList(productSkn)); 98 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(Arrays.asList(productSkn));
  99 + // 1)设置此SKN相关的性别过滤条件
  100 + String gender = productInfoInEs.getString("gender");
  101 + List<String> genderList = searchLikeHelper.getGenderInfo(gender);
  102 + if (genderList != null) {
  103 + boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
  104 + }
  105 + // 2)设置品牌或店铺信息
99 Integer brandId = productInfoInEs.getInteger("brandId"); 106 Integer brandId = productInfoInEs.getInteger("brandId");
100 Integer shopId = productInfoInEs.getInteger("shopId"); 107 Integer shopId = productInfoInEs.getInteger("shopId");
101 if (isLegalInteger(shopId)) { 108 if (isLegalInteger(shopId)) {
@@ -127,9 +134,9 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService { @@ -127,9 +134,9 @@ public class SearchLikeInShopServiceImpl implements ISearchLikeInShopService {
127 if (searchResult != null) { 134 if (searchResult != null) {
128 productList = searchServiceHelper.getProductMapList(searchResult.getResultList()); 135 productList = searchServiceHelper.getProductMapList(searchResult.getResultList());
129 } 136 }
130 - //低于4条不返回  
131 - if(productList==null || productList.size()<4){  
132 - productList = new ArrayList<Map<String,Object>>(); 137 + // 低于4条不返回
  138 + if (productList == null || productList.size() < 4) {
  139 + productList = new ArrayList<Map<String, Object>>();
133 } 140 }
134 jsonObject = new JSONObject(); 141 jsonObject = new JSONObject();
135 jsonObject.put("page", 1); 142 jsonObject.put("page", 1);
@@ -241,21 +241,11 @@ public class SearchLikeServiceImpl implements ISearchLikeService { @@ -241,21 +241,11 @@ public class SearchLikeServiceImpl implements ISearchLikeService {
241 return searchLikeHelper.genSearchLikeQueryBuilder(query, minimumShouldMatch, productFeatureFactor); 241 return searchLikeHelper.genSearchLikeQueryBuilder(query, minimumShouldMatch, productFeatureFactor);
242 } 242 }
243 243
244 - private List<String> getGenderInfo(String gender) {  
245 - if ("1".equals(gender)) {  
246 - return Arrays.asList("1", "3");  
247 - }  
248 - if ("2".equals(gender)) {  
249 - return Arrays.asList("2", "3");  
250 - }  
251 - return Arrays.asList("1", "2", "3");  
252 - }  
253 -  
254 private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand) { 244 private BoolQueryBuilder genBoolQueryBuilder(JSONObject productInfoInEs, Map<String, String> paramMap, List<String> notProductSkns, boolean isInBrand) {
255 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns); 245 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultQueryBuilder(notProductSkns);
256 // 1)设置此SKN相关的过滤条件 246 // 1)设置此SKN相关的过滤条件
257 String gender = productInfoInEs.getString("gender"); 247 String gender = productInfoInEs.getString("gender");
258 - List<String> genderList = this.getGenderInfo(gender); 248 + List<String> genderList = searchLikeHelper.getGenderInfo(gender);
259 if (genderList != null) { 249 if (genderList != null) {
260 boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()]))); 250 boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
261 } 251 }