SearchDynamicConfigService.java 6.61 KB
package com.yoho.search.service.base;

import com.yoho.core.config.ConfigReader;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.common.downgrade.persional.PersionalRateLimitConfig;
import com.yoho.search.recall.scene.constants.RecallCommonConstants;
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;

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

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

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

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

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

	/**
	 * 是否打开搜索无结果或结果太少时的搜索提示功能
	 * 
	 * @return
	 */
	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 int getSearchLikeNotInShopSameSortPercent() {
		return configReader.getInt("search.searchlike.not_in_shop.same_sort_percent", 60);
	}

	/**
	 * 个性化限流配置
	 */
	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);
	}

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

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

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

	/**
	 * 新的的召回策略-兜底策略是否参与评分
	 *
	 * @return
	 */
	public boolean searchPersionalNewStrategyCommonJoinScoreOpen() {
		return configReader.getBoolean("search.persional.newstrategy.common.join_score.open", false);
	}

	/**
	 * 新的的召回策略-实时的品牌品类
	 *
	 * @return
	 */
	public int maxRealTimeSortBrandCount() {
		return configReader.getInt("search.persional.newstrategy.realtime.max_sort_brand.count", RecallCommonConstants.maxRealTimeSortBrandCount);
	}

	/**
	 * 新的的召回策略-基于向量的品牌品类
	 *
	 * @return
	 */
	public int maxVectorSortBrandCount() {
		return configReader.getInt("search.persional.newstrategy.vector.max_sort_brand.count", RecallCommonConstants.maxVectorSortBrandCount);
	}

	/**
	 * 新的的召回策略-预测的品牌品类
	 *
	 * @return
	 */
	public int maxForecastSortBrandCount() {
		return configReader.getInt("search.persional.newstrategy.forecast.max_sort_brand.count", RecallCommonConstants.maxForecastSortBrandCount);
	}

	/**
	 * 新的的召回策略-最多预测的品牌品类
	 *
	 * @return
	 */
	public int directTrainIndexInterval() {
		return configReader.getInt("search.persional.newstrategy.directtrain.index.interval",4);
	}


	/**
	 * 新的的召回策略-召回来后是否再次进行品类品牌的平衡
	 *
	 * @return
	 */
	public boolean searchPersionalNewStrategySortBrandBalance() {
		return configReader.getBoolean("search.persional.newstrategy.sort_brand_balance.open", false);
	}

	/**
	 * 使用性能高的召回场景【双11打开】
	 *
	 * @return
	 */
	public boolean searchPersionalPerfamanceStrategyOpen() {
		return configReader.getBoolean("search.persional.performancestrategy.open", false);
	}

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

	/**
	 * 找相似是否使用bigdatasimilarskn
	 */
	public boolean isSearchLikeSimilarSknOpen() {
		return configReader.getBoolean("search.searchlike.similarskn", true);
	}

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

	/**
	 * 推荐品牌是否要使用大数据的推荐
	 * @return
	 */
	public boolean isRecommendBrandUserPersonalOpen() {
		return configReader.getBoolean("search.recommendbrand.userPersonal.open", false);
	}

	/**
	 * 奇数的uid使用AB-TEST
	 * @return
	 */
	public boolean isAbTestUser(int uid) {
		boolean abTestOpen = configReader.getBoolean("search.persional.abTest.open", false);
		if(!abTestOpen){
			return true;
		}
		if(uid%2==1){
			return true;
		}
		return false;
	}

}