RecallCommonConfigService.java 3.99 KB
package com.yoho.search.recall.config;

import com.yoho.search.recall.beans.helper.StrategyHelper;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class RecallCommonConfigService {

    private Map<String, Map<Integer, RecallCommonConfig>> configMap = new HashMap<>();

    private RecallCommonConfig queryCommonConfig(int configPage, String configKey) {
        Map<Integer, RecallCommonConfig> pageConfigMap = configMap.get(configKey);
        if (pageConfigMap == null) {
            return null;
        }
        RecallCommonConfig pageConfig = pageConfigMap.get(configPage);
        if (pageConfig == null) {
            pageConfig = pageConfigMap.get(0);
        }
        if (pageConfigMap == null) {
            return null;
        } else {
            return pageConfig;
        }
    }

    private String getConfiKey(StrategyEnum strategyEnum) {
        if (strategyEnum.equals(StrategyEnum.REC_SKN)) {
            return RecallCommonConfigKeys.REC_SKN;
        }
        if (strategyEnum.equals(StrategyEnum.RT_SIM_SKN)) {
            return RecallCommonConfigKeys.RT_SIM_SKN;
        }
        if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN)) {
            return RecallCommonConfigKeys.DIRECT_TRAIN;
        }
        if (strategyEnum.equals(StrategyEnum.NEW_SHOP)) {
            return RecallCommonConfigKeys.NEW_SHOP;
        }
        if (strategyEnum.equals(StrategyEnum.ADD_FLOW)) {
            return RecallCommonConfigKeys.ADD_FLOW;
        }
        return null;
    }

    public int getRecallSize(int pageId, StrategyEnum strategyEnum) {
        String configKey = this.getConfiKey(strategyEnum);
        if (StringUtils.isBlank(configKey)) {
            return 0;
        }
        RecallCommonConfig config = queryCommonConfig(pageId, configKey);
        return config == null ? 0 : config.getSize();
    }

    public int getRecallInterval(int pageId, StrategyEnum strategyEnum) {
        String configKey = this.getConfiKey(strategyEnum);
        if (StringUtils.isBlank(configKey)) {
            return 0;
        }
        RecallCommonConfig config = queryCommonConfig(pageId, configKey);
        return config == null ? 0 : config.getInterval();
    }

    /**
     * 获取推荐的品类品牌的配置
     *
     * @param pageId
     * @return
     */
    public int getRecSortBrandCount(int pageId) {
        RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.REC_S_B_COUNT);
        if (recallCommonConfig != null) {
            return recallCommonConfig.getSize();
        }
        return 12;
    }

    /**
     * 获取预测的品类品牌的配置
     *
     * @param pageId
     * @return
     */
    public int getVectorW2vSortBrandCount(int pageId) {
        RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.VEC_W2V_S_B_COUNT);
        if (recallCommonConfig != null) {
            return recallCommonConfig.getSize();
        }
        return 12;
    }

    /**
     * 获取预测的品类品牌的配置
     *
     * @param pageId
     * @return
     */
    public int getVectorRNNSortBrandCount(int pageId) {
        RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.VEC_RNN_S_B_COUNT);
        if (recallCommonConfig != null) {
            return recallCommonConfig.getSize();
        }
        return 12;
    }

    /**
     * 获取预测的品类品牌的配置
     *
     * @param pageId
     * @return
     */
    public int getUserMaxRecallCount(int pageId) {
        RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.USER_MAX_RECALL_COUNT);
        if (recallCommonConfig != null) {
            return recallCommonConfig.getSize();
        }
        return 200;
    }

}