predictionio 的validScores方法 有点问题,因为model对象中的一个属性类型为Map<String, Item> items,在数据量很大的时候,肯定是不行,所以优化一下,采用join+filter的模式,代码如下
return all.mapToPair(new PairFunction<ItemScore, String, ItemScore>() {
@Override
public Tuple2<String, ItemScore> call(ItemScore idUser) throws Exception {
return new Tuple2<>(idUser.getItemEntityId(), idUser);
}
}).join(model.getItems()).filter(new Function<Tuple2<String,Tuple2<ItemScore,Item>>, Boolean>() {
@Override
public Boolean call(Tuple2<String,Tuple2<ItemScore,Item>> itemScore) throws Exception {
/*Item item = items.get(itemScore.getItemEntityId());*/
Item item =itemScore._2._2;
//logger.info("join end");
return (item!=null && /*item != null
&& */passWhitelistCriteria(whitelist, itemScore._2._1.getItemEntityId())
&& passBlacklistCriteria(blacklist, itemScore._2._1.getItemEntityId())
/* && passCategoryCriteria(categories, item)*/
/* && passUnseenCriteria(seenItemEntityIds, itemScore.getItemEntityId())*///看过或买过的不要
/* && passAvailabilityCriteria(unavailableItemEntityIds, itemScore.getItemEntityId())*/);
}
}).map(new Function<Tuple2<String, Tuple2<ItemScore,Item>>, ItemScore>() {
@Override
public ItemScore call(Tuple2<String, Tuple2<ItemScore,Item>> userItemCount) throws Exception {
return userItemCount._2._1;
}
});
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/196040.html