SearchDynamicConfigService.java 5.04 KB
package com.yoho.search.common;

import com.yoho.core.config.ConfigReader;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SearchDynamicConfigService {

    private static final Logger logger = LoggerFactory.getLogger(SearchDynamicConfigService.class);

    @Autowired
    private ConfigReader configReader;

    /**
     * 是否开启个性化
     */
    public boolean openPersonalized() {
        return configReader.getBoolean("search.degrade.open.personalized", true);
    }

    /**
     * 搜索结果是否包含全球购
     */
    public boolean containglobal() {
        return configReader.getBoolean("search.degrade.open.containglobal", true);
    }

    /**
     * 是否返回变价计划
     */
    public boolean pricePlanOpen() {
        return configReader.getBoolean("search.price.plan.open", true);
    }

    /**
     * 频道降分是否打开
     */
    public boolean isDeScorePhysicalChannelOpen() {
        return configReader.getBoolean("search.degrade.descore.physicalchannel.open", true);
    }

    /**
     * 频道降分权重
     */
    public double getDeScorePhysicalChannelWeight() {
        return configReader.getDouble("search.degrade.descore.physicalchannel.value", 0.6);
    }

    /**
     * 是否打开搜索无结果或结果太少时的搜索提示功能
     */
    public boolean isSearchSuggestionTipsOpen() {
        return configReader.getBoolean("search.suggestion.tips.open", true);
    }

    /**
     * 关于API查看动态参数值
     */
    public String getDynamicParameterValue(String key) {
        return configReader.getString(key, "DEFAULT");
    }

    /**
     * 新品到着页的根据首次上架时间衰减函数规则值
     */
    public String getNewArrivalPageDecayRuleValue() {
        return configReader.getString("search.function.score.new_arrival_page_decay_rule", "4,1");
    }

    /**
     * 非新品到着页的根据首次上架时间衰减函数规则值
     */
    public String getOtherPageDecayRuleValue() {
        return configReader.getString("search.function.score.other_page_decay_rule", "30,7");
    }

    /**
     * 个性化限流配置
     */
    public PersionalRateLimitConfig getPersionalRateLimitConfig(String rateLimitName, PersionalRateLimit persionalRateLimit) {
        try {
            String zkConfigKey = "search.persional.rateLimit" + rateLimitName.replaceAll("/", ".");
            PersionalRateLimitConfig defalut = new PersionalRateLimitConfig(persionalRateLimit);
            String zkConfigValue = configReader.getString(zkConfigKey, defalut.toZkValue());
            return new PersionalRateLimitConfig(zkConfigValue);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return new PersionalRateLimitConfig(200, 10);
        }
    }

    /**
     * 个性化限流开关【双11打开】
     */
    public boolean isPersionalRateLimitOpen() {
        return configReader.getBoolean("search.persional.rateLimit.open", true);
    }

    /**
     * 使用新的的召回策略
     */
    public boolean searchPersionalNewStrategyOpen() {
        return configReader.getBoolean("search.persional.newstrategy.open", true);
    }

    /**
     * 促销页使用新的的召回策略
     */
    public boolean searchPersionalNewStrategyPromotionOpen() {
        return configReader.getBoolean("search.persional.newstrategy.promotion.open", true);
    }

    /**
     * 新的的召回策略-第一页是否缓存
     */
    public boolean searchPersionalNewStrategyFirstPageCacheOpen() {
        return configReader.getBoolean("search.persional.newstrategy.first_page_cache.open", false);
    }


    /**
     * 相关推荐否使用个性化-【双11关闭】
     */
    public boolean isRecommendPersionalOpen() {
        return configReader.getBoolean("search.persional.recommend.open", true);
    }

    /**
     * 超时日志是否打开
     */
    public boolean isControllerCostLogOpen() {
        return configReader.getBoolean("search.controller.cost.log.open", true);
    }

    /**
     * A策略是否打开
     */
    public boolean isAStrategyOpen() {
        return configReader.getBoolean("search.persional.abTest.a.strategy.open", true);
    }

    /**
     * B策略是否打开
     */
    public boolean isBStrategyOpen() {
        return configReader.getBoolean("search.persional.abTest.b.strategy.open", true);
    }

    /**
     * 全球购查新索引
     */
    public boolean tblUseNewIndex() {
        return configReader.getBoolean("search.tbl.use.new.index", true);
    }

    /**
     * group_shop新实现
     */
    public boolean groupShopNew() {
        return configReader.getBoolean("search.shop.group.new", true);
    }

}