|
@@ -28,15 +28,13 @@ import java.util.List; |
|
@@ -28,15 +28,13 @@ import java.util.List; |
28
|
import java.util.Map;
|
28
|
import java.util.Map;
|
29
|
|
29
|
|
30
|
@Service
|
30
|
@Service
|
31
|
-public class BigdataSimilarSknService extends SearchLikeNotInShopService{
|
31
|
+public class BigdataSimilarSknService {
|
32
|
private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknService.class);
|
32
|
private static final Logger logger = LoggerFactory.getLogger(BigdataSimilarSknService.class);
|
33
|
|
33
|
|
34
|
@Autowired
|
34
|
@Autowired
|
35
|
private SearchLikeHelper searchLikeHelper;
|
35
|
private SearchLikeHelper searchLikeHelper;
|
36
|
@Autowired
|
36
|
@Autowired
|
37
|
private ProductIndexBaseService productIndexBaseService;
|
37
|
private ProductIndexBaseService productIndexBaseService;
|
38
|
- @Autowired
|
|
|
39
|
- private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
40
|
|
38
|
|
41
|
public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) {
|
39
|
public SearchApiResult searchLikeSimilarSknNotInShop(Map<String, String> paramMap) {
|
42
|
try {
|
40
|
try {
|
|
@@ -65,10 +63,7 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
|
@@ -65,10 +63,7 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
65
|
List<String> diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(","));
|
63
|
List<String> diffShopImgSimilarSkns = CollectionUtils.arrayToList(similarSkn.getDiffShopImgSimilarSkns().split(","));
|
66
|
searchParams.add(builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, pageSize/3));
|
64
|
searchParams.add(builderSimilarSknSearchParam(productInfoInEs, diffShopImgSimilarSkns, pageSize/3));
|
67
|
}
|
65
|
}
|
68
|
-
|
|
|
69
|
- int sameSortCount = searchDynamicConfigService.getSearchLikeNotInShopSameSortPercent() * pageSize / 100;
|
|
|
70
|
- searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), sameSortCount, true));
|
|
|
71
|
- searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize - sameSortCount, false));
|
66
|
+ searchParams.add(builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize, true));
|
72
|
|
67
|
|
73
|
// 4、获取搜索结果[截取条数]
|
68
|
// 4、获取搜索结果[截取条数]
|
74
|
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
|
69
|
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
|
|
@@ -95,11 +90,65 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
|
@@ -95,11 +90,65 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
95
|
}
|
90
|
}
|
96
|
}
|
91
|
}
|
97
|
|
92
|
|
|
|
93
|
+ private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSameSort) {
|
|
|
94
|
+ // 1、设置SearchParam
|
|
|
95
|
+ SearchParam searchParam = new SearchParam();
|
|
|
96
|
+ // 2)设置query和filter
|
|
|
97
|
+ searchParam.setQuery(builderQueryBuilder(productInfoInEs, inSameSort ? "30%" : "20%"));
|
|
|
98
|
+ searchParam.setFiter(builderFilterBuilder(productInfoInEs, productSkns, inSameSort));
|
|
|
99
|
+ // 3、设置排序规则[按打分排序]
|
|
|
100
|
+ List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
|
|
|
101
|
+ sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
|
|
|
102
|
+ searchParam.setSortBuilders(sortBuilders);
|
|
|
103
|
+ // 4、设置分页参数
|
|
|
104
|
+ searchParam.setOffset(0);
|
|
|
105
|
+ searchParam.setSize(pageSize);
|
|
|
106
|
+ // 5)设置返回的参数【节省带宽】
|
|
|
107
|
+ List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
|
|
|
108
|
+ searchParam.setIncludeFields(includeFields);
|
|
|
109
|
+ return searchParam;
|
|
|
110
|
+ }
|
|
|
111
|
+
|
|
|
112
|
+ private QueryBuilder builderQueryBuilder(JSONObject productInfoInEs, String minimumShouldMatch) {
|
|
|
113
|
+ String queryString = searchLikeHelper.genYohoQueryStringWithOutBrandName(productInfoInEs);
|
|
|
114
|
+ String productFeatureFactor = productInfoInEs.getString(ProductIndexEsField.productFeatureFactor);
|
|
|
115
|
+ QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, minimumShouldMatch, productFeatureFactor);
|
|
|
116
|
+ return queryBuilder;
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSameSort) {
|
|
|
120
|
+ String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
|
|
|
121
|
+ boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
|
|
|
122
|
+ BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
|
|
|
123
|
+ // 1)设置此SKN相关的性别过滤条件
|
|
|
124
|
+ String gender = productInfoInEs.getString(ProductIndexEsField.gender);
|
|
|
125
|
+ List<String> genderList = searchLikeHelper.getGenderInfo(gender);
|
|
|
126
|
+ if (genderList != null && !genderList.isEmpty()) {
|
|
|
127
|
+ boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genderList));
|
|
|
128
|
+ }
|
|
|
129
|
+ // 2)设置品牌或店铺信息
|
|
|
130
|
+ Integer brandId = productInfoInEs.getInteger(ProductIndexEsField.brandId);
|
|
|
131
|
+ Integer shopId = productInfoInEs.getInteger(ProductIndexEsField.shopId);
|
|
|
132
|
+ if (searchLikeHelper.isLegalInteger(shopId)) {
|
|
|
133
|
+ boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.shopId, shopId));
|
|
|
134
|
+ } else if (searchLikeHelper.isLegalInteger(brandId)) {
|
|
|
135
|
+ boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.brandId, brandId));
|
|
|
136
|
+ }
|
|
|
137
|
+ // 3)设置品类信息
|
|
|
138
|
+ Integer middleSortId = productInfoInEs.getInteger(ProductIndexEsField.middleSortId);
|
|
|
139
|
+ if (inSameSort) {
|
|
|
140
|
+ boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
|
|
|
141
|
+ } else {
|
|
|
142
|
+ boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.middleSortId, middleSortId));
|
|
|
143
|
+ boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.smallSort_smallSort_keyword, productInfoInEs.getString(ProductIndexEsField.smallSort)));// 有些小分类同名,要排除这种情况。
|
|
|
144
|
+ }
|
|
|
145
|
+ return boolFilter;
|
|
|
146
|
+ }
|
|
|
147
|
+
|
98
|
private SearchParam builderSimilarSknSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
|
148
|
private SearchParam builderSimilarSknSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
|
99
|
// 1、设置SearchParam
|
149
|
// 1、设置SearchParam
|
100
|
SearchParam searchParam = new SearchParam();
|
150
|
SearchParam searchParam = new SearchParam();
|
101
|
// 2)设置query和filter
|
151
|
// 2)设置query和filter
|
102
|
- searchParam.setQuery(builderSimilarSknQueryBuilder(productInfoInEs));
|
|
|
103
|
searchParam.setFiter(builderSimilarSknFilterBuilder(productInfoInEs, productSkns));
|
152
|
searchParam.setFiter(builderSimilarSknFilterBuilder(productInfoInEs, productSkns));
|
104
|
// 3、设置排序规则[按打分排序]
|
153
|
// 3、设置排序规则[按打分排序]
|
105
|
List<SortBuilder<?>> sortBuilders = new ArrayList<>();
|
154
|
List<SortBuilder<?>> sortBuilders = new ArrayList<>();
|
|
@@ -139,8 +188,4 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
|
@@ -139,8 +188,4 @@ public class BigdataSimilarSknService extends SearchLikeNotInShopService{ |
139
|
return boolFilter;
|
188
|
return boolFilter;
|
140
|
}
|
189
|
}
|
141
|
|
190
|
|
142
|
- private QueryBuilder builderSimilarSknQueryBuilder(JSONObject productInfoInEs) {
|
|
|
143
|
- return searchLikeHelper.genProductFeatureQueryBuilder( productInfoInEs.getString(ProductIndexEsField.productFeatureFactor));
|
|
|
144
|
- }
|
|
|
145
|
-
|
|
|
146
|
} |
191
|
} |