...
|
...
|
@@ -2,7 +2,7 @@ package com.yoho.search.service.personalized; |
|
|
|
|
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
|
|
|
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.script.ScriptService;
|
...
|
...
|
@@ -30,17 +30,17 @@ public class PersonalVectorFeatureSearch { |
|
|
@Autowired
|
|
|
private PersonalizedRedisService personalizedRedisService;
|
|
|
|
|
|
public ScoreFunctionBuilder build(String uid) {
|
|
|
public void addPersonalizedScriptScore(FunctionScoreQueryBuilder functionScoreQueryBuilder, String uid) {
|
|
|
// 1. 获取特征向量版本(即生成时间,该时间需要与skn的生成时间一致才有意义)
|
|
|
String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
|
|
|
if (StringUtils.isEmpty(vectorFeatureVersion) || "-1".equals(vectorFeatureVersion)) {
|
|
|
return null;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 2. 获取用户的特征向量
|
|
|
String userVectorFeature = personalizedRedisService.getUserVectorFeature(uid, vectorFeatureVersion);
|
|
|
if (StringUtils.isEmpty(userVectorFeature)) {
|
|
|
return null;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 3. 传入参数调用脚本
|
...
|
...
|
@@ -56,7 +56,7 @@ public class PersonalVectorFeatureSearch { |
|
|
scriptParams.put("factorConstant", FACTOR_CONSTANT);
|
|
|
logger.info("[PersonalVectorFeatureSearch.build][scriptParams={}]", scriptParams);
|
|
|
Script script = new Script("feature_factor_vector_score", ScriptService.ScriptType.INLINE, "native", scriptParams);
|
|
|
return ScoreFunctionBuilders.scriptFunction(script);
|
|
|
functionScoreQueryBuilder.add(ScoreFunctionBuilders.scriptFunction(script));
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|