|
@@ -2,9 +2,9 @@ package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
|
|
|
|
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
|
|
|
import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
|
|
|
-import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.VideoTagModel4RecallMap;
|
|
|
-import com.tzld.piaoquan.recommend.server.util.ListMerger;
|
|
|
+import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
@@ -20,13 +20,13 @@ public class ContentBaseRecallScore extends AbstractScorer4Recall {
|
|
|
|
|
|
@Override
|
|
|
public void loadModel() {
|
|
|
- doLoadModel(VideoTagModel4RecallMap.class);
|
|
|
+ doLoadModel(Model4RecallKeyValue.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Pair<Long, Double>> recall(Map<String, String> params) {
|
|
|
- VideoTagModel4RecallMap model = (VideoTagModel4RecallMap) this.getModel();
|
|
|
- if (model == null || model.map == null) {
|
|
|
+ Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
|
|
|
+ if (model == null || MapUtils.isEmpty(model.kv)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
String tags = params.get("tags");
|
|
@@ -34,17 +34,25 @@ public class ContentBaseRecallScore extends AbstractScorer4Recall {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
List<String> tagList = Arrays.stream(tags.split(",")).collect(Collectors.toList());
|
|
|
- Map<String, List<Long>> tagVideoIdMap = model.map;
|
|
|
- List<List<Pair<Long, Double>>> multiTagVideos = new ArrayList<>();
|
|
|
+ List<Pair<Long, Double>> result = new ArrayList<>();
|
|
|
for (String tag : tagList) {
|
|
|
- List<Long> videoIds = tagVideoIdMap.get(tag);
|
|
|
- if (CollectionUtils.isNotEmpty(videoIds)) {
|
|
|
- multiTagVideos.add(videoIds.stream().map(videoId -> Pair.of(videoId, 1.0))
|
|
|
- .collect(Collectors.toList()));
|
|
|
+ List<Pair<Long, Double>> videoAndScores = model.kv.get(tag);
|
|
|
+ if (CollectionUtils.isNotEmpty(videoAndScores)) {
|
|
|
+ result.addAll(videoAndScores);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- return ListMerger.mergeLists(multiTagVideos);
|
|
|
+ // 结果去重
|
|
|
+ Set<Long> videoIdSet = new HashSet<>();
|
|
|
+ List<Pair<Long, Double>> distinctResult = new ArrayList<>();
|
|
|
+ for (Pair<Long, Double> pair : result) {
|
|
|
+ if (pair.getLeft() == null || pair.getRight() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (videoIdSet.add(pair.getLeft())) {
|
|
|
+ distinctResult.add(pair);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return distinctResult;
|
|
|
}
|
|
|
|
|
|
|