Authored by Gino Zhang

增加【颜色+品类】、【风格+品类】的建议词

... ... @@ -20,7 +20,7 @@ public enum KeywordType {
ProductKeywordToken(5, 6, SuggestionConstants.PRODUCTKEYWORD_TOKEN_ENABLED_KEY),
BrandKeywordToken(6, 6, SuggestionConstants.BRANDKEYWORD_TOKEN_ENABLED_KEY),
SortNameWithOtherDetail(14, 3, SuggestionConstants.SORTNAME_ENABLED_KEY),
SortNameWithDetail(14, 3, SuggestionConstants.SORTNAME_ENABLED_KEY),
ProductName(8, 1, SuggestionConstants.PRODUCTNAME_ENABLED_KEY),
Customized(0, 1),
... ...
... ... @@ -19,11 +19,11 @@ import java.util.*;
import java.util.stream.Collectors;
/**
* 【颜色+品类】的搜索建议词,如【白色 卫衣
* 品类相关的组合词,【颜色+品类】、【风格+品牌】、【品类+性别
* Created by ginozhang on 2017/3/20.
*/
@Component
public class SortNameWithColorSuggestionDiscoverer extends AbstractSuggestionDiscoverer {
public class SortNameWithDetailSuggestionDiscoverer extends AbstractSuggestionDiscoverer {
@Autowired
private ProductSortService productSortService;
... ... @@ -45,6 +45,14 @@ public class SortNameWithColorSuggestionDiscoverer extends AbstractSuggestionDis
return keywordSet;
}
for (ProductSort productSort : productSortList) {
// 有一些sortName是用斜杠连接多个词(如[凉鞋/凉拖]),需要split处理一下
String sortName = productSort.getSortName();
for (String itemName : sortName.split("\\/")) {
keywordSet.addAll(buildSortNameWithGenderKeywords(itemName, productSort.getGender()));
}
}
SearchParam searchParam = new SearchParam();
searchParam.setSize(0);
searchParam.setFiter(QueryBuilders.termsQuery("status", 1));
... ... @@ -99,8 +107,30 @@ public class SortNameWithColorSuggestionDiscoverer extends AbstractSuggestionDis
return keywordSet;
}
private List<String> buildSortNameWithGenderKeywords(String itemName, String gender) {
List<String> resultList = new ArrayList<>();
if (gender != null) {
switch (gender) {
case "1":
// 男性
resultList.add(itemName + " 男");
break;
case "2":
// 女性
resultList.add(itemName + " 女");
break;
default:
// 通用
resultList.add(itemName + " 男");
resultList.add(itemName + " 女");
}
}
return resultList;
}
@Override
public KeywordType getKeywordType() {
return KeywordType.SortNameWithOtherDetail;
return KeywordType.SortNameWithDetail;
}
}
... ...
package com.yoho.search.consumer.suggests.discover;
import com.yoho.search.consumer.service.base.ProductSortService;
import com.yoho.search.consumer.suggests.common.KeywordType;
import com.yoho.search.dal.model.ProductSort;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 【品类+性别】的搜索建议词,如【卫衣 女】
* Created by ginozhang on 2017/3/20.
*/
@Component
public class SortNameWithGenderSuggestionDiscoverer extends AbstractSuggestionDiscoverer {
@Autowired
private ProductSortService productSortService;
@Override
public int count() {
return productSortService.count();
}
@Override
public Set<String> getSuggestWordSet(int pageNo, int batchSize) {
Set<String> sortNameSet = new HashSet<>(batchSize);
int start = (pageNo - 1) * batchSize;
List<ProductSort> productSortList = productSortService.getPageLists(start, batchSize);
if (CollectionUtils.isNotEmpty(productSortList)) {
for (ProductSort productSort : productSortList) {
// 有一些sortName是用斜杠连接多个词(如[凉鞋/凉拖]),需要split处理一下
String sortName = productSort.getSortName();
for (String itemName : sortName.split("\\/")) {
sortNameSet.addAll(buildSortNameWithGenderKeywords(itemName, productSort.getGender()));
}
}
}
return sortNameSet;
}
private List<String> buildSortNameWithGenderKeywords(String itemName, String gender) {
List<String> resultList = new ArrayList<>();
if (gender != null) {
switch (gender) {
case "1":
// 男性
resultList.add(itemName + " 男");
break;
case "2":
// 女性
resultList.add(itemName + " 女");
break;
default:
// 通用
resultList.add(itemName + " 男");
resultList.add(itemName + " 女");
}
}
return resultList;
}
@Override
public KeywordType getKeywordType() {
return KeywordType.SortNameWithOtherDetail;
}
}