|
|
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;
|
|
|
}
|
|
|
} |