Authored by Gino Zhang

Merge branch 'zf_suggest_parametermake' into zf_smart_search2

# Conflicts:
#	service/src/main/java/com/yoho/search/consumer/service/base/ParameterMakeService.java
package com.yoho.search.dal;
import com.yoho.search.dal.model.ParameterMake;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -18,4 +19,8 @@ public interface ParameterMakeMapper {
int updateByPrimaryKey(ParameterMake record);
List<ParameterMake> getAll();
int selectTotalCount();
List<ParameterMake> selectPageLists(@Param(value="offset")Integer offset, @Param(value="pageSize")Integer pageSize);
}
\ No newline at end of file
... ...
... ... @@ -92,4 +92,12 @@
<include refid="Base_Column_List" />
from parameter_make
</select>
<select id="selectTotalCount" resultType="java.lang.Integer" timeout="20000">
SELECT count(1) FROM parameter_make
</select>
<select id="selectPageLists" resultMap="BaseResultMap" timeout="20000">
select
<include refid="Base_Column_List" />
from parameter_make limit #{offset},#{pageSize}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -16,7 +16,9 @@ public enum KeywordType {
ProductNameToken(4, 6, SuggestionConstants.PRODUCTNAME_TOKEN_ENABLED_KEY),
ProductKeywordToken(5, 6,SuggestionConstants.PRODUCTKEYWORD_TOKEN_ENABLED_KEY),
BrandKeywordToken(6, 6, SuggestionConstants.BRANDKEYWORD_TOKEN_ENABLED_KEY),
ParameterMake(12, 3, SuggestionConstants.PARAMETERMAKE_ENABLED_KEY),
ProductName(8, 1, SuggestionConstants.PRODUCTNAME_ENABLED_KEY),
Customized(0, 1),
HotKeyword(3, 0,SuggestionConstants.HOTKEYWORD_ENABLED_KEY);
... ...
... ... @@ -2,6 +2,9 @@ package com.yoho.search.consumer.suggests.common;
import com.yoho.search.base.utils.Configuration;
import java.util.Arrays;
import java.util.List;
/**
* Created by ginozhang on 2016/11/25.
*/
... ... @@ -13,6 +16,8 @@ public class SuggestionConstants {
public static final Integer VALID_STATUS = Integer.valueOf(1);
public static final List<String> IGNORE_KEYWORDS = Arrays.asList("其他","正常","中文","中国","普通","2%");
public static String YOHO_SEARCH_KEYWORDS_HOT = "YOHO.SEARCH.KEYWORDS.HOT";
... ... @@ -27,6 +32,7 @@ public class SuggestionConstants {
public static String SHOPNAME_ENABLED_KEY = "search.suggestion.consumer.shopname.enable";
public static String PRODUCTNAME_ENABLED_KEY = "search.suggestion.consumer.productname.enable";
public static String PARAMETERMAKE_ENABLED_KEY = "search.suggestion.consumer.parametermake.enable";
public static int FETCH_HOTKEYWORD_COUNT = 10000;
... ...
package com.yoho.search.consumer.suggests.discover;
import com.yoho.search.consumer.service.base.ParameterMakeService;
import com.yoho.search.consumer.suggests.common.KeywordType;
import com.yoho.search.consumer.suggests.common.SuggestionConstants;
import com.yoho.search.dal.model.ParameterMake;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by ginozhang on 2016/11/25.
*/
@Component
public class ParameterMakeSuggestionDiscoverer extends AbstractSuggestionDiscoverer {
@Autowired
private ParameterMakeService parameterMakeService;
@Override
public int count() {
return parameterMakeService.selectTotalCount();
}
@Override
public Set<String> getSuggestWordSet(int pageNo, int batchSize) {
Set<String> parameterValueSet = new HashSet<>(batchSize);
int start = (pageNo - 1) * batchSize;
List<ParameterMake> parameterMakeList = parameterMakeService.selectPageLists(start, batchSize);
if (CollectionUtils.isNotEmpty(parameterMakeList)) {
for (ParameterMake pm : parameterMakeList) {
if (pm.getParameterValue() != null && pm.getParameterValue().length() > 1) {
for (String item : pm.getParameterValue().split("\\/")) {
if (!SuggestionConstants.IGNORE_KEYWORDS.contains(pm.getParameterValue())) {
parameterValueSet.add(item);
}
}
}
}
}
return parameterValueSet;
}
@Override
public KeywordType getKeywordType() {
return KeywordType.ParameterMake;
}
public static void main(String[] args) {
System.out.println(Arrays.asList("羊毛/羊绒".split("\\/")));
}
}
... ...
package com.yoho.search.consumer.service.base;
import com.yoho.search.dal.ParameterMakeMapper;
import com.yoho.search.dal.model.ParameterMake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.dal.ParameterMakeMapper;
import java.util.List;
@Service
public class ParameterMakeService {
@Autowired
private ParameterMakeMapper parameterMakeMapper;
public ParameterMake getById(Integer id) {
return parameterMakeMapper.selectByPrimaryKey(id);
}
public int insert(ParameterMake parameterMake) {
return parameterMakeMapper.insert(parameterMake);
}
public int update(ParameterMake parameterMake) {
return parameterMakeMapper.updateByPrimaryKeySelective(parameterMake);
}
public int saveOrUpdate(ParameterMake parameterMake) {
if (parameterMake.getId() == null || parameterMakeMapper.selectByPrimaryKey(parameterMake.getId()) == null) {
return parameterMakeMapper.insert(parameterMake);
} else {
return parameterMakeMapper.updateByPrimaryKeySelective(parameterMake);
}
}
public int delete(Integer id) {
return parameterMakeMapper.deleteByPrimaryKey(id);
}
public List<ParameterMake> getAll(){
return parameterMakeMapper.getAll();
}
@Autowired
private ParameterMakeMapper parameterMakeMapper;
public ParameterMake getById(Integer id) {
return parameterMakeMapper.selectByPrimaryKey(id);
}
public int insert(ParameterMake parameterMake) {
return parameterMakeMapper.insert(parameterMake);
}
public int update(ParameterMake parameterMake) {
return parameterMakeMapper.updateByPrimaryKeySelective(parameterMake);
}
public int saveOrUpdate(ParameterMake parameterMake) {
if (parameterMake.getId() == null || parameterMakeMapper.selectByPrimaryKey(parameterMake.getId()) == null) {
return parameterMakeMapper.insert(parameterMake);
} else {
return parameterMakeMapper.updateByPrimaryKeySelective(parameterMake);
}
}
public int delete(Integer id) {
return parameterMakeMapper.deleteByPrimaryKey(id);
}
public List<ParameterMake> getAll() {
return parameterMakeMapper.getAll();
}
public int selectTotalCount() {
return parameterMakeMapper.selectTotalCount();
}
public List<ParameterMake> selectPageLists(int start, int size) {
return parameterMakeMapper.selectPageLists(start, size);
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.spider.conversation;
import com.yoho.search.consumer.index.common.AnalyzerHelper;
import com.yoho.search.consumer.service.base.*;
import com.yoho.search.consumer.suggests.common.SuggestionConstants;
import com.yoho.search.dal.model.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
... ... @@ -26,9 +27,6 @@ public class SuggestConvertorService {
private static final int MAX_KEYWORDS = 5;
// TODO:
private static final List<String> IGNORE_KEYWORDS = Arrays.asList("其他","正常");
@Autowired
private AnalyzerHelper analyzerHelper;
... ... @@ -58,7 +56,7 @@ public class SuggestConvertorService {
Map<String, Set<String>> yohoKeywords = new HashMap<>(keywordSet.size());
Set<String> tokens;
for (String keyword : keywordSet) {
if (keyword.length() > 1 && !IGNORE_KEYWORDS.contains(keyword) && CollectionUtils.isNotEmpty(tokens = analyzerHelper.getTokens(keyword, ANALYZER))) {
if (keyword.length() > 1 && !SuggestionConstants.IGNORE_KEYWORDS.contains(keyword) && CollectionUtils.isNotEmpty(tokens = analyzerHelper.getTokens(keyword, ANALYZER))) {
yohoKeywords.put(keyword, tokens);
}
}
... ...
... ... @@ -6,6 +6,7 @@ import com.yoho.search.base.utils.RedisKeys;
import com.yoho.search.consumer.index.common.AnalyzerHelper;
import com.yoho.search.consumer.service.base.SpiderContentService;
import com.yoho.search.consumer.suggests.common.RetryBusinessFlow;
import com.yoho.search.consumer.suggests.common.SuggestionConstants;
import com.yoho.search.dal.model.SpiderContent;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
... ... @@ -33,8 +34,6 @@ public class KeywordCrawlerFlow implements RetryBusinessFlow {
private static final Logger logger = LoggerFactory.getLogger("FLOW_EXECUTOR");
private static final Set<String> IGNORE_KEYWORDS = new HashSet<>();
private static final int KEYWORD_COUNT = 1000;
@Resource(name = "yhNoSyncZSetOperations")
... ... @@ -61,13 +60,6 @@ public class KeywordCrawlerFlow implements RetryBusinessFlow {
@Override
public void init() {
//TODO: 增加忽略的关键词 需要能自行添加
IGNORE_KEYWORDS.add("其他");
IGNORE_KEYWORDS.add("中文");
IGNORE_KEYWORDS.add("中国");
IGNORE_KEYWORDS.add("普通");
IGNORE_KEYWORDS.add("2%");
Set<String> keywordSet = new HashSet<>(1000);
Set<ZSetOperations.TypedTuple<String>> redisResults = yhNoSyncZSetOperations.reverseRangeWithScores(RedisKeys.getRedisKey4Yesterday(RedisKeys.YOHO_SEARCH_KEYWORDS_EMPTY), 0, KEYWORD_COUNT);
for (ZSetOperations.TypedTuple<String> typedTuple : redisResults) {
... ... @@ -106,7 +98,7 @@ public class KeywordCrawlerFlow implements RetryBusinessFlow {
}
// 在忽略列表的不要
if (IGNORE_KEYWORDS.contains(keyword)) {
if (SuggestionConstants.IGNORE_KEYWORDS.contains(keyword)) {
return false;
}
... ...
... ... @@ -6,7 +6,7 @@ search.suggestion.consumer.sortname.enable=true
search.suggestion.consumer.productname.token.enable=true
search.suggestion.consumer.productkeyword.token.enable=true
search.suggestion.consumer.brandkeyword.token.enable=true
search.suggestion.consumer.parametermake.enable=true
search.suggestion.consumer.shopname.enable=true
search.suggestion.consumer.productname.enable=true
search.suggestion.consumer.brandwithsortname.enable=true
... ...