...
|
...
|
@@ -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");
|
...
|
...
|
|