RecallConfigService.java 3.24 KB
package com.yoho.search.recall.config;

import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RecallConfigService {
    @Autowired
    private RecallConfigServiceProduct recallConfigServiceProduct;
    @Autowired
    private RecallConfigServiceCommon recallConfigServiceCommon;

    /**
     * 获取召回数量
     *
     * @param pageId
     * @param sortBrand
     * @return
     */
    public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType,SortBrand sortBrand) {
        return recallConfigServiceProduct.queryRecallSknCount(pageId,sortBrandType,sortBrand);
    }

    /**
     * 获取推荐的品类品牌的配置
     *
     * @param pageId
     * @return
     */
    public int getRecSortBrandCount(int pageId) {
        return recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.REC_S_B_COUNT, 12);
    }

    /**
     * 获取W2v预测的品类品牌的数量
     *
     * @param pageId
     * @return
     */
    public int getVectorW2vSortBrandCount(int pageId) {
        return recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_W2V_S_B_COUNT, 12);
    }

    /**
     * 获取RNN预测的品类品牌的数量
     *
     * @param pageId
     * @return
     */
    public int getVectorRNNSortBrandCount(int pageId) {
        return recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_RNN_S_B_COUNT, 0);
    }

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

    /**
     * 获取某些策略的召回数量
     *
     * @param pageId
     * @param strategyEnum
     * @return
     */
    public int queryStrategyRecallSknSize(int pageId, StrategyEnum strategyEnum) {
        String configKey = getStrategyConfiKey(strategyEnum);
        return recallConfigServiceCommon.queryConfigSize(pageId, configKey, 0);
    }

    /**
     * 获取某些策略的间隔
     *
     * @param pageId
     * @param strategyEnum
     * @return
     */
    public int queryStrategyInterval(int pageId, StrategyEnum strategyEnum) {
        String configKey = getStrategyConfiKey(strategyEnum);
        int interval = recallConfigServiceCommon.queryConfigInterval(pageId, configKey, 10);
        interval = Math.max(interval, 2);
        interval = Math.min(interval, 40);
        return interval;
    }

}