|
@@ -0,0 +1,65 @@
|
|
|
|
+package com.tzld.piaoquan.recommend.server.service.recall.strategy;
|
|
|
|
+
|
|
|
|
+import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.model.Video;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.filter.FilterResult;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.filter.RegionFilterService;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.recall.FilterParamFactory;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.recall.RecallParam;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.recall.RecallStrategy;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.score.ScorerUtils;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.service.score4recall.ScorerPipeline4Recall;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.RandomUtils;
|
|
|
|
+import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author zhangbo
|
|
|
|
+ */
|
|
|
|
+@Slf4j
|
|
|
|
+@Component
|
|
|
|
+public class RegionRealtimeRecallStrategyV5Hand implements RecallStrategy {
|
|
|
|
+ @ApolloJsonValue("${alg.recall.hand.videos:[]}")
|
|
|
|
+ private List<Long> handVideos;
|
|
|
|
+ @Autowired
|
|
|
|
+ protected RegionFilterService filterService;
|
|
|
|
+ @Override
|
|
|
|
+ public List<Video> recall(RecallParam param) {
|
|
|
|
+ List<Long> vids = handVideos != null ? handVideos : new ArrayList<>();
|
|
|
|
+ List<Video> videosResult = new ArrayList<>();
|
|
|
|
+ if (vids.isEmpty()){
|
|
|
|
+ return videosResult;
|
|
|
|
+ }
|
|
|
|
+ FilterParam filterParam = FilterParamFactory.create(param, vids);
|
|
|
|
+ filterParam.setForceTruncation(10000);
|
|
|
|
+ filterParam.setConcurrent(true);
|
|
|
|
+ filterParam.setNotUsePreView(false);
|
|
|
|
+ FilterResult filterResult = filterService.filter(filterParam);
|
|
|
|
+ if (filterResult == null || filterResult.getVideoIds().isEmpty()){
|
|
|
|
+ return videosResult;
|
|
|
|
+ }
|
|
|
|
+ filterResult.getVideoIds().forEach(vid -> {
|
|
|
|
+ Video video = new Video();
|
|
|
|
+ video.setVideoId(vid);
|
|
|
|
+ video.setAbCode(param.getAbCode());
|
|
|
|
+ video.setRovScore(RandomUtils.nextFloat(0, 1));
|
|
|
|
+ video.setPushFrom(pushFrom());
|
|
|
|
+ videosResult.add(video);
|
|
|
|
+ });
|
|
|
|
+ videosResult.sort(Comparator.comparingDouble(o -> -o.getRovScore()));
|
|
|
|
+ return videosResult;
|
|
|
|
+ }
|
|
|
|
+ public static final String PUSH_FORM = "recall_strategy_hand";
|
|
|
|
+ @Override
|
|
|
|
+ public String pushFrom(){
|
|
|
|
+ return PUSH_FORM;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|