|
@@ -3,6 +3,8 @@ package com.tzld.longarticle.recommend.server.service.filter;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.longarticle.recommend.server.common.ThreadPoolFactory;
|
|
|
import com.tzld.longarticle.recommend.server.service.ServiceBeanFactory;
|
|
|
+import com.tzld.longarticle.recommend.server.service.filter.strategy.CategoryStrategy;
|
|
|
+import com.tzld.longarticle.recommend.server.service.filter.strategy.DuplicateStrategy;
|
|
|
import com.tzld.longarticle.recommend.server.service.filter.strategy.SimilarityStrategy;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -22,12 +24,12 @@ public class FilterService {
|
|
|
private final ExecutorService pool = ThreadPoolFactory.filterPool();
|
|
|
|
|
|
public FilterResult filter(FilterParam param) {
|
|
|
- List<Long> videoIds = viewFilter(param);
|
|
|
+ List<Long> videoIds = contentFilter(param);
|
|
|
|
|
|
return new FilterResult(videoIds);
|
|
|
}
|
|
|
|
|
|
- protected List<Long> viewFilter(FilterParam param) {
|
|
|
+ private List<Long> contentFilter(FilterParam param) {
|
|
|
|
|
|
List<FilterStrategy> strategies = getStrategies(param);
|
|
|
CountDownLatch cdl = new CountDownLatch(strategies.size());
|
|
@@ -47,20 +49,20 @@ public class FilterService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- List<List<Long>> videoIds = new ArrayList<>();
|
|
|
+ List<List<Long>> contentIds = new ArrayList<>();
|
|
|
for (Future<List<Long>> f : futures) {
|
|
|
try {
|
|
|
- videoIds.add(f.get());
|
|
|
+ contentIds.add(f.get());
|
|
|
} catch (Exception e) {
|
|
|
log.error("future get error ", e);
|
|
|
}
|
|
|
}
|
|
|
- if (CollectionUtils.isEmpty(videoIds)) {
|
|
|
+ if (CollectionUtils.isEmpty(contentIds)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
List<Long> result = Lists.newArrayList(param.getVideoIds());
|
|
|
- for (int i = 0; i < videoIds.size(); ++i) {
|
|
|
- result.retainAll(videoIds.get(i));
|
|
|
+ for (int i = 0; i < contentIds.size(); ++i) {
|
|
|
+ result.retainAll(contentIds.get(i));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
@@ -68,6 +70,11 @@ public class FilterService {
|
|
|
private List<FilterStrategy> getStrategies(FilterParam param) {
|
|
|
List<FilterStrategy> strategies = new ArrayList<>();
|
|
|
strategies.add(ServiceBeanFactory.getBean(SimilarityStrategy.class));
|
|
|
+ strategies.add(ServiceBeanFactory.getBean(DuplicateStrategy.class));
|
|
|
+
|
|
|
+ if (param.isFlowPool()) {
|
|
|
+ strategies.add(ServiceBeanFactory.getBean(CategoryStrategy.class));
|
|
|
+ }
|
|
|
|
|
|
return strategies;
|
|
|
}
|