RecallService.java
3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.yoho.search.recall.scene;
import com.yoho.search.recall.scene.builder.request.BrandRecallRequestBuilder;
import com.yoho.search.recall.scene.builder.request.CommonRecallRequestBuilder;
import com.yoho.search.recall.scene.builder.request.SortPriceRecallRequestBuilder;
import com.yoho.search.recall.scene.builder.response.RecallResponseBatchBuilder;
import com.yoho.search.recall.scene.builder.response.RecallSknResultBuilder;
import com.yoho.search.recall.scene.component.BatchRecallComponent;
import com.yoho.search.recall.scene.models.*;
import com.yoho.search.recall.scene.persional.PersionalFactor;
import com.yoho.search.recall.scene.persional.RecallPersionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class RecallService {
@Autowired
private RecallPersionalService recallPersionalService;
@Autowired
private BatchRecallComponent bacthRecallComponent;
@Autowired
private RecallResponseBatchBuilder recallResponseBatchBuilder;
@Autowired
private RecallSknResultBuilder recallSknResultBuilder;
@Autowired
private CommonRecallRequestBuilder commonRequestBuilder;
@Autowired
private BrandRecallRequestBuilder brandRequestBuilder;
@Autowired
private SortPriceRecallRequestBuilder sortPriceRequestBuilder;
public RecallSknResult getRecallSknResult(RecallSknParams recallSknParams){
RecallSknResult recallSknResult = this.doRecall(recallSknParams);
return recallSknResult;
}
/**
* 召回入口
* @param param
* @return
*/
private RecallSknResult doRecall(RecallSknParams param) {
//1、获取个性化因子
PersionalFactor persionalFactor = recallPersionalService.queryPersionalFactor(param);
//2、构造请求
List<RecallRequest> batchRequests = this.buildBatchRequests(param, persionalFactor);
//3、批量召回
List<CacheRecallRequestResponse> requestResponses = bacthRecallComponent.batchRecallAndCache(batchRequests);
//4、获取skn列表[去重]
RecallResponseBatch recallResponseBatch = recallResponseBatchBuilder.buildRecallResponseBatch(requestResponses);
//5、构造真实结果[排序,截取skn]
RecallSknResult recallSknResult = recallSknResultBuilder.builderRecallResult(recallResponseBatch, param, persionalFactor);
return recallSknResult;
}
/**
* 批量构造请求
* @param param
* @param persionalFactor
* @return
*/
public List<RecallRequest> buildBatchRequests(RecallSknParams param, PersionalFactor persionalFactor) {
//1、构造召回请求
List<RecallRequest> allRequests = new ArrayList<>();
//2、构造非个性化的请求
List<RecallRequest> commonRequests = commonRequestBuilder.buildCommonRecallRequests(param.getParamQueryFilter(), param.getFirstProductSkns());
allRequests.addAll(commonRequests);
//4、构建个性化品牌的召回请求
List<RecallRequest> brandRequests = brandRequestBuilder.buildBrandRecallRequests(param.getParamQueryFilter(), persionalFactor.getBrandIds());
allRequests.addAll(brandRequests);
//5、构建个性化品牌的召回请求
List<RecallRequest> sortPriceRequests = sortPriceRequestBuilder.buildSortPriceRecallRequests(param.getParamQueryFilter(), persionalFactor.getSortPriceAreas());
allRequests.addAll(sortPriceRequests);
return allRequests;
}
}