...
|
...
|
@@ -21,372 +21,390 @@ import java.util.Map; |
|
|
@Component
|
|
|
public class SearchCommonHelper {
|
|
|
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService dynamicConfig;
|
|
|
@Autowired
|
|
|
private SearchServiceConfiger searchServiceConfiger;
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
|
|
|
public int getPage(Map<String, String> paramMap) {
|
|
|
return StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
}
|
|
|
|
|
|
public int getPageSize(Map<String, String> paramMap) {
|
|
|
return StringUtils.isBlank(paramMap.get("viewNum")) ? 60 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
}
|
|
|
|
|
|
public boolean isPersionalScene(Map<String, String> paramMap) {
|
|
|
if (!searchDynamicConfigService.openPersonalized()) {
|
|
|
return false;
|
|
|
}
|
|
|
if (this.hasUid(paramMap) && this.isOrderEmpty(paramMap)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public long getTotalPage(long total, int size) {
|
|
|
return PageUtils.getTotalPage(total,size);
|
|
|
}
|
|
|
|
|
|
public int getUid(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
return MapUtils.getIntValue(paramMap, "uid", 0);
|
|
|
} catch (Exception e) {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public boolean hasUid(Map<String, String> paramMap) {
|
|
|
return this.getUid(paramMap) > 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 是否是默认的模糊搜索
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isFuzzySearchPageDefault(Map<String, String> paramMap) {
|
|
|
String query = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
|
|
|
if (StringUtils.isBlank(query)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (!SearchPageIdDefine.PAGE_ID_SEARCH.equalsIgnoreCase(pageId)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要开启个性化
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNeedPersonalSearch(Map<String, String> paramMap) {
|
|
|
// 从 zk中动态获取是否使用个性化
|
|
|
boolean openPersonalized = dynamicConfig.openPersonalized();
|
|
|
if (!openPersonalized) {
|
|
|
return false;
|
|
|
}
|
|
|
if(!this.hasUid(paramMap)){
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要对某个SKN加分
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isFirstProductSknSearch(Map<String, String> paramMap) {
|
|
|
String first_productskn = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
if (StringUtils.isBlank(first_productskn)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要对频道降分
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
|
|
|
String physicalChannel = paramMap.get(SearchRequestParams.PARAM_SEARCH_PHYSICAL_CHANNEL);
|
|
|
if (StringUtils.isBlank(physicalChannel)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!isFuzzySearchPageDefault(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!dynamicConfig.isDeScorePhysicalChannelOpen()) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断搜索是否需要包含全球购
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean containGlobal(Map<String, String> paramMap) {
|
|
|
// 1、如果总开关关了,则肯定不包含全球购商品
|
|
|
boolean containglobal = dynamicConfig.containglobal();
|
|
|
if (!containglobal) {
|
|
|
return false;
|
|
|
}
|
|
|
// 2、如果前端传来的参数中不包含contain_global!=Y,则不包含全球购
|
|
|
if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL))) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 当前查询的关键字是否是skn
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isQuerySknOrSku(String keyword) {
|
|
|
try {
|
|
|
String key = "";
|
|
|
if (keyword.contains(" ")) {
|
|
|
key = keyword.split(" ")[0];
|
|
|
} else if (keyword.contains(",")) {
|
|
|
key = keyword.split(",")[0];
|
|
|
} else if (keyword.contains("+")) {
|
|
|
key = keyword.split("\\+")[0];
|
|
|
}
|
|
|
if ((CharUtils.isNumeric(keyword) && keyword.length() >= 6) || (CharUtils.isNumeric(key) && key.length() >= 6)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
} catch (Exception e) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从搜索的关键词中提取出skn信息
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Integer> getQuerySknList(String keyword) {
|
|
|
List<Integer> sknList = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
String[] keys = null;
|
|
|
if (keyword.contains(" ")) {
|
|
|
keys = keyword.split(" ");
|
|
|
} else if (keyword.contains(",")) {
|
|
|
keys = keyword.split(",");
|
|
|
} else if (keyword.contains("+")) {
|
|
|
keys = keyword.split("\\+");
|
|
|
}
|
|
|
|
|
|
if (keys != null && keys.length > 0) {
|
|
|
for (String key : keys) {
|
|
|
if (CharUtils.isNumeric(key) && key.length() >= 7) {
|
|
|
sknList.add(Integer.valueOf(key));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return sknList;
|
|
|
} catch (Exception e) {
|
|
|
return sknList;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecPage(Map<String, String> paramMap) {
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_NEW)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着默认页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecPageDefault(Map<String, String> paramMap) {
|
|
|
if (!isNewRecPage(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着页的人气排序
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecHeatValueDescSearch(Map<String, String> paramMap) {
|
|
|
if (!this.isNewRecPage(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
if (StringUtils.isBlank(order)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!order.contains("heatValue")) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否未传order
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isOrderEmpty(Map<String, String> paramMap) {
|
|
|
String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
if (!StringUtils.isBlank(order)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是品类列表的默认页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isSortPageDefault(Map<String, String> paramMap) {
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_SORT)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 关键字中含性别,则加上性别的过滤条件
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @param paramMap
|
|
|
*/
|
|
|
public void dealKeywordOfGender(String keyword, Map<String, String> paramMap) {
|
|
|
// 如果参数中已经包含了性别,则不处理
|
|
|
String gender = paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER);
|
|
|
if (StringUtils.isNotBlank(gender)) {
|
|
|
return;
|
|
|
}
|
|
|
// 对男女关键字做特殊处理
|
|
|
boolean cotainBoy = keyword.contains("男");
|
|
|
boolean cotainGirl = keyword.contains("女");
|
|
|
// 对性别做特殊处理
|
|
|
if (cotainBoy && !cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,3");
|
|
|
return;
|
|
|
}
|
|
|
if (!cotainBoy && cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "2,3");
|
|
|
return;
|
|
|
}
|
|
|
if (cotainBoy && cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,2,3");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取MultiMatchQueryBuilder的类型
|
|
|
public MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() {
|
|
|
String configMultiMatchQueryType = searchServiceConfiger.getSearchMultiMatchQueryType();
|
|
|
return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造活动相关的过滤条件
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getActivitiesTermsBuilder(Map<String, String> paramMap) {
|
|
|
// 增加活动模板相关的过滤条件
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_TEMP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP))) {
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.template_id", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP)));
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_REC) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC))) {
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.is_recommend", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC)));
|
|
|
}
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS))) {
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.status", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS)));
|
|
|
}
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造商品池相关的过滤条件
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getPoolIdTermsBuilder(Map<String, String> paramMap) {
|
|
|
// 增加商品池相关的过滤条件
|
|
|
if (paramMap.containsKey("filter_poolId") && StringUtils.isNotBlank("filter_poolId")) {
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("pools.pool_id", paramMap.get("filter_poolId")));
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 自定义标签过滤
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
|
|
|
if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
|
|
|
int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService dynamicConfig;
|
|
|
@Autowired
|
|
|
private SearchServiceConfiger searchServiceConfiger;
|
|
|
@Autowired
|
|
|
private SearchDynamicConfigService searchDynamicConfigService;
|
|
|
|
|
|
public int getPage(Map<String, String> paramMap) {
|
|
|
return StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
}
|
|
|
|
|
|
public int getPageSize(Map<String, String> paramMap) {
|
|
|
return StringUtils.isBlank(paramMap.get("viewNum")) ? 60 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
}
|
|
|
|
|
|
public boolean isPersionalScene(Map<String, String> paramMap) {
|
|
|
if (!searchDynamicConfigService.openPersonalized()) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (this.hasUid(paramMap)) {
|
|
|
return true;
|
|
|
}
|
|
|
if (this.hasUdid(paramMap)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
public long getTotalPage(long total, int size) {
|
|
|
return PageUtils.getTotalPage(total, size);
|
|
|
}
|
|
|
|
|
|
public int getUid(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
return MapUtils.getIntValue(paramMap, "uid", 0);
|
|
|
} catch (Exception e) {
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public String getUdid(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
return MapUtils.getString(paramMap, "udid", "");
|
|
|
} catch (Exception e) {
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public boolean hasUid(Map<String, String> paramMap) {
|
|
|
return this.getUid(paramMap) > 0;
|
|
|
}
|
|
|
|
|
|
public boolean hasUdid(Map<String, String> paramMap) {
|
|
|
return StringUtils.isBlank(this.getUdid(paramMap))?false:true;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 是否是默认的模糊搜索
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isFuzzySearchPageDefault(Map<String, String> paramMap) {
|
|
|
String query = paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY);
|
|
|
if (StringUtils.isBlank(query)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (!SearchPageIdDefine.PAGE_ID_SEARCH.equalsIgnoreCase(pageId)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要开启个性化
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNeedPersonalSearch(Map<String, String> paramMap) {
|
|
|
// 从 zk中动态获取是否使用个性化
|
|
|
boolean openPersonalized = dynamicConfig.openPersonalized();
|
|
|
if (!openPersonalized) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.hasUid(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要对某个SKN加分
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isFirstProductSknSearch(Map<String, String> paramMap) {
|
|
|
String first_productskn = paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_PRODUCRSKN);
|
|
|
if (StringUtils.isBlank(first_productskn)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否需要对频道降分
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
|
|
|
String physicalChannel = paramMap.get(SearchRequestParams.PARAM_SEARCH_PHYSICAL_CHANNEL);
|
|
|
if (StringUtils.isBlank(physicalChannel)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!isFuzzySearchPageDefault(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!dynamicConfig.isDeScorePhysicalChannelOpen()) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断搜索是否需要包含全球购
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean containGlobal(Map<String, String> paramMap) {
|
|
|
// 1、如果总开关关了,则肯定不包含全球购商品
|
|
|
boolean containglobal = dynamicConfig.containglobal();
|
|
|
if (!containglobal) {
|
|
|
return false;
|
|
|
}
|
|
|
// 2、如果前端传来的参数中不包含contain_global!=Y,则不包含全球购
|
|
|
if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_GLOBAL))) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 当前查询的关键字是否是skn
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isQuerySknOrSku(String keyword) {
|
|
|
try {
|
|
|
String key = "";
|
|
|
if (keyword.contains(" ")) {
|
|
|
key = keyword.split(" ")[0];
|
|
|
} else if (keyword.contains(",")) {
|
|
|
key = keyword.split(",")[0];
|
|
|
} else if (keyword.contains("+")) {
|
|
|
key = keyword.split("\\+")[0];
|
|
|
}
|
|
|
if ((CharUtils.isNumeric(keyword) && keyword.length() >= 6) || (CharUtils.isNumeric(key) && key.length() >= 6)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
} catch (Exception e) {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 从搜索的关键词中提取出skn信息
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Integer> getQuerySknList(String keyword) {
|
|
|
List<Integer> sknList = new ArrayList<>();
|
|
|
|
|
|
try {
|
|
|
String[] keys = null;
|
|
|
if (keyword.contains(" ")) {
|
|
|
keys = keyword.split(" ");
|
|
|
} else if (keyword.contains(",")) {
|
|
|
keys = keyword.split(",");
|
|
|
} else if (keyword.contains("+")) {
|
|
|
keys = keyword.split("\\+");
|
|
|
}
|
|
|
|
|
|
if (keys != null && keys.length > 0) {
|
|
|
for (String key : keys) {
|
|
|
if (CharUtils.isNumeric(key) && key.length() >= 7) {
|
|
|
sknList.add(Integer.valueOf(key));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return sknList;
|
|
|
} catch (Exception e) {
|
|
|
return sknList;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecPage(Map<String, String> paramMap) {
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_NEW)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着默认页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecPageDefault(Map<String, String> paramMap) {
|
|
|
if (!isNewRecPage(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是新品到着页的人气排序
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isNewRecHeatValueDescSearch(Map<String, String> paramMap) {
|
|
|
if (!this.isNewRecPage(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
if (StringUtils.isBlank(order)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!order.contains("heatValue")) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否未传order
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isOrderEmpty(Map<String, String> paramMap) {
|
|
|
String order = paramMap.get(SearchRequestParams.PARAM_SEARCH_ORDER);
|
|
|
if (!StringUtils.isBlank(order)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否是品类列表的默认页
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public boolean isSortPageDefault(Map<String, String> paramMap) {
|
|
|
String pageId = paramMap.get(SearchRequestParams.PARAM_SEARCH_PAGEID);
|
|
|
if (StringUtils.isBlank(pageId) || !pageId.equals(SearchPageIdDefine.PAGE_ID_SORT)) {
|
|
|
return false;
|
|
|
}
|
|
|
if (!this.isOrderEmpty(paramMap)) {
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 关键字中含性别,则加上性别的过滤条件
|
|
|
*
|
|
|
* @param keyword
|
|
|
* @param paramMap
|
|
|
*/
|
|
|
public void dealKeywordOfGender(String keyword, Map<String, String> paramMap) {
|
|
|
// 如果参数中已经包含了性别,则不处理
|
|
|
String gender = paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER);
|
|
|
if (StringUtils.isNotBlank(gender)) {
|
|
|
return;
|
|
|
}
|
|
|
// 对男女关键字做特殊处理
|
|
|
boolean cotainBoy = keyword.contains("男");
|
|
|
boolean cotainGirl = keyword.contains("女");
|
|
|
// 对性别做特殊处理
|
|
|
if (cotainBoy && !cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,3");
|
|
|
return;
|
|
|
}
|
|
|
if (!cotainBoy && cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "2,3");
|
|
|
return;
|
|
|
}
|
|
|
if (cotainBoy && cotainGirl) {
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GENDER, "1,2,3");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取MultiMatchQueryBuilder的类型
|
|
|
public MultiMatchQueryBuilder.Type getMultiMatchQueryBuilderType() {
|
|
|
String configMultiMatchQueryType = searchServiceConfiger.getSearchMultiMatchQueryType();
|
|
|
return SearchFieldUtils.getMultiMatchQueryBuilderType(configMultiMatchQueryType);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造活动相关的过滤条件
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getActivitiesTermsBuilder(Map<String, String> paramMap) {
|
|
|
// 增加活动模板相关的过滤条件
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_TEMP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP))) {
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.template_id", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_TEMP)));
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_REC) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC))) {
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.is_recommend", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_REC)));
|
|
|
}
|
|
|
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ACT_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS))) {
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("activities.status", paramMap.get(SearchRequestParams.PARAM_SEARCH_ACT_STATUS)));
|
|
|
}
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造商品池相关的过滤条件
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getPoolIdTermsBuilder(Map<String, String> paramMap) {
|
|
|
// 增加商品池相关的过滤条件
|
|
|
if (paramMap.containsKey("filter_poolId") && StringUtils.isNotBlank("filter_poolId")) {
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termQuery("pools.pool_id", paramMap.get("filter_poolId")));
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 自定义标签过滤
|
|
|
*
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
|
|
|
if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
|
|
|
int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
|
|
|
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
|
|
|
nestedBoolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));
|
|
|
return nestedBoolFilter;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
} |
...
|
...
|
|