Authored by 胡古飞

ufo二手列表开发

... ... @@ -179,34 +179,9 @@ public class SearchRequestParams {
//brand index field
public static final String BRANDINDEX_ID = "brandIds";
//ufo
public static final String UFOPRODUCTINDEX_SEARCH_QUERY = "query";
public static final String UFOPRODUCTINDEX_PARAM_ID = "id";
public static final String UFOPRODUCTINDEX_PARAM_NOT_ID = "not_id";
public static final String UFOPRODUCTINDEX_PARAM_MAXSORT = "maxSort";
public static final String UFOPRODUCTINDEX_PARAM_MIDSORT = "midSort";
public static final String UFOPRODUCTINDEX_PARAM_GENDER = "gender";
public static final String UFOPRODUCTINDEX_PARAM_BRAND = "brand";
public static final String UFOPRODUCTINDEX_PARAM_NOT_BRAND = "not_brand";
public static final String UFOPRODUCTINDEX_PARAM_SERIES = "series";
public static final String UFOPRODUCTINDEX_PARAM_SIZE = "size";
public static final String UFOPRODUCTINDEX_PARAM_COLOR = "color";
public static final String UFOPRODUCTINDEX_PARAM_POOL = "pool";
// 是否包含UFO
public static final String PARAM_SEARCH_CONTAIN_UFO = "contain_ufo";
// 是否只过滤UFO
public static final String PARAM_SEARCH_IS_UFO = "is_ufo";
// ufo 发售日历
public static final String UFO_PARAM_START_TIME = "startTime";
public static final String UFO_PARAM_END_TIME = "endTime";
// ufo 融入有货
public static final String UFO_PARAM_SEARCH_CONTAIN_YOHO = "contain_yoho";
// rank类型
public static final String UFO_PARAM_RANK_TYPE = "rankType";
// ufo发售日历 商品类型
public static final String UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE = "product_type";
// ufo过滤独家商品 ufo鉴定服务用
public static final String UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE = "isFilterLimitSale";
}
... ...
package com.yoho.search.common;
public class UfoSearchRequestParams {
//分页参数
public static final String UFO_PARAM_SEARCH_PAGE = "page";//页码
public static final String UFO_PARAM_SEARCH_VIEWNUM = "viewNum"; // 数量
//ufo
public static final String UFOPRODUCTINDEX_SEARCH_QUERY = "query";
public static final String UFOPRODUCTINDEX_PARAM_ID = "id";
public static final String UFOPRODUCTINDEX_PARAM_NOT_ID = "not_id";
public static final String UFOPRODUCTINDEX_PARAM_MAXSORT = "maxSort";
public static final String UFOPRODUCTINDEX_PARAM_MIDSORT = "midSort";
public static final String UFOPRODUCTINDEX_PARAM_GENDER = "gender";
public static final String UFOPRODUCTINDEX_PARAM_BRAND = "brand";
public static final String UFOPRODUCTINDEX_PARAM_NOT_BRAND = "not_brand";
public static final String UFOPRODUCTINDEX_PARAM_SERIES = "series";
public static final String UFOPRODUCTINDEX_PARAM_SIZE = "size";
public static final String UFOPRODUCTINDEX_PARAM_COLOR = "color";
public static final String UFOPRODUCTINDEX_PARAM_POOL = "pool";
// ufo发售日历 商品类型
public static final String UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE = "product_type";
public static final String UFO_PARAM_START_TIME = "startTime";
public static final String UFO_PARAM_END_TIME = "endTime";
// ufo过滤独家商品 ufo鉴定服务用
public static final String UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE = "isFilterLimitSale";
// rank类型
public static final String UFO_PARAM_RANK_TYPE = "rankType";
// ufo 融入有货
public static final String UFO_PARAM_SEARCH_CONTAIN_YOHO = "contain_yoho";
}
... ...
package com.yoho.search.restapi.ufo;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ufo.UfoBrandListService;
import com.yoho.search.service.scene.ufo.UfoSecondhandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
@RestController
public class UfoSecondhandController {
@Autowired
private UfoSecondhandService ufoSecondhandService;
@RequestMapping(method = RequestMethod.GET, value = "/ufo/secondhand/productList")
public SearchApiResult secondhandProductList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return ufoSecondhandService.secondHandProductList(paramMap);
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.search.base.constants.SearchPageIdDefine;
import com.yoho.search.base.utils.*;
import com.yoho.search.common.SearchServiceConfiger;
import com.yoho.search.base.utils.SearchPageUtils;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.utils.SearchFieldUtils;
import com.yoho.search.common.SearchDynamicConfigService;
import com.yoho.search.common.SearchRequestParams;
... ... @@ -186,27 +187,12 @@ public class SearchCommonHelper {
return true;
}
/**
* 判断UFO搜索是否需要包含YOHO
*/
public boolean containYoho(Map<String, String> paramMap) {
// 1、如果总开关关了,则肯定不包含yoho商品
boolean ufoContainYoho = searchDynamicConfigService.ufoContainYoho();
if (!ufoContainYoho) {
return false;
}
// 2、如果前端传来的参数中不包含contain_yoho!=Y,则不包含yoho的
if (!paramMap.containsKey(SearchRequestParams.UFO_PARAM_SEARCH_CONTAIN_YOHO) || !"Y".equals(paramMap.get(SearchRequestParams.UFO_PARAM_SEARCH_CONTAIN_YOHO))) {
return false;
}
return true;
}
/**
* 判断UFO搜索是否需要包含独家商品
*/
public boolean filterUfoLimitSale(Map<String, String> paramMap) {
if (paramMap.containsKey(SearchRequestParams.UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE) && "Y".equals(paramMap.get(SearchRequestParams.UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE))) {
if (paramMap.containsKey(UfoSearchRequestParams.UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE) && "Y".equals(paramMap.get(UfoSearchRequestParams.UFO_PARAM_SEARCH_IS_FILTER_LIMIT_SALE))) {
return true;
}
return false;
... ...
package com.yoho.search.service.helper;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.SearchConvertUtils;
import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.common.BaseService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.SearchServiceConfiger;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.SearchConvertUtils;
import com.yoho.search.common.*;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import com.yoho.search.core.es.model.SearchField;
import com.yoho.search.core.es.utils.SearchFieldUtils;
... ... @@ -34,6 +32,8 @@ public class UfoSearchQueryHelper extends BaseService {
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchServiceConfiger configurer;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
private Set<String> orderValues = new HashSet<>();
... ... @@ -63,20 +63,20 @@ public class UfoSearchQueryHelper extends BaseService {
public BoolQueryBuilder constructFilterBuilder(Map<String, String> paramMap) throws Exception {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
//参数过滤
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
this.addMustNotIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_ID, UfoProductIndexEsField.id);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_MAXSORT, UfoProductIndexEsField.maxSortId);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_MIDSORT, UfoProductIndexEsField.midSortId);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_GENDER, UfoProductIndexEsField.gender);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_BRAND, UfoProductIndexEsField.brandId);
this.addMustNotIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_BRAND, UfoProductIndexEsField.brandId);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_SERIES, UfoProductIndexEsField.seriesId);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_SIZE, UfoProductIndexEsField.sizeIds);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_COLOR, UfoProductIndexEsField.colorIds);
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, UfoProductIndexEsField.poolIds);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_ID, UfoProductIndexEsField.id);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_MAXSORT, UfoProductIndexEsField.maxSortId);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_MIDSORT, UfoProductIndexEsField.midSortId);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_GENDER, UfoProductIndexEsField.gender);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_BRAND, UfoProductIndexEsField.brandId);
this.addMustNotIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_NOT_BRAND, UfoProductIndexEsField.brandId);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_SERIES, UfoProductIndexEsField.seriesId);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_SIZE, UfoProductIndexEsField.sizeIds);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_COLOR, UfoProductIndexEsField.colorIds);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, UfoProductIndexEsField.poolIds);
//是否包含有货
if (!searchCommonHelper.containYoho(paramMap)) {
if (!this.containYoho(paramMap)) {
boolFilter.mustNot(QueryBuilders.termQuery(UfoProductIndexEsField.isYoho, "Y"));
}
... ... @@ -92,9 +92,25 @@ public class UfoSearchQueryHelper extends BaseService {
return boolFilter;
}
/**
* 判断UFO搜索是否需要包含YOHO
*/
private boolean containYoho(Map<String, String> paramMap) {
// 1、如果总开关关了,则肯定不包含yoho商品
boolean ufoContainYoho = searchDynamicConfigService.ufoContainYoho();
if (!ufoContainYoho) {
return false;
}
// 2、如果前端传来的参数中不包含contain_yoho!=Y,则不包含yoho的
if (!paramMap.containsKey(UfoSearchRequestParams.UFO_PARAM_SEARCH_CONTAIN_YOHO) || !"Y".equals(paramMap.get(UfoSearchRequestParams.UFO_PARAM_SEARCH_CONTAIN_YOHO))) {
return false;
}
return true;
}
public BoolQueryBuilder constructFilterBuilderIdFilter(Map<String, String> paramMap) throws Exception {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
this.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
this.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID, UfoProductIndexEsField.id);
return boolFilter;
}
... ... @@ -117,11 +133,11 @@ public class UfoSearchQueryHelper extends BaseService {
public QueryBuilder constructQueryBuilder(Map<String, String> paramMap) {
// 0、处理查询关键字
String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, SearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY);
String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY);
if (StringUtils.isBlank(query)) {
return QueryBuilders.matchAllQuery();
}
paramMap.put(SearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, query);
paramMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, query);
// 1、处理查询中包含性别的情况
searchCommonHelper.dealKeywordOfGender(query, paramMap);
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -49,7 +50,7 @@ public class UfoFavoriteService {
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID))) {
if (StringUtils.isBlank(paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID))) {
return new SearchApiResult().setCode(400).setMessage("id参数必传");
}
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
... ... @@ -82,7 +83,7 @@ public class UfoFavoriteService {
dataMap.put("page_total", searchResult.getTotalPage());
Map<String, Map<String, Object>> productReturnInfoMap = returnInfoList.stream().collect(Collectors.toMap(p -> p.get("id").toString(), p -> p));
List<Map<String, Object>> productReturnInfoListSorted = new ArrayList<>(productReturnInfoMap.size());
List<String> idList = Arrays.asList(paramMap.get(SearchRequestParams.UFOPRODUCTINDEX_PARAM_ID).split(","));
List<String> idList = Arrays.asList(paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_ID).split(","));
for (String id : idList) {
Map<String, Object> sknInfo = productReturnInfoMap.get(id);
if (sknInfo != null) {
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
... ... @@ -138,7 +139,7 @@ public class UfoFuzzySceneService {
public SearchParam buildSearchParamForProductCodeSearch(Map<String, String> paramMap, int pageSize, int page) throws Exception {
SearchParam searchParam = new SearchParam();
// QUERY
String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, SearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY);
String query = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY);
if (StringUtils.isBlank(query)) {
searchParam.setQuery(QueryBuilders.matchAllQuery());
} else {
... ...
... ... @@ -6,7 +6,7 @@ import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -53,7 +53,7 @@ public class UfoPoolSceneService {
public SearchApiResult productList(Map<String, String> paramMap) {
try {
// 1、参数校验
if (!paramMap.containsKey(SearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL)) {
if (!paramMap.containsKey(UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL)) {
return new SearchApiResult().setCode(400).setMessage("缺少必传pool参数");
}
int page = MapUtils.getIntValue(paramMap, "page", 1);
... ... @@ -137,7 +137,7 @@ public class UfoPoolSceneService {
private int getPoolOrderBy(Map<String, Object> map, Map<String, String> paramMap) {
try {
String inputPoolId = MapUtils.getString(paramMap, SearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, "");
String inputPoolId = MapUtils.getString(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_PARAM_POOL, "");
if (StringUtils.isBlank(inputPoolId)) {
return 0;
}
... ...
... ... @@ -10,6 +10,7 @@ import com.yoho.search.base.utils.date.SearchDateUtils;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -94,14 +95,14 @@ public class UfoSaleCalendarNewService {
private BoolQueryBuilder constructSaleCalendarFilterBuilder(Map<String, String> paramMap) {
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE, CsSearchSalesCalendarIndexEsField.productType);
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE, CsSearchSalesCalendarIndexEsField.productType);
//硬过滤
boolFilter.must(QueryBuilders.termQuery(CsSearchSalesCalendarIndexEsField.ufoIsSynCalender, 1));
boolFilter.must(QueryBuilders.termQuery(CsSearchSalesCalendarIndexEsField.ufoDelStatus, 0));
boolFilter.must(QueryBuilders.termQuery(CsSearchSalesCalendarIndexEsField.ufoShelveStatus, 1));
//发售时间过滤
int startTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_START_TIME, 0);
int endTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_END_TIME, 0);
int startTime = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_START_TIME, 0);
int endTime = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_END_TIME, 0);
boolFilter.must(QueryBuilders.rangeQuery(CsSearchSalesCalendarIndexEsField.salesTime).gte(startTime));
boolFilter.must(QueryBuilders.rangeQuery(CsSearchSalesCalendarIndexEsField.salesTime).lte(endTime));
return boolFilter;
... ... @@ -228,7 +229,7 @@ public class UfoSaleCalendarNewService {
searchParam.setSize(0);
//1.构造过滤
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, SearchRequestParams.UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE, CsSearchSalesCalendarIndexEsField.productType);
ufoSearchQueryHelper.addMustIntTermsQuery(boolFilter, paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_SALE_CALENDAR_PRODUCT_TYPE, CsSearchSalesCalendarIndexEsField.productType);
//硬过滤
boolFilter.must(QueryBuilders.termQuery(CsSearchSalesCalendarIndexEsField.ufoIsSynCalender, 1));
boolFilter.must(QueryBuilders.termQuery(CsSearchSalesCalendarIndexEsField.ufoDelStatus, 0));
... ...
... ... @@ -2,12 +2,12 @@ package com.yoho.search.service.scene.ufo;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.utils.date.SearchDateUtils;
import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.base.utils.date.SearchDateUtils;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -90,8 +90,8 @@ public class UfoSaleCalendarService {
boolFilter.must(QueryBuilders.termQuery(UfoProductIndexEsField.shelveStatus, 1));
boolFilter.mustNot(QueryBuilders.termQuery(UfoProductIndexEsField.isYoho, "Y"));
//发售时间过滤
int startTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_START_TIME, 0);
int endTime = MapUtils.getIntValue(paramMap, SearchRequestParams.UFO_PARAM_END_TIME, 0);
int startTime = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_START_TIME, 0);
int endTime = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_END_TIME, 0);
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).gte(startTime));
boolFilter.must(QueryBuilders.rangeQuery(UfoProductIndexEsField.saleTime).lte(endTime));
return boolFilter;
... ...
package com.yoho.search.service.scene.ufo;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.base.utils.SearchConvertUtils;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
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.Component;
import java.util.*;
/**
* 二手列表通用
*/
@Component
public class UfoSecondhandService {
private static final Logger logger = LoggerFactory.getLogger(UfoSecondhandService.class);
@Autowired
private SearchCommonService searchCommonService;
//@SearchCacheAble(cacheName = "SECONDEHAND_PRODUCT_LIST", cacheInMinute = CacheInMinute.Minute_UFO, includeParams = {"page", "viewNum", "preSaleFlag"})
public SearchApiResult secondHandProductList(Map<String, String> paramMap) {
try {
// 1、参数校验
int page = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_PAGE, 1);
int pageSize = MapUtils.getIntValue(paramMap, UfoSearchRequestParams.UFO_PARAM_SEARCH_VIEWNUM, 10);
pageSize = Math.min(pageSize, 100);
if (page < 1 || pageSize < 0 || page * pageSize > 100000) {
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
}
// 2、构造SearchParam
SearchParam searchParam = new SearchParam();
BoolQueryBuilder boolFilter = this.builderFilter(paramMap);
searchParam.setFiter(boolFilter);
searchParam.setQuery(QueryBuilders.matchAllQuery());
// 3、构建分页参数
searchParam.setSize(pageSize);
searchParam.setOffset((page - 1) * pageSize);
// 4、设置排序字段
searchParam.setSortBuilders(this.builderSortBuilders(paramMap));
// 5、执行搜索
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_STORAGE_PRICE, searchParam);
List<Map<String, Object>> skupResultList = new ArrayList<>();
for (Map<String, Object> productEsSource : searchResult.getResultList()) {
skupResultList.add(this.buildSkupResult(productEsSource));
}
// 6、构造返回结果
JSONObject dataMap = new JSONObject();
dataMap.put("total", searchResult.getTotal());
dataMap.put("page", searchResult.getPage());
dataMap.put("page_size", pageSize);
dataMap.put("page_total", searchResult.getTotalPage());
dataMap.put("skup_list", skupResultList);
return new SearchApiResult().setData(dataMap);
} catch (Exception e) {
return SearchApiResultUtils.defaultErrorSearchApiResult(logger, e);
}
}
private Map<String, Object> buildSkupResult(Map<String, Object> map) {
Map<String, Object> skupResult = new HashMap<>();
skupResult.put("skup", MapUtils.getIntValue(map, "skup", 0));
skupResult.put("product_id", MapUtils.getIntValue(map, "productId", 0));
skupResult.put("product_name", "待处理");
skupResult.put("goods_id", MapUtils.getIntValue(map, "goodsId", 0));
skupResult.put("storage_id", MapUtils.getIntValue(map, "storageId", 0));
skupResult.put("seller_uid", MapUtils.getIntValue(map, "sellerUid", 0));
//价格
Double price = MapUtils.getDouble(map, "price");
skupResult.put("price", price == null || price == -1d ? null : price);
skupResult.put("down_price", "待处理");
skupResult.put("status", MapUtils.getIntValue(map, "status", 0));
skupResult.put("is_hide", MapUtils.getIntValue(map, "isHide", 0));
skupResult.put("pre_sale_flag", MapUtils.getIntValue(map, "preSaleFlag", 0));
skupResult.put("region", MapUtils.getIntValue(map, "region", 0));
//图片
String secondhand_image = MapUtils.getString(map, "secondhandImage","");
skupResult.put("secondhand_image", secondhand_image == null ? "" : secondhand_image);
//尺码
Integer size_id = MapUtils.getIntValue(map, "sizeId",0);
skupResult.put("size_id", size_id == null || size_id<=0 ? 0 : size_id);
String sizeName = MapUtils.getString(map, "sizeName","");
skupResult.put("size_name", sizeName == null ? "" : sizeName);
return skupResult;
}
private BoolQueryBuilder builderFilter(Map<String, String> paramMap) {
BoolQueryBuilder filter = QueryBuilders.boolQuery();
List<Integer> preSaleFlags = SearchConvertUtils.stringToIntList(MapUtils.getString(paramMap, "preSaleFlag"), ",");
if (CollectionUtils.isNotEmpty(preSaleFlags)) {
filter.must(QueryBuilders.termsQuery("preSaleFlag", preSaleFlags));
} else {
filter.must(QueryBuilders.termsQuery("preSaleFlag", Arrays.asList(5, 6)));
}
filter.must(QueryBuilders.termQuery("isHide", 0));
filter.must(QueryBuilders.termQuery("status", 1));
return filter;
}
private List<SortBuilder<?>> builderSortBuilders(Map<String, String> paramMap) {
List<SortBuilder<?>> sortList = new ArrayList<>();
sortList.add(SortBuilders.fieldSort("id").order(SortOrder.DESC));
return sortList;
}
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
... ... @@ -79,7 +80,7 @@ public class UfoSelectionListService {
// 调用ES
SearchResult searchResult = searchCommonService.doSearch(productIndexName, searchParam);
// 正常查询结果为空,调用模糊纠错货号的逻辑去查
if (searchResult.getTotal() == 0 && paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_QUERY)) {
if (searchResult.getTotal() == 0 && paramMap.containsKey(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY)) {
searchParam = ufoFuzzySceneService.buildSearchParamForProductCodeSearch(paramMap, 0, 0);
searchParam.setAggregationBuilders(this.getAllAggregationBuilders(paramMap));
searchParam.setSize(0);
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.search.base.constants.ISearchConstants;
import com.yoho.search.base.constants.ProductIndexEsField;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.common.utils.SearchKeyWordUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
... ... @@ -52,7 +53,7 @@ public class UfoSuggestService {
logger.info("[func=suggest][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
// 1)关键参数验证
String keyword = SearchKeyWordUtils.getUfoParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_QUERY);
String keyword = SearchKeyWordUtils.getUfoParamKeyword(paramMap, UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY);
if (StringUtils.isBlank(keyword)) {
return new SearchApiResult().setCode(400).setMessage("关键字[query]参数为空!");
}
... ... @@ -60,8 +61,7 @@ public class UfoSuggestService {
if (keyword.length() > 30) {
return new SearchApiResult().setCode(400).setMessage("关键字[query]参数非法!");
}
paramMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, keyword);
paramMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, keyword);
// 2)构建查询参数
SearchParam searchParam = this.buildSuggestSearchParam(paramMap);
... ... @@ -101,7 +101,7 @@ public class UfoSuggestService {
* 通过纠错的方式,查询建议词列表
*/
private SearchResult suggestByCorrectSpelling(Map<String, String> paramMap) {
String keyword = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY).toLowerCase();
String keyword = paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY).toLowerCase();
String newKeyword = (String) this.correctSpellingKeyword(paramMap).getData();
if (StringUtils.isEmpty(newKeyword)) {
return null;
... ... @@ -110,7 +110,7 @@ public class UfoSuggestService {
logger.info("Switch the suggest keyword from [{}] to [{}].", keyword, newKeyword);
Map<String, String> newParamMap = new HashMap<>(paramMap.size());
newParamMap.putAll(paramMap);
newParamMap.put(SearchRequestParams.PARAM_SEARCH_QUERY, newKeyword);
newParamMap.put(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY, newKeyword);
SearchParam newSearchParam = this.buildSuggestSearchParam(newParamMap);
return searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_SUGGEST, newSearchParam);
} catch (Exception e) {
... ... @@ -123,7 +123,7 @@ public class UfoSuggestService {
* 构建查询参数
*/
private SearchParam buildSuggestSearchParam(Map<String, String> paramMap) {
String keyword = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY).toLowerCase();
String keyword = paramMap.get(UfoSearchRequestParams.UFOPRODUCTINDEX_SEARCH_QUERY).toLowerCase();
SearchParam searchParam = new SearchParam();
QueryBuilder query = QueryBuilders.boolQuery().should(QueryBuilders.prefixQuery("keyword", keyword)).should(QueryBuilders.prefixQuery("keyword.keyword_pinyin", keyword))
.should(QueryBuilders.prefixQuery("keyword.keyword_jianpin", keyword));
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.search.base.constants.UfoProductIndexEsField;
import com.yoho.search.cache.CacheInMinute;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.common.SearchRequestParams;
import com.yoho.search.common.UfoSearchRequestParams;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -87,7 +88,7 @@ public class UfoUVScoreSceneService {
searchParam.setSize(pageSize);
searchParam.setOffset((page - 1) * pageSize);
// 设置排序字段
String rankType = MapUtils.getString(paramMap, SearchRequestParams.UFO_PARAM_RANK_TYPE, "a");
String rankType = MapUtils.getString(paramMap, UfoSearchRequestParams.UFO_PARAM_RANK_TYPE, "a");
this.constructSortBuilder(searchParam, rankType);
// 设置返回的结果
List<String> includeFields = ufoProductIndexBaseService.getUfoProductIndexIncludeFields();
... ...