Authored by hugufei

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

@@ -131,7 +131,7 @@ public class SearchLikeInShopService { @@ -131,7 +131,7 @@ public class SearchLikeInShopService {
131 // 1、设置SearchParam 131 // 1、设置SearchParam
132 SearchParam searchParam = new SearchParam(); 132 SearchParam searchParam = new SearchParam();
133 // 2)设置query和filter 133 // 2)设置query和filter
134 - searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, productSkns)); 134 + searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, productSkns, true));
135 // 3、设置分页参数 135 // 3、设置分页参数
136 searchParam.setOffset(0); 136 searchParam.setOffset(0);
137 searchParam.setSize(productSkns.size()); 137 searchParam.setSize(productSkns.size());
@@ -153,7 +153,7 @@ public class SearchLikeInShopService { @@ -153,7 +153,7 @@ public class SearchLikeInShopService {
153 SearchParam searchParam = new SearchParam(); 153 SearchParam searchParam = new SearchParam();
154 // 2)设置query和filter 154 // 2)设置query和filter
155 searchParam.setQuery(this.buildeCharactersQueryBuilder(productInfoInEs, "20%")); 155 searchParam.setQuery(this.buildeCharactersQueryBuilder(productInfoInEs, "20%"));
156 - searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, null)); 156 + searchParam.setFiter(this.builderSearchLikeInShopFilter(productInfoInEs, null, false));
157 // 3、设置排序规则[按打分排序] 157 // 3、设置排序规则[按打分排序]
158 List<SortBuilder<?>> sortBuilders = new ArrayList<>(); 158 List<SortBuilder<?>> sortBuilders = new ArrayList<>();
159 sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC)); 159 sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
@@ -173,14 +173,13 @@ public class SearchLikeInShopService { @@ -173,14 +173,13 @@ public class SearchLikeInShopService {
173 return queryBuilder; 173 return queryBuilder;
174 } 174 }
175 175
176 - private BoolQueryBuilder builderSearchLikeInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns) { 176 + private BoolQueryBuilder builderSearchLikeInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns, boolean needSameSort) {
177 //1) 默认参数 177 //1) 默认参数
178 String productSkn = productInfoInEs.getString(ProductIndexEsField.productSkn); 178 String productSkn = productInfoInEs.getString(ProductIndexEsField.productSkn);
179 String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal); 179 String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
180 boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs); 180 boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
181 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), isGlobal); 181 BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), isGlobal);
182 182
183 -  
184 // 2)设置此SKN相关的性别过滤条件 183 // 2)设置此SKN相关的性别过滤条件
185 String gender = productInfoInEs.getString(ProductIndexEsField.gender); 184 String gender = productInfoInEs.getString(ProductIndexEsField.gender);
186 List<String> genderList = searchLikeHelper.getGenderInfo(gender); 185 List<String> genderList = searchLikeHelper.getGenderInfo(gender);
@@ -202,8 +201,13 @@ public class SearchLikeInShopService { @@ -202,8 +201,13 @@ public class SearchLikeInShopService {
202 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns)); 201 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns));
203 } 202 }
204 203
  204 + // 5)同品类
  205 + Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
  206 + if (needSameSort && searchLikeHelper.isLegalInteger(middleSortId)) {
  207 + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
  208 + }
  209 +
205 return boolFilter; 210 return boolFilter;
206 } 211 }
207 212
208 -  
209 } 213 }
@@ -194,6 +194,7 @@ public class SearchLikeNotInShopService { @@ -194,6 +194,7 @@ public class SearchLikeNotInShopService {
194 if (genderList != null && !genderList.isEmpty()) { 194 if (genderList != null && !genderList.isEmpty()) {
195 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList)); 195 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
196 } 196 }
  197 +
197 // 3)设置品牌或店铺信息 198 // 3)设置品牌或店铺信息
198 Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId); 199 Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
199 Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId); 200 Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
@@ -202,10 +203,12 @@ public class SearchLikeNotInShopService { @@ -202,10 +203,12 @@ public class SearchLikeNotInShopService {
202 } else if (searchLikeHelper.isLegalInteger(brandId)) { 203 } else if (searchLikeHelper.isLegalInteger(brandId)) {
203 boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId)); 204 boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
204 } 205 }
  206 +
205 // 4)设置productskn 207 // 4)设置productskn
206 if (CollectionUtils.isNotEmpty(inProductSkns)) { 208 if (CollectionUtils.isNotEmpty(inProductSkns)) {
207 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns)); 209 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, inProductSkns));
208 } 210 }
  211 +
209 // 5)同品类 212 // 5)同品类
210 Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId); 213 Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
211 if (searchLikeHelper.isLegalInteger(middleSortId)) { 214 if (searchLikeHelper.isLegalInteger(middleSortId)) {