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.Model4Recall2List;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


public class ShareWidthRecallScore extends AbstractScorer4Recall {

    public ShareWidthRecallScore(ScorerConfigInfo configInfo) {
        super(configInfo);
    }

    @Override
    public void loadModel() {
        doLoadModel(Model4Recall2List.class);
    }

    @Override
    public List<Pair<Long, Double>> recall(Map<String, String> params) {
        if (params == null || params.isEmpty()) {
            return new ArrayList<>();
        }
        Model4Recall2List model = (Model4Recall2List) this.getModel();
        if (model == null || model.recallList == null) {
            return new ArrayList<>();
        }
        int limit = Integer.parseInt(params.getOrDefault("limit", "500"));
        return model.recallList.stream().limit(limit).collect(Collectors.toList());
    }


}