Authored by hugufei

找相似支持返回ufo商品

... ... @@ -183,15 +183,13 @@ public class SearchLikeHelper {
*
* @return
*/
public BoolQueryBuilder genDefaultSearchLikeFilter(List<String> notProductSkns, boolean isGlobal) {
public BoolQueryBuilder genDefaultSearchLikeFilter(List<String> notProductSkns, boolean isGlobal, boolean isUfo) {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isFobbiden, 1));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.attribute, 2));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, 1));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isOutlets, 2));
if (notProductSkns != null && !notProductSkns.isEmpty()) {
... ... @@ -199,10 +197,12 @@ public class SearchLikeHelper {
}
if (isGlobal) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
} else if (isUfo) {
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.isUfo, "Y"));
} else {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
}
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isUfo, "Y"));
}
return boolFilter;
}
... ...
... ... @@ -53,12 +53,6 @@ public class SearchLikeInShopService {
@Autowired
private BigdataSimilarSknIndexBaseService bigdataSimilarSknIndexBaseService;
@SearchCacheAble(cacheInMinute = 60, cacheName = "SEARCH_LIKE_IN_SHOP_OLD", includeParams = {"product_skn"})
public SearchApiResult searchLikeInShop(Map<String, String> paramMap) {
return innerSearchLikeInShop(paramMap, false);
}
@SearchCacheAble(cacheInMinute = 60, cacheName = "SEARCH_LIKE_IN_SHOP", includeParams = {"product_skn"})
public SearchApiResult searchLikeInShopWithYohoImage(Map<String, String> paramMap) {
return innerSearchLikeInShop(paramMap, true);
... ... @@ -196,9 +190,7 @@ public class SearchLikeInShopService {
private BoolQueryBuilder builderSearchLikeInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns, boolean needSameSort) {
//1) 默认参数
String productSkn = productInfoInEs.getString(ProductIndexEsField.productSkn);
String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), isGlobal);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), false,false);
// 2)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString(ProductIndexEsField.gender);
... ...
... ... @@ -191,9 +191,7 @@ public class SearchLikeNotInShopService {
private BoolQueryBuilder buildSearchLikeNotInShopFilter(JSONObject productInfoInEs, List<String> inProductSkns) {
//1) 默认参数
String productSkn = productInfoInEs.getString(ProductIndexEsField.productSkn);
String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), isGlobal);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productSkn), false,false);
// 2)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString(ProductIndexEsField.gender);
... ...
... ... @@ -65,10 +65,12 @@ public class SearchLikeSceneService {
// 4、设置第一步SearchParam
String isGlobalInEs = productInfoInEs.getString(ProductIndexEsField.isGlobal);
String isUfoInEs = productInfoInEs.getString(ProductIndexEsField.isUfo);
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
boolean isUfo = "Y".equalsIgnoreCase(isUfoInEs);
List<SearchParam> searchParams = new ArrayList<SearchParam>();
searchParams.add(this.buildSearchParam(productInfoInEs, 5, true, isGlobal));// 固定取同品牌的5个商品
searchParams.add(this.buildSearchParam(productInfoInEs, pageSize, false, isGlobal));
searchParams.add(this.buildSearchParam(productInfoInEs, 5, true, isGlobal,isUfo));// 固定取同品牌的5个商品
searchParams.add(this.buildSearchParam(productInfoInEs, pageSize, false, isGlobal,isUfo));// 取同品牌的5个商品
// 5、获取搜索结果[并截取条数]
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
... ... @@ -103,16 +105,16 @@ public class SearchLikeSceneService {
* @param isGlobal
* @return
*/
private SearchParam buildSearchParam(JSONObject productInfoInEs, int limitCount, boolean inBrand, boolean isGlobal) {
private SearchParam buildSearchParam(JSONObject productInfoInEs, int limitCount, boolean inBrand, boolean isGlobal,boolean isUfo) {
SearchParam searchParam = new SearchParam();
// 1、构建Query
QueryBuilder queryBuilder = this.buildCharsetQueryBuilder(productInfoInEs, inBrand, isGlobal);
QueryBuilder queryBuilder = this.buildCharsetQueryBuilder(productInfoInEs, inBrand, isGlobal,isUfo);
searchParam.setQuery(queryBuilder);
// 2、设置过滤条件
List<String> notProductSkns = Arrays.asList(productInfoInEs.getString(ProductIndexEsField.productSkn));
BoolQueryBuilder booleanQueryBuilder = this.genSearchLikeFilterBuilder(productInfoInEs, notProductSkns, inBrand, isGlobal);
BoolQueryBuilder booleanQueryBuilder = this.genSearchLikeFilterBuilder(productInfoInEs, notProductSkns, inBrand, isGlobal, isUfo);
searchParam.setFiter(booleanQueryBuilder);
// 3、设置排序规则[按打分排序]
... ... @@ -137,8 +139,8 @@ public class SearchLikeSceneService {
* @param isGlobal
* @return
*/
private BoolQueryBuilder genSearchLikeFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean isInBrand, boolean isGlobal) {
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isInBrand ? isGlobal : false);// 前几个是全球购,后面找有货的就好
private BoolQueryBuilder genSearchLikeFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean isInBrand, boolean isGlobal,boolean isUfo) {
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isInBrand ? isGlobal : false,isInBrand ? isUfo : false);// 前几个是全球购,后面找有货的就好
// 1)设置此SKN相关的过滤条件
String gender = productInfoInEs.getString(ProductIndexEsField.gender);
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
... ... @@ -177,9 +179,9 @@ public class SearchLikeSceneService {
* @param isGlobal
* @return
*/
private QueryBuilder buildCharsetQueryBuilder(JSONObject productInfoInEs, boolean isInBrand, boolean isGlobal) {
private QueryBuilder buildCharsetQueryBuilder(JSONObject productInfoInEs, boolean isInBrand, boolean isGlobal,boolean isUfo){
// 1、如果是全球购,则直接用商品名称+品类名称去查
if (isGlobal) {
if (isGlobal || isUfo) {
String queryString = searchLikeHelper.genGlobalQueryString(productInfoInEs);
return searchLikeHelper.buildCharsetQueryBuilder(queryString, "25%");
}
... ... @@ -251,7 +253,7 @@ public class SearchLikeSceneService {
searchParam.setQuery(queryBuilder);
// 2、设置过滤条件
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productInfoInEs.getString("productSkn")), false);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productInfoInEs.getString("productSkn")), false,false);
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, Arrays.asList("1", "2")));
// 3、找相似要具体到到中分类或小分类,大分类范围太广
... ...