|
|
package com.yoho.search.service.servicenew.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
...
|
...
|
@@ -9,6 +10,9 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; |
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|
|
import org.elasticsearch.search.sort.SortBuilder;
|
|
|
import org.elasticsearch.search.sort.SortBuilders;
|
|
|
import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -59,7 +63,7 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
|
|
|
}
|
|
|
if (pageSize > 50) {
|
|
|
pageSize = 100;
|
|
|
pageSize = 50;
|
|
|
}
|
|
|
// 用来做加分
|
|
|
int brand_id = (int) productInfo.get("brand_id");
|
...
|
...
|
@@ -114,8 +118,10 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
boolFilter.mustNot(QueryBuilders.termsQuery("isGlobal", "Y"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
|
|
|
// 4、设置排序规则
|
|
|
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
|
|
|
// 4、设置排序规则[支持持按打分排序]
|
|
|
List<SortBuilder>sortBuilders = new ArrayList<SortBuilder>();
|
|
|
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
|
|
|
searchParam.setSortBuilders(sortBuilders);
|
|
|
|
|
|
// 5、设置分页
|
|
|
searchParam.setPage(page);
|
...
|
...
|
@@ -133,14 +139,31 @@ public class SearchLikeServiceImpl implements ISearchLikeService { |
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
SearchApiResult searchApiResult = new SearchApiResult();
|
|
|
dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", searchParam.getSize());
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
|
|
|
long total = searchResult.getTotal();
|
|
|
if(total>300){
|
|
|
total = 300;
|
|
|
}
|
|
|
dataMap.put("total", total);
|
|
|
dataMap.put("page", page);
|
|
|
dataMap.put("page_size", pageSize);
|
|
|
dataMap.put("page_total", this.getPageTotal(total, pageSize));
|
|
|
dataMap.put("product_info", productInfo);
|
|
|
dataMap.put("product_list", searchServiceHelper.getProductMapList(searchResult.getResultList()));
|
|
|
searchCacheService.addJSONObjectToCache(cacheEnum, productIndexName, searchParam, dataMap);
|
|
|
return searchApiResult.setData(dataMap);
|
|
|
}
|
|
|
|
|
|
private long getPageTotal(long total,int pageSize){
|
|
|
if(pageSize<=0){
|
|
|
return total;
|
|
|
}
|
|
|
if(total % pageSize==0){
|
|
|
return total / pageSize;
|
|
|
}else{
|
|
|
return total / pageSize + 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private JSONObject getProductSknInfo(String productSkn) {
|
|
|
SearchParam searchParam = new SearchParam();
|
...
|
...
|
|