| 
					
				 | 
			
			
				@@ -16,17 +16,13 @@ import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.data.redis.core.RedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.data.redis.core.ZSetOperations; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Set; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @author dyp 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-public abstract class AbstractRegionRecallStrategy implements RecallStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public abstract class AbstractRecallStrategy implements RecallStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     protected RedisTemplate<String, String> redisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -80,6 +76,7 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 召回 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         int getSize = param.getSize() * 5; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         int freq = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String lastVideoId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         List<RecallResult.RecallData> results = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         while (results.size() < param.getSize()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             freq += 1; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -92,13 +89,13 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             idx += getSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            Map<Long, Double> videoMap = data.stream() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .filter(t -> NumberUtils.isDigits(t.getValue())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .collect(Collectors.toMap( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            t -> Long.getLong(t.getValue()), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            t -> t.getScore(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            (a, b) -> b 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    )); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Map<Long, Double> videoMap = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            for (ZSetOperations.TypedTuple<String> t : data) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                lastVideoId = t.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                videoMap.put(NumberUtils.toLong(t.getValue(), 0), t.getScore()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             FilterParam filterParam = new FilterParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             filterParam.setVideoIds(Lists.newArrayList(videoMap.keySet())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             FilterResult filterResult = filterService.filter(filterParam); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -115,16 +112,14 @@ public abstract class AbstractRegionRecallStrategy implements RecallStrategy { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        pool_recall_result.sort(key=lambda x: x.get('rovScore', 0), reverse=True) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        # if len(recall_data) > 0 and len(pool_recall_result) == 0 \ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        #         and self.ab_code == config_.AB_CODE['region_rank_by_h'].get('abtest_112') and self.mid: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        if len(recall_data) > 0 and len(pool_recall_result) == 0 and self.mid: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//            # 召回数据不为空 & 过滤后结果为空 & 位于实验组 & mid不为空时,更新召回获取的末位视频id记录到定位的key中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                last_video_key = f'{last_video_key_prefix}{self.app_type}:{self.mid}' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//        self.redis_helper.set_data_to_redis(key_name=last_video_key, value=recall_data[-1][0], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-//                expire_time=expire_time) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Collections.sort(results, (o1, o2) -> (int) (o2.getRovScore() - o1.getRovScore())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (StringUtils.isNotBlank(lastVideoId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                && CollectionUtils.isNotEmpty(results) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                && StringUtils.isNotBlank(param.getMid())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 召回数据不为空 & 过滤后结果为空 &  mid不为空时,更新召回获取的末位视频id记录到定位的key中 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            redisTemplate.opsForValue().set(lastVideoKey, lastVideoId, 2, TimeUnit.HOURS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         RecallResult result = new RecallResult(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         result.setRecallData(results.subList(0, results.size() < param.getSize() ? results.size() : param.getSize())); 
			 |