Authored by hugufei

Merge branch 'master' into zj_skninfo

  1 +package com.yoho.search.service.index;
  2 +
  3 +import com.yoho.search.base.utils.ISearchConstants;
  4 +import com.yoho.search.base.utils.ProductIndexEsField;
  5 +import com.yoho.search.common.SearchCommonService;
  6 +import com.yoho.search.core.es.model.SearchParam;
  7 +import com.yoho.search.core.es.model.SearchResult;
  8 +import com.yoho.search.dal.model.SimilarSkn;
  9 +import org.apache.commons.collections.MapUtils;
  10 +import org.apache.commons.lang.StringUtils;
  11 +import org.elasticsearch.index.query.BoolQueryBuilder;
  12 +import org.elasticsearch.index.query.QueryBuilders;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Service;
  17 +import org.springframework.util.CollectionUtils;
  18 +
  19 +import java.util.ArrayList;
  20 +import java.util.Arrays;
  21 +import java.util.List;
  22 +import java.util.Map;
  23 +
  24 +/**
  25 + * @author wangnan
  26 + * @version 2018/5/23
  27 + */
  28 +@Service
  29 +public class BigDataSimilarSknImgAliIndexBaseService {
  30 +
  31 + private final Logger logger = LoggerFactory.getLogger(this.getClass());
  32 +
  33 + @Autowired
  34 + private SearchCommonService searchCommonService;
  35 +
  36 +
  37 + public SimilarSkn querySimilarSkn(String productSkn) {
  38 + try {
  39 + SearchParam searchParam = new SearchParam();
  40 + BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
  41 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, productSkn));
  42 + searchParam.setFiter(boolFilter);
  43 + searchParam.setAggregationBuilders(null);
  44 + searchParam.setSize(1);
  45 + String productIndexName = ISearchConstants.INDEX_NAME_BIGDATA_SIMILAR_SKN_IMG_ALI_INDEX;
  46 + SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
  47 + if (searchResult == null) {
  48 + return null;
  49 + }
  50 + List<Map<String, Object>> similarSknResults = searchResult.getResultList();
  51 + if (CollectionUtils.isEmpty(similarSknResults) || similarSknResults.get(0) == null) {
  52 + return null;
  53 + }
  54 + Map<String, Object> result = similarSknResults.get(0);
  55 + SimilarSkn similarSkn = new SimilarSkn();
  56 + similarSkn.setDataId(MapUtils.getInteger(result, "dateId", 0));
  57 + similarSkn.setSameShopImgSimilarSkns(MapUtils.getString(result, "sameShopImgSimilarSkns", ""));
  58 + similarSkn.setDiffShopImgSimilarSkns(MapUtils.getString(result, "diffShopImgSimilarSkns", ""));
  59 + return similarSkn;
  60 + } catch (Exception e) {
  61 + logger.error(e.getMessage(), e);
  62 + return null;
  63 + }
  64 + }
  65 +
  66 + public List<String> getSimilarProductSknListInShop(String productSkn) {
  67 + SimilarSkn similarSkn = this.querySimilarSkn(productSkn);
  68 + List<String> similarProductSknList = new ArrayList<>();
  69 + if (similarSkn != null && StringUtils.isNotBlank(similarSkn.getSameShopImgSimilarSkns())) {
  70 + String[] productSknArray = similarSkn.getSameShopImgSimilarSkns().split(",");
  71 + if (productSknArray.length > 0) {
  72 + similarProductSknList = Arrays.asList(productSknArray);
  73 + }
  74 + }
  75 + return similarProductSknList;
  76 + }
  77 +
  78 +
  79 +}
@@ -4,14 +4,15 @@ import com.alibaba.fastjson.JSONArray; @@ -4,14 +4,15 @@ import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
6 import com.yoho.search.base.utils.ProductIndexEsField; 6 import com.yoho.search.base.utils.ProductIndexEsField;
  7 +import com.yoho.search.common.SearchCommonService;
7 import com.yoho.search.core.es.model.SearchParam; 8 import com.yoho.search.core.es.model.SearchParam;
8 import com.yoho.search.core.es.model.SearchResult; 9 import com.yoho.search.core.es.model.SearchResult;
9 import com.yoho.search.models.SearchApiResult; 10 import com.yoho.search.models.SearchApiResult;
10 import com.yoho.search.models.SearchFieldBoost; 11 import com.yoho.search.models.SearchFieldBoost;
11 -import com.yoho.search.common.SearchCommonService;  
12 -import com.yoho.search.service.index.ProductIndexBaseService;  
13 import com.yoho.search.service.helper.FunctionScoreSearchHelper; 12 import com.yoho.search.service.helper.FunctionScoreSearchHelper;
14 import com.yoho.search.service.helper.ProductListHelper; 13 import com.yoho.search.service.helper.ProductListHelper;
  14 +import com.yoho.search.service.index.ProductIndexBaseService;
  15 +import org.apache.commons.collections.CollectionUtils;
15 import org.apache.commons.collections.MapUtils; 16 import org.apache.commons.collections.MapUtils;
16 import org.apache.commons.lang.StringUtils; 17 import org.apache.commons.lang.StringUtils;
17 import org.elasticsearch.index.query.BoolQueryBuilder; 18 import org.elasticsearch.index.query.BoolQueryBuilder;
@@ -26,6 +27,7 @@ import org.springframework.stereotype.Component; @@ -26,6 +27,7 @@ import org.springframework.stereotype.Component;
26 27
27 import javax.annotation.PostConstruct; 28 import javax.annotation.PostConstruct;
28 import java.util.*; 29 import java.util.*;
  30 +import java.util.stream.Collectors;
29 31
30 @Component 32 @Component
31 public class SearchLikeHelper { 33 public class SearchLikeHelper {
@@ -329,6 +331,39 @@ public class SearchLikeHelper { @@ -329,6 +331,39 @@ public class SearchLikeHelper {
329 } 331 }
330 332
331 /** 333 /**
  334 + * 处理图片相似+文字相似skn列表,把图片相似skn排序
  335 + */
  336 + public List<Map<String, Object>> queryProductListWithSimilarImg(List<SearchParam> searchParams, List<String> similarProductSknList) {
  337 + List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
  338 + List<Map<String, Object>> results = new ArrayList<>();
  339 + Set<String> existProductSkns = new HashSet<>();
  340 + if (CollectionUtils.isEmpty(searchResults) || searchResults.size() != 2) {
  341 + return results;
  342 + }
  343 + SearchResult searchResultFromImg = searchResults.get(0);
  344 + List<Map<String, Object>> searchResultFromImgList = searchResultFromImg.getResultList();
  345 + if (CollectionUtils.isNotEmpty(searchResultFromImgList)) {
  346 + Map<String, Map<String, Object>> searchResultFromImgMap = searchResultFromImgList.stream().collect(Collectors.toMap(p -> MapUtils.getString(p, ProductIndexEsField.productSkn), p -> p));
  347 + for (String skn : similarProductSknList) {
  348 + if (searchResultFromImgMap.containsKey(skn)) {
  349 + results.add(searchResultFromImgMap.get(skn));
  350 + existProductSkns.add(skn);
  351 + }
  352 + }
  353 + }
  354 + SearchResult searchResultFromWord = searchResults.get(1);
  355 + if (CollectionUtils.isNotEmpty(searchResultFromWord.getResultList())) {
  356 + for (Map<String, Object> product : searchResultFromWord.getResultList()) {
  357 + if (this.isProductSknExists(existProductSkns, product)) {
  358 + continue;
  359 + }
  360 + results.add(product);
  361 + }
  362 + }
  363 + return results;
  364 + }
  365 +
  366 + /**
332 * 店铺外按文字找相似 367 * 店铺外按文字找相似
333 * 368 *
334 * @param productInfoInEs 369 * @param productInfoInEs
@@ -387,7 +422,8 @@ public class SearchLikeHelper { @@ -387,7 +422,8 @@ public class SearchLikeHelper {
387 boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId)); 422 boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
388 } else { 423 } else {
389 boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId)); 424 boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
390 - boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.smallSort_smallSort_keyword, productInfoInEs.getString(ProductIndexEsField.smallSort)));// 有些小分类同名,要排除这种情况。 425 + // 有些小分类同名,要排除这种情况。
  426 + boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.smallSort_smallSort_keyword, productInfoInEs.getString(ProductIndexEsField.smallSort)));
391 } 427 }
392 return boolFilter; 428 return boolFilter;
393 } 429 }
1 package com.yoho.search.service.scene.searchlike; 1 package com.yoho.search.service.scene.searchlike;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.search.aop.cache.SearchCacheAble;
4 import com.yoho.search.base.utils.CollectionUtils; 5 import com.yoho.search.base.utils.CollectionUtils;
5 import com.yoho.search.base.utils.ProductIndexEsField; 6 import com.yoho.search.base.utils.ProductIndexEsField;
6 -import com.yoho.search.aop.cache.SearchCacheAble; 7 +import com.yoho.search.common.SearchRequestParams;
7 import com.yoho.search.core.es.model.SearchParam; 8 import com.yoho.search.core.es.model.SearchParam;
8 import com.yoho.search.models.SearchApiResult; 9 import com.yoho.search.models.SearchApiResult;
9 -import com.yoho.search.common.SearchRequestParams;  
10 -import com.yoho.search.service.index.ProductIndexBaseService;  
11 -  
12 import com.yoho.search.service.helper.ProductListHelper; 10 import com.yoho.search.service.helper.ProductListHelper;
  11 +import com.yoho.search.service.index.BigDataSimilarSknImgAliIndexBaseService;
  12 +import com.yoho.search.service.index.ProductIndexBaseService;
13 import org.apache.commons.lang.StringUtils; 13 import org.apache.commons.lang.StringUtils;
14 import org.elasticsearch.index.query.BoolQueryBuilder; 14 import org.elasticsearch.index.query.BoolQueryBuilder;
15 import org.elasticsearch.index.query.QueryBuilder; 15 import org.elasticsearch.index.query.QueryBuilder;
@@ -29,114 +29,152 @@ import java.util.Map; @@ -29,114 +29,152 @@ import java.util.Map;
29 29
30 /** 30 /**
31 * 店铺内找相似 31 * 店铺内找相似
32 - * 32 + *
33 * @author gufei.hu 33 * @author gufei.hu
34 */ 34 */
35 @Service 35 @Service
36 public class SearchLikeInShopService { 36 public class SearchLikeInShopService {
37 37
38 - private static final Logger logger = LoggerFactory.getLogger(SearchLikeInShopService.class); 38 + private static final Logger logger = LoggerFactory.getLogger(SearchLikeInShopService.class);
  39 +
  40 + @Autowired
  41 + private SearchLikeHelper searchLikeHelper;
  42 + @Autowired
  43 + private ProductIndexBaseService productIndexBaseService;
  44 + @Autowired
  45 + private ProductListHelper productListHelper;
  46 + @Autowired
  47 + private BigDataSimilarSknImgAliIndexBaseService bigDataSimilarSknImgAliIndexBaseService;
  48 +
  49 + /**
  50 + * 店铺内推荐
  51 + */
  52 + @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_IN_SHOP_NEW", includeParams = {"product_skn"})
  53 + public SearchApiResult searchLikeInShop(Map<String, String> paramMap) {
  54 + try {
  55 + // 1、获取参数
  56 + String productSkn = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN);
  57 + if (StringUtils.isBlank(productSkn)) {
  58 + return new SearchApiResult().setCode(400).setMessage("请输入SKN");
  59 + }
  60 + // 2、检测分页参数【默认30条】
  61 + int viewNum = 30;
  62 + // 3、获取当前查询的SKN的基本信息
  63 + JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);
  64 + if (productInfoInEs == null) {
  65 + return new SearchApiResult().setCode(400).setMessage("SKN不存在");
  66 + }
  67 + // 4、设置SearchParams
  68 + List<SearchParam> searchParams = new ArrayList<>();
  69 + //4.1图片相似skn
  70 + List<String> similarProductSknList = bigDataSimilarSknImgAliIndexBaseService.getSimilarProductSknListInShop(productSkn);
  71 + if (similarProductSknList != null && !similarProductSknList.isEmpty()) {
  72 + searchParams.add(this.builderSearchParamForSimilarImg(productInfoInEs, similarProductSknList, viewNum));
  73 + }
  74 + //4.2文字相似skn
  75 + searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), viewNum));
  76 + // 5、获取搜索结果[截取条数]
  77 + List<Map<String, Object>> tempProductList = new ArrayList<>();
  78 + //只包含文字相似
  79 + if (searchParams.size() == 1) {
  80 + tempProductList = searchLikeHelper.queryProductList(searchParams);
  81 + } else {
  82 + //包含图片+文字相似
  83 + tempProductList = searchLikeHelper.queryProductListWithSimilarImg(searchParams, similarProductSknList);
  84 + }
  85 + if (tempProductList.size() > viewNum) {
  86 + tempProductList = CollectionUtils.safeSubList(tempProductList, 0, viewNum);
  87 + }
  88 + //6、保留偶数
  89 + if (tempProductList.size() % 2 > 0) {
  90 + tempProductList = CollectionUtils.safeSubList(tempProductList, 0, tempProductList.size() - 1);
  91 + }
  92 + // 7、构造返回结果
  93 + List<Map<String, Object>> productListResults = new ArrayList<>();
  94 + if (!tempProductList.isEmpty()) {
  95 + productListResults = productListHelper.buildReturnInfoByEsSourceList(tempProductList);
  96 + }
  97 + JSONObject result = new JSONObject();
  98 + result.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));
  99 + result.put("product_list", productListResults);
  100 + return new SearchApiResult().setData(result);
  101 + } catch (Exception e) {
  102 + logger.error(e.getMessage(), e);
  103 + return new SearchApiResult().setData(null).setMessage("searchLikeInShop Exception").setCode(500);
  104 + }
  105 + }
39 106
40 - @Autowired  
41 - private SearchLikeHelper searchLikeHelper;  
42 - @Autowired  
43 - private ProductIndexBaseService productIndexBaseService;  
44 - @Autowired  
45 - private ProductListHelper productListHelper;  
46 -  
47 - /**  
48 - * 店铺内推荐  
49 - *  
50 - * @param paramMap  
51 - * @return  
52 - */  
53 - @SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_IN_SHOP_NEW", includeParams = { "product_skn"})  
54 - public SearchApiResult searchLikeInShop(Map<String, String> paramMap) {  
55 - try {  
56 - // 1、获取参数  
57 - String productSkn = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN);  
58 - if (StringUtils.isBlank(productSkn)) {  
59 - return new SearchApiResult().setCode(400).setMessage("请输入SKN");  
60 - }  
61 - // 2、检测分页参数【默认30条】  
62 - int viewNum = 30;  
63 - // 3、获取当前查询的SKN的基本信息  
64 - JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);  
65 - if (productInfoInEs == null) {  
66 - return new SearchApiResult().setCode(400).setMessage("SKN不存在");  
67 - }  
68 - // 4、设置SearchParams  
69 - List<SearchParam> searchParams = new ArrayList<SearchParam>();  
70 - searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), viewNum));  
71 - // 5、获取搜索结果[截取条数]  
72 - List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);  
73 - if (tempProductList.size() > viewNum) {  
74 - tempProductList = CollectionUtils.safeSubList(tempProductList,0, viewNum);  
75 - }  
76 - //6、保留偶数  
77 - if (tempProductList.size() % 2 > 0) {  
78 - tempProductList = CollectionUtils.safeSubList(tempProductList, 0, tempProductList.size() - 1);  
79 - }  
80 - // 7、构造返回结果  
81 - List<Map<String, Object>> productListResults = new ArrayList<Map<String, Object>>();  
82 - if (!tempProductList.isEmpty()) {  
83 - productListResults = productListHelper.buildReturnInfoByEsSourceList(tempProductList);  
84 - }  
85 - JSONObject result = new JSONObject();  
86 - result.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));  
87 - result.put("product_list", productListResults);  
88 - return new SearchApiResult().setData(result);  
89 - } catch (Exception e) {  
90 - logger.error(e.getMessage(), e);  
91 - return new SearchApiResult().setData(null).setMessage("searchLikeInShop Exception").setCode(500);  
92 - }  
93 - } 107 + private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
  108 + // 1、设置SearchParam
  109 + SearchParam searchParam = new SearchParam();
  110 + // 2)设置query和filter
  111 + searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%"));
  112 + searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns));
  113 + // 3、设置排序规则[按打分排序]
  114 + List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
  115 + sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
  116 + searchParam.setSortBuilders(sortBuilders);
  117 + // 4、设置分页参数
  118 + searchParam.setOffset(0);
  119 + searchParam.setSize(pageSize);
  120 + // 5)设置返回的参数【节省带宽】
  121 + List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
  122 + searchParam.setIncludeFields(includeFields);
  123 + return searchParam;
  124 + }
94 125
95 - private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {  
96 - // 1、设置SearchParam  
97 - SearchParam searchParam = new SearchParam();  
98 - // 2)设置query和filter  
99 - searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%"));  
100 - searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns));  
101 - // 3、设置排序规则[按打分排序]  
102 - List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();  
103 - sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));  
104 - searchParam.setSortBuilders(sortBuilders);  
105 - // 4、设置分页参数  
106 - searchParam.setOffset(0);  
107 - searchParam.setSize(pageSize);  
108 - // 5)设置返回的参数【节省带宽】  
109 - List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();  
110 - searchParam.setIncludeFields(includeFields);  
111 - return searchParam;  
112 - } 126 + private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns) {
  127 + String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
  128 + boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
  129 + BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
  130 + // 1)设置此SKN相关的性别过滤条件
  131 + String gender = productInfoInEs.getString(ProductIndexEsField.gender);
  132 + List<String> genderList = searchLikeHelper.getGenderInfo(gender);
  133 + if (genderList != null && !genderList.isEmpty()) {
  134 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
  135 + }
  136 + // 2)设置品牌或店铺信息
  137 + Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
  138 + Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
  139 + if (searchLikeHelper.isLegalInteger(shopId)) {
  140 + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId));
  141 + } else if (searchLikeHelper.isLegalInteger(brandId)) {
  142 + boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
  143 + }
  144 + return boolFilter;
  145 + }
113 146
114 - private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns) {  
115 - String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);  
116 - boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);  
117 - BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);  
118 - // 1)设置此SKN相关的性别过滤条件  
119 - String gender = productInfoInEs.getString(ProductIndexEsField.gender);  
120 - List<String> genderList = searchLikeHelper.getGenderInfo(gender);  
121 - if (genderList != null && !genderList.isEmpty()) {  
122 - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));  
123 - }  
124 - // 2)设置品牌或店铺信息  
125 - Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);  
126 - Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);  
127 - if (searchLikeHelper.isLegalInteger(shopId)) {  
128 - boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId));  
129 - } else if (searchLikeHelper.isLegalInteger(brandId)) {  
130 - boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));  
131 - }  
132 - return boolFilter;  
133 - } 147 + private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) {
  148 + String queryString = searchLikeHelper.genYohoQueryStringWithBrandName(productInfoInEs);
  149 + String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor);
  150 + QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor);
  151 + return queryBuilder;
  152 + }
134 153
135 - private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) {  
136 - String queryString = searchLikeHelper.genYohoQueryStringWithBrandName(productInfoInEs);  
137 - String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor);  
138 - QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor);  
139 - return queryBuilder;  
140 - } 154 + /**
  155 + * 根据阿里相似图片的skn构建SearchParam去查productindex
  156 + */
  157 + private SearchParam builderSearchParamForSimilarImg(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
  158 + // 1、设置SearchParam
  159 + SearchParam searchParam = new SearchParam();
  160 + // 2)设置filter
  161 + String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
  162 + boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
  163 + BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(null, isGlobal);
  164 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, productSkns));
  165 + String gender = productInfoInEs.getString(ProductIndexEsField.gender);
  166 + List<String> genderList = searchLikeHelper.getGenderInfo(gender);
  167 + if (genderList != null && !genderList.isEmpty()) {
  168 + boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
  169 + }
  170 + searchParam.setFiter(boolFilter);
  171 + // 4、设置分页参数
  172 + searchParam.setOffset(0);
  173 + searchParam.setSize(pageSize);
  174 + // 5)设置返回的参数【节省带宽】
  175 + List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
  176 + searchParam.setIncludeFields(includeFields);
  177 + return searchParam;
  178 + }
141 179
142 } 180 }