Authored by unknown

fix找相似BUG

... ... @@ -81,14 +81,10 @@ public class GoodProductSceneService {
private static final String collect_product_skn = "collect_product_skn";
public SearchApiResult goodProductList(Map<String, String> paramMap) throws Exception {
// if (searchCommonHelper.isDebugUser(paramMap)) {
// logger.warn("goodProductList param is : [{}]", paramMap.toString());
// }
// 去除product_skn参数先,为了兼容
// 0、去除product_skn参数先,为了兼容
if (paramMap.containsKey("product_skn")) {
paramMap.remove("product_skn");
}
// 1、检测分页参数
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 30 : Integer.parseInt(paramMap.get("viewNum"));
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
... ... @@ -112,10 +108,6 @@ public class GoodProductSceneService {
// 3、再根据品类和品牌推荐SKN
List<String> recommondSkns = this.recommondSknsBySortAndBrandInfo(sortAndBrandInfo, paramMap, view_product_skns, cart_productskns, collect_product_skns);
// if (searchCommonHelper.isDebugUser(paramMap)) {
// logger.warn("goodProductList recommondSkns is : [{}]", recommondSkns);
// }
// 4、构造搜索参数
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = searchServiceHelper.constructFilterBuilder(paramMap, null);
... ...
... ... @@ -160,12 +160,15 @@ public class SearchLikeHelper {
*/
public BoolQueryBuilder genDefaultSearchLikeFilter(List<String> notProductSkns, boolean isGlobal) {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.mustNot(QueryBuilders.termsQuery("isSeckill", "Y"));
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.isFobbiden, 1));
boolFilter.must(QueryBuilders.termQuery("status", 1));
boolFilter.must(QueryBuilders.termQuery("isOutlets", 2));
boolFilter.must(QueryBuilders.termQuery("attribute", 1));
boolFilter.must(QueryBuilders.rangeQuery("storageNum").gte(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()) {
boolFilter.mustNot(QueryBuilders.termsQuery("productSkn", notProductSkns));
}
... ...
... ... @@ -11,12 +11,9 @@ import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -25,7 +22,6 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.SearchCacheFactory;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.SearchParamUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchCacheService;
import com.yoho.search.service.base.SearchCommonService;
... ... @@ -42,8 +38,6 @@ import com.yoho.search.service.helper.SearchCommonHelper;
@Service
public class SearchLikeInShopService {
private static final Logger logger = LoggerFactory.getLogger(SearchLikeInShopService.class);
@Autowired
private SearchCommonService searchCommonService;
@Autowired
... ... @@ -92,16 +86,12 @@ public class SearchLikeInShopService {
// 4、设置第一步SearchParam
List<SearchParam> searchParams = new ArrayList<SearchParam>();
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize));
for (SearchParam searchParam : searchParams) {
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
logger.warn("searchSourceBuilder is [{}]",searchSourceBuilder.toString());
}
// 5、从缓存中获取数据,有则直接返回
String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(searchLikeSearchCache, productIndexName, searchParams);
if (cacheObject != null) {
//return new SearchApiResult().setData(cacheObject);
return new SearchApiResult().setData(cacheObject);
}
// 6、获取搜索结果[截取条数]
... ... @@ -130,7 +120,7 @@ public class SearchLikeInShopService {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "10%"));
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%"));
searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns));
// 3、设置排序规则[按打分排序]
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
... ... @@ -152,8 +142,8 @@ public class SearchLikeInShopService {
// 1)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString("gender");
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
if (genderList != null) {
boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
if (genderList != null && !genderList.isEmpty()) {
boolFilter.must(QueryBuilders.termsQuery("gender",genderList));
}
// 2)设置品牌或店铺信息
Integer brandId = productInfoInEs.getInteger("brandId");
... ...
... ... @@ -119,7 +119,7 @@ public class SearchLikeNotInShopService {
// 1、设置SearchParam
SearchParam searchParam = new SearchParam();
// 2)设置query和filter
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, inSmallSort ? "40%" : "20%"));
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, inSmallSort ? "30%" : "20%"));
searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns, inSmallSort));
// 3、设置排序规则[按打分排序]
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
... ... @@ -141,8 +141,8 @@ public class SearchLikeNotInShopService {
// 1)设置此SKN相关的性别过滤条件
String gender = productInfoInEs.getString("gender");
List<String> genderList = searchLikeHelper.getGenderInfo(gender);
if (genderList != null) {
boolFilter.must(QueryBuilders.termsQuery("gender", genderList.toArray(new String[genderList.size()])));
if (genderList != null && !genderList.isEmpty()) {
boolFilter.must(QueryBuilders.termsQuery("gender", genderList));
}
// 2)设置品牌或店铺信息
Integer brandId = productInfoInEs.getInteger("brandId");
... ...
... ... @@ -263,11 +263,11 @@ public class SimilarProductServiceImpl extends BaseService implements ISimilarPr
private BoolQueryBuilder getDefaultBoolQueryBuilder() {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
// boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal,
// "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.termQuery(ProductIndexEsField.isOutlets, 2));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, 1));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
// 非断码
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.breakSizePercent).lt(50));
... ...
... ... @@ -241,10 +241,13 @@ public class SknImageVectorsServiceImpl implements ISknImageVectorsService, Appl
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.termQuery(ProductIndexEsField.isOutlets, 2));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, 1));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isOutlets, 2));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, productSkns));
return boolFilter;
}
... ...