predictionio 的validScores方法 有点问题,因为model对象中的一个属性类型为Map items,在数据量很大的时候,肯定是不行,所以优化一下,采用join+filter的模式,代码如下

return all.mapToPair(new PairFunction() {
            @Override
            public Tuple2 call(ItemScore idUser) throws Exception {
                return new Tuple2<>(idUser.getItemEntityId(), idUser);
            }
        }).join(model.getItems()).filter(new Function>, Boolean>() {
            @Override
            public Boolean call(Tuple2> 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>, ItemScore>() {
             @Override
             public ItemScore call(Tuple2> userItemCount) throws Exception {
                 return userItemCount._2._1;
             }
         });