Authored by hugufei

Merge branch '0522' into wn_fix_promotion

Showing 100 changed files with 1457 additions and 1489 deletions

Too many changes to show.

To preserve performance only 100 of 100+ files are displayed.

package com.yoho.search.common.cache.aop;
package com.yoho.search.aop.cache;
public interface ISearchCacheAbleParam {
... ...
package com.yoho.search.common.cache.aop;
import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.models.SearchApiResult;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface SearchCacheAble {
/**
* 缓存名称
*
* @return
*/
public String cacheName();
/**
* 缓存时间
*
* @return
*/
public int cacheInMinute();
/**
* 是否需要md5
* @return
*/
public boolean needMd5() default true;
/**
* 缓存类型,默认search_redis
*
* @return
*/
public CacheType cacheType() default CacheType.SEARCH_REDIS;
/**
* 包含的参数-优先级比去除的参数高
*
* @return
*/
public String[] includeParams() default {};
/**
* 去除的参数
*
* @return
*/
public String[] excludeParams() default {};
/**
* 返回值类型
*
* @return
*/
public Class<? extends Serializable> returnClass() default SearchApiResult.class;
package com.yoho.search.aop.cache;
import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.yoho.search.cache.CacheType;
import com.yoho.search.models.SearchApiResult;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface SearchCacheAble {
/**
* 缓存名称
*
* @return
*/
public String cacheName();
/**
* 缓存时间
*
* @return
*/
public int cacheInMinute();
/**
* 是否需要md5
* @return
*/
public boolean needMd5() default true;
/**
* 缓存类型,默认search_redis
*
* @return
*/
public CacheType cacheType() default CacheType.SEARCH_REDIS;
/**
* 包含的参数-优先级比去除的参数高
*
* @return
*/
public String[] includeParams() default {};
/**
* 去除的参数
*
* @return
*/
public String[] excludeParams() default {};
/**
* 返回值类型
*
* @return
*/
public Class<? extends Serializable> returnClass() default SearchApiResult.class;
}
\ No newline at end of file
... ...
package com.yoho.search.common.cache.aop;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.common.cache.SearchCacheFactory;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.base.SearchCacheService;
@Component
@Aspect
@Order(Integer.MAX_VALUE-1)
public class SearchCacheAspect {
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private SearchCacheFactory searchCacheFactory;
@Around("@annotation(com.yoho.search.common.cache.aop.SearchCacheAble)")
public Object doCache(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
// 检查注解
SearchCacheAble searchCacheAble = signature.getMethod().getAnnotation(SearchCacheAble.class);
if (searchCacheAble == null) {
return pjp.proceed();
}
// 检查返回类型
Class<? extends Serializable> returnClass = this.getReturnClass(searchCacheAble, signature);
if (returnClass == null) {
return pjp.proceed();
}
// 检查cacheKey
RedisKeyBuilder redisKeyBuilder = this.getRedisKeyBuilder(pjp, searchCacheAble);
if (StringUtils.isBlank(redisKeyBuilder.getKey())){
return pjp.proceed();
}
SearchCache searchCache = searchCacheFactory.getAspectSearhCache(searchCacheAble);
boolean useJsonSerializable = searchCacheAble.cacheType().equals(CacheType.EHCACHE)?false:true;
Serializable cacheObject = searchCacheService.getSerializableObjectFromCache(searchCache, redisKeyBuilder, returnClass,useJsonSerializable);
if (cacheObject != null) {
return cacheObject;
}
Object result = pjp.proceed();
if (result == null) {
return result;
}
cacheObject = (Serializable) result;
if (cacheObject instanceof SearchApiResult && ((SearchApiResult) cacheObject).getCode() != 200) {
return cacheObject;
}
searchCacheService.addSerializableObjectToCache(searchCache, redisKeyBuilder, cacheObject,useJsonSerializable);
return cacheObject;
}
// 校验返回类型是否一致
private Class<? extends Serializable> getReturnClass(SearchCacheAble searchCacheAble, MethodSignature signature) {
final Class<?> returnType = signature.getMethod().getReturnType();
final Class<? extends Serializable> returnClass = searchCacheAble.returnClass();
if (!returnType.getName().equals(returnClass.getName())) {
return null;
}
return returnClass;
}
// 获取请求的参数
private RedisKeyBuilder getRedisKeyBuilder(ProceedingJoinPoint pjp, SearchCacheAble searchCacheAble) {
Object[] arges = pjp.getArgs();
Object object = arges[0];
if (object instanceof ISearchCacheAbleParam) {
return this.getRedisKeyBuilder((ISearchCacheAbleParam) object, searchCacheAble);
}
if (object instanceof HttpServletRequest) {
return this.getRedisKeyBuilder((HttpServletRequest) object, searchCacheAble);
}
if (object instanceof Map) {
return this.getRedisKeyBuilder((Map<?, ?>) object, searchCacheAble);
}
return null;
}
// 获取SearchCacheAbleParam的缓存key
private RedisKeyBuilder getRedisKeyBuilder(ISearchCacheAbleParam searchCacheAbleParam, SearchCacheAble searchCacheAble) {
String valueString = searchCacheAbleParam.toCacheKeyValue();
return this.getRedisKeyBuilderByParamKey(valueString, searchCacheAble);
}
// 获取httpServletRequest的缓存key
private RedisKeyBuilder getRedisKeyBuilder(HttpServletRequest httpServletRequest, SearchCacheAble searchCacheAble) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(httpServletRequest);
return this.getRedisKeyBuilder(paramMap, searchCacheAble);
}
// 获取请求的参数
private RedisKeyBuilder getRedisKeyBuilder(Map<?, ?> paramMap, SearchCacheAble searchCacheAble) {
List<String> includeParams = Arrays.asList(searchCacheAble.includeParams());
List<String> excludeParams = Arrays.asList(searchCacheAble.excludeParams());
String paramKey = "";
if (!includeParams.isEmpty()) {
paramKey = HttpServletRequestUtils.genParamStringWithIncludeParams(paramMap, includeParams);
} else if (!excludeParams.isEmpty()) {
paramKey = HttpServletRequestUtils.genParamStringWithExcludeParams(paramMap, excludeParams);
} else {
paramKey = HttpServletRequestUtils.genParamString(paramMap);
}
return this.getRedisKeyBuilderByParamKey(paramKey, searchCacheAble);
}
private RedisKeyBuilder getRedisKeyBuilderByParamKey(String paramKey,SearchCacheAble searchCacheAble){
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:AOP:");
redisKeyBuilder.appendFixed(searchCacheAble.cacheName()).appendFixed(":");
if(searchCacheAble.needMd5()){
redisKeyBuilder.appendVar(MD5Util.string2MD5(paramKey));
}else{
redisKeyBuilder.appendVar(paramKey);
}
return redisKeyBuilder;
}
}
package com.yoho.search.aop.cache;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.cache.CacheType;
import com.yoho.search.cache.beans.SearchCacheFactory;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.cache.beans.SearchCacheService;
@Component
@Aspect
@Order(Integer.MAX_VALUE-1)
public class SearchCacheAspect {
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private SearchCacheFactory searchCacheFactory;
@Around("@annotation(com.yoho.search.aop.cache.SearchCacheAble)")
public Object doCache(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
// 检查注解
SearchCacheAble searchCacheAble = signature.getMethod().getAnnotation(SearchCacheAble.class);
if (searchCacheAble == null) {
return pjp.proceed();
}
// 检查返回类型
Class<? extends Serializable> returnClass = this.getReturnClass(searchCacheAble, signature);
if (returnClass == null) {
return pjp.proceed();
}
// 检查cacheKey
RedisKeyBuilder redisKeyBuilder = this.getRedisKeyBuilder(pjp, searchCacheAble);
if (StringUtils.isBlank(redisKeyBuilder.getKey())){
return pjp.proceed();
}
SearchCache searchCache = searchCacheFactory.getAspectSearhCache(searchCacheAble);
boolean useJsonSerializable = searchCacheAble.cacheType().equals(CacheType.EHCACHE)?false:true;
Serializable cacheObject = searchCacheService.getSerializableObjectFromCache(searchCache, redisKeyBuilder, returnClass,useJsonSerializable);
if (cacheObject != null) {
return cacheObject;
}
Object result = pjp.proceed();
if (result == null) {
return result;
}
cacheObject = (Serializable) result;
if (cacheObject instanceof SearchApiResult && ((SearchApiResult) cacheObject).getCode() != 200) {
return cacheObject;
}
searchCacheService.addSerializableObjectToCache(searchCache, redisKeyBuilder, cacheObject,useJsonSerializable);
return cacheObject;
}
// 校验返回类型是否一致
private Class<? extends Serializable> getReturnClass(SearchCacheAble searchCacheAble, MethodSignature signature) {
final Class<?> returnType = signature.getMethod().getReturnType();
final Class<? extends Serializable> returnClass = searchCacheAble.returnClass();
if (!returnType.getName().equals(returnClass.getName())) {
return null;
}
return returnClass;
}
// 获取请求的参数
private RedisKeyBuilder getRedisKeyBuilder(ProceedingJoinPoint pjp, SearchCacheAble searchCacheAble) {
Object[] arges = pjp.getArgs();
Object object = arges[0];
if (object instanceof ISearchCacheAbleParam) {
return this.getRedisKeyBuilder((ISearchCacheAbleParam) object, searchCacheAble);
}
if (object instanceof HttpServletRequest) {
return this.getRedisKeyBuilder((HttpServletRequest) object, searchCacheAble);
}
if (object instanceof Map) {
return this.getRedisKeyBuilder((Map<?, ?>) object, searchCacheAble);
}
return null;
}
// 获取SearchCacheAbleParam的缓存key
private RedisKeyBuilder getRedisKeyBuilder(ISearchCacheAbleParam searchCacheAbleParam, SearchCacheAble searchCacheAble) {
String valueString = searchCacheAbleParam.toCacheKeyValue();
return this.getRedisKeyBuilderByParamKey(valueString, searchCacheAble);
}
// 获取httpServletRequest的缓存key
private RedisKeyBuilder getRedisKeyBuilder(HttpServletRequest httpServletRequest, SearchCacheAble searchCacheAble) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(httpServletRequest);
return this.getRedisKeyBuilder(paramMap, searchCacheAble);
}
// 获取请求的参数
private RedisKeyBuilder getRedisKeyBuilder(Map<?, ?> paramMap, SearchCacheAble searchCacheAble) {
List<String> includeParams = Arrays.asList(searchCacheAble.includeParams());
List<String> excludeParams = Arrays.asList(searchCacheAble.excludeParams());
String paramKey = "";
if (!includeParams.isEmpty()) {
paramKey = HttpServletRequestUtils.genParamStringWithIncludeParams(paramMap, includeParams);
} else if (!excludeParams.isEmpty()) {
paramKey = HttpServletRequestUtils.genParamStringWithExcludeParams(paramMap, excludeParams);
} else {
paramKey = HttpServletRequestUtils.genParamString(paramMap);
}
return this.getRedisKeyBuilderByParamKey(paramKey, searchCacheAble);
}
private RedisKeyBuilder getRedisKeyBuilderByParamKey(String paramKey,SearchCacheAble searchCacheAble){
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:AOP:");
redisKeyBuilder.appendFixed(searchCacheAble.cacheName()).appendFixed(":");
if(searchCacheAble.needMd5()){
redisKeyBuilder.appendVar(MD5Util.string2MD5(paramKey));
}else{
redisKeyBuilder.appendVar(paramKey);
}
return redisKeyBuilder;
}
}
... ...
package com.yoho.search.common.compress.aop;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface CommpressAble {
public boolean isCommpress() default false;
}
package com.yoho.search.aop.compress;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface CommpressAble {
public boolean isCommpress() default false;
}
... ...
package com.yoho.search.common.compress.aop;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.common.utils.SnappyUtils;
import com.yoho.search.models.SearchApiResult;
@Component
@Aspect
public class CommpressAspect {
// 获取请求的参数
private boolean isCommpress() {
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(httpServletRequest);
if(paramMap.containsKey("isDebug")){
return false;
}
return true;
}
@Around("@annotation(com.yoho.search.common.compress.aop.CommpressAble)")
public Object downGrade(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
final Class<?> returnType = signature.getMethod().getReturnType();
if (!returnType.isAssignableFrom(SearchApiResult.class)) {
return pjp.proceed();
}
Object result = pjp.proceed();
if (result == null) {
return result;
}
CommpressAble commpressAble = signature.getMethod().getAnnotation(CommpressAble.class);
SearchApiResult searchApiResult=(SearchApiResult)result;
if(commpressAble.isCommpress() && isCommpress()){
searchApiResult.setData(SnappyUtils.compress(searchApiResult.getData())).setCompress(true);
}
return searchApiResult;
}
}
package com.yoho.search.aop.compress;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.common.utils.SnappyUtils;
import com.yoho.search.models.SearchApiResult;
@Component
@Aspect
public class CommpressAspect {
// 获取请求的参数
private boolean isCommpress() {
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(httpServletRequest);
if(paramMap.containsKey("isDebug")){
return false;
}
return true;
}
@Around("@annotation(com.yoho.search.aop.compress.CommpressAble)")
public Object downGrade(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
final Class<?> returnType = signature.getMethod().getReturnType();
if (!returnType.isAssignableFrom(SearchApiResult.class)) {
return pjp.proceed();
}
Object result = pjp.proceed();
if (result == null) {
return result;
}
CommpressAble commpressAble = signature.getMethod().getAnnotation(CommpressAble.class);
SearchApiResult searchApiResult=(SearchApiResult)result;
if(commpressAble.isCommpress() && isCommpress()){
searchApiResult.setData(SnappyUtils.compress(searchApiResult.getData())).setCompress(true);
}
return searchApiResult;
}
}
... ...
package com.yoho.search.common.downgrade.persional;
package com.yoho.search.aop.downgrade;
import java.util.concurrent.atomic.AtomicInteger;
... ...
package com.yoho.search.common.downgrade.persional;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface PersionalRateLimit {
public int limit() default 100;// 总次数
public int second() default 10;// 总时间
public String name() default "";
public boolean isOrderUseable();// order参数是否对个性化有影响
}
package com.yoho.search.aop.downgrade;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
public @interface PersionalRateLimit {
public int limit() default 100;// 总次数
public int second() default 10;// 总时间
public String name() default "";
public boolean isOrderUseable();// order参数是否对个性化有影响
}
... ...
package com.yoho.search.common.downgrade.persional;
import java.lang.reflect.Method;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yoho.search.common.filter.YohoHttpServletGetRequestWrapper;
import com.yoho.search.service.base.SearchDynamicConfigService;
@Component
@Aspect
public class PersionalRateLimitAspect {
private static final Logger DOWNGRADE = LoggerFactory.getLogger("DOWNGRADE");
@Autowired
private PersionalRateLimitService persionalRateLimitService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Around("@annotation(com.yoho.search.common.downgrade.persional.PersionalRateLimit)")
public Object persionalRateLimit(ProceedingJoinPoint pjp) throws Throwable {
try {
//限流是否打开
if(!searchDynamicConfigService.isPersionalRateLimitOpen()){
return pjp.proceed();
}
MethodSignature signature = (MethodSignature) pjp.getSignature();
PersionalRateLimit rersionalRateLimit = signature.getMethod().getAnnotation(PersionalRateLimit.class);
String rateLimitName = this.getPersionalRateLimitName(rersionalRateLimit, pjp);
Object[] arges = pjp.getArgs();
for (Object object : arges) {
if (this.doPersionalRateLimit(object, rersionalRateLimit, rateLimitName)) {
break;
}
}
return pjp.proceed();
} catch (Exception e) {
DOWNGRADE.error(e.getMessage());
throw e;
}
}
private boolean doPersionalRateLimit(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (object instanceof YohoHttpServletGetRequestWrapper) {
return this.dealWithGetMethod(object, rateLimit, rateLimitName);
}
if (object instanceof Map) {
return this.dealWithPostMethod(object, rateLimit, rateLimitName);
}
return false;
}
/**
* 处理get请求的方式
*
* @param object
* @return
*/
private boolean dealWithGetMethod(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (!(object instanceof YohoHttpServletGetRequestWrapper)) {
return false;
}
YohoHttpServletGetRequestWrapper yohoHttpServletRequestWrapper = (YohoHttpServletGetRequestWrapper) object;
String uid = yohoHttpServletRequestWrapper.getParameter("uid");
if (StringUtils.isBlank(uid) || "0".equalsIgnoreCase(uid)) {
return false;
}
if (rateLimit.isOrderUseable() && StringUtils.isNotBlank(yohoHttpServletRequestWrapper.getParameter("order"))) {
return false;
}
PersionalRateLimitConfig limitConfig = searchDynamicConfigService.getPersionalRateLimitConfig(rateLimitName,rateLimit);
if (persionalRateLimitService.isPersionalRateLimit(rateLimitName, limitConfig)) {
yohoHttpServletRequestWrapper.addParams("uid", new String[] { "0" });
return true;
}
return false;
}
@SuppressWarnings("unchecked")
private boolean dealWithPostMethod(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (!(object instanceof Map)) {
return false;
}
Map<String, Object> map = (Map<String, Object>) object;
String uid = MapUtils.getString(map, "uid", "");
if (StringUtils.isBlank(uid) || "0".equalsIgnoreCase(uid)) {
return false;
}
if (rateLimit.isOrderUseable() && StringUtils.isNotBlank(MapUtils.getString(map, "order", ""))) {
return false;
}
PersionalRateLimitConfig limitConfig = searchDynamicConfigService.getPersionalRateLimitConfig(rateLimitName,rateLimit);
if (persionalRateLimitService.isPersionalRateLimit(rateLimitName, limitConfig)) {
map.put("uid", 0);
return true;
}
return false;
}
/**
* @controller层则获取url名称
* @service层则获取方法名称
* @param pjp
* @return
*/
private String getPersionalRateLimitName(PersionalRateLimit rersionalRateLimit, ProceedingJoinPoint pjp) {
if (StringUtils.isNotBlank(rersionalRateLimit.name())) {
return rersionalRateLimit.name();
}
// 1、获取method和class
Method targetMethod = ((MethodSignature) (pjp.getSignature())).getMethod();
Class<?> clazz = targetMethod.getDeclaringClass();
// 2、获取class上的requestMapping
String classRequestMappingValue = "";
RequestMapping classRequestMapping = clazz.getDeclaredAnnotation(RequestMapping.class);
if (classRequestMapping != null && classRequestMapping.value() != null && classRequestMapping.value().length > 0) {
classRequestMappingValue = classRequestMapping.value()[0];
}
// 3、获取method上的requestMapping
String methodRequestMappingValue = "";
RequestMapping methodRequestMapping = targetMethod.getDeclaredAnnotation(RequestMapping.class);
if (methodRequestMapping != null && methodRequestMapping.value() != null && methodRequestMapping.value().length > 0) {
methodRequestMappingValue = methodRequestMapping.value()[0];
}
// 4、获取key
if (StringUtils.isNotBlank(classRequestMappingValue) || StringUtils.isNotBlank(methodRequestMappingValue)) {
return classRequestMappingValue + methodRequestMappingValue;
} else {
return clazz.getName() + '.' + targetMethod.getName();
}
}
}
package com.yoho.search.aop.downgrade;
import java.lang.reflect.Method;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import com.yoho.search.common.filter.YohoHttpServletGetRequestWrapper;
import com.yoho.search.service.base.SearchDynamicConfigService;
@Component
@Aspect
public class PersionalRateLimitAspect {
private static final Logger DOWNGRADE = LoggerFactory.getLogger("DOWNGRADE");
@Autowired
private PersionalRateLimitService persionalRateLimitService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Around("@annotation(com.yoho.search.aop.downgrade.PersionalRateLimit)")
public Object persionalRateLimit(ProceedingJoinPoint pjp) throws Throwable {
try {
//限流是否打开
if(!searchDynamicConfigService.isPersionalRateLimitOpen()){
return pjp.proceed();
}
MethodSignature signature = (MethodSignature) pjp.getSignature();
PersionalRateLimit rersionalRateLimit = signature.getMethod().getAnnotation(PersionalRateLimit.class);
String rateLimitName = this.getPersionalRateLimitName(rersionalRateLimit, pjp);
Object[] arges = pjp.getArgs();
for (Object object : arges) {
if (this.doPersionalRateLimit(object, rersionalRateLimit, rateLimitName)) {
break;
}
}
return pjp.proceed();
} catch (Exception e) {
DOWNGRADE.error(e.getMessage());
throw e;
}
}
private boolean doPersionalRateLimit(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (object instanceof YohoHttpServletGetRequestWrapper) {
return this.dealWithGetMethod(object, rateLimit, rateLimitName);
}
if (object instanceof Map) {
return this.dealWithPostMethod(object, rateLimit, rateLimitName);
}
return false;
}
/**
* 处理get请求的方式
*
* @param object
* @return
*/
private boolean dealWithGetMethod(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (!(object instanceof YohoHttpServletGetRequestWrapper)) {
return false;
}
YohoHttpServletGetRequestWrapper yohoHttpServletRequestWrapper = (YohoHttpServletGetRequestWrapper) object;
String uid = yohoHttpServletRequestWrapper.getParameter("uid");
if (StringUtils.isBlank(uid) || "0".equalsIgnoreCase(uid)) {
return false;
}
if (rateLimit.isOrderUseable() && StringUtils.isNotBlank(yohoHttpServletRequestWrapper.getParameter("order"))) {
return false;
}
PersionalRateLimitConfig limitConfig = searchDynamicConfigService.getPersionalRateLimitConfig(rateLimitName,rateLimit);
if (persionalRateLimitService.isPersionalRateLimit(rateLimitName, limitConfig)) {
yohoHttpServletRequestWrapper.addParams("uid", new String[] { "0" });
return true;
}
return false;
}
@SuppressWarnings("unchecked")
private boolean dealWithPostMethod(Object object, PersionalRateLimit rateLimit, String rateLimitName) {
if (!(object instanceof Map)) {
return false;
}
Map<String, Object> map = (Map<String, Object>) object;
String uid = MapUtils.getString(map, "uid", "");
if (StringUtils.isBlank(uid) || "0".equalsIgnoreCase(uid)) {
return false;
}
if (rateLimit.isOrderUseable() && StringUtils.isNotBlank(MapUtils.getString(map, "order", ""))) {
return false;
}
PersionalRateLimitConfig limitConfig = searchDynamicConfigService.getPersionalRateLimitConfig(rateLimitName,rateLimit);
if (persionalRateLimitService.isPersionalRateLimit(rateLimitName, limitConfig)) {
map.put("uid", 0);
return true;
}
return false;
}
/**
* @controller层则获取url名称
* @service层则获取方法名称
* @param pjp
* @return
*/
private String getPersionalRateLimitName(PersionalRateLimit rersionalRateLimit, ProceedingJoinPoint pjp) {
if (StringUtils.isNotBlank(rersionalRateLimit.name())) {
return rersionalRateLimit.name();
}
// 1、获取method和class
Method targetMethod = ((MethodSignature) (pjp.getSignature())).getMethod();
Class<?> clazz = targetMethod.getDeclaringClass();
// 2、获取class上的requestMapping
String classRequestMappingValue = "";
RequestMapping classRequestMapping = clazz.getDeclaredAnnotation(RequestMapping.class);
if (classRequestMapping != null && classRequestMapping.value() != null && classRequestMapping.value().length > 0) {
classRequestMappingValue = classRequestMapping.value()[0];
}
// 3、获取method上的requestMapping
String methodRequestMappingValue = "";
RequestMapping methodRequestMapping = targetMethod.getDeclaredAnnotation(RequestMapping.class);
if (methodRequestMapping != null && methodRequestMapping.value() != null && methodRequestMapping.value().length > 0) {
methodRequestMappingValue = methodRequestMapping.value()[0];
}
// 4、获取key
if (StringUtils.isNotBlank(classRequestMappingValue) || StringUtils.isNotBlank(methodRequestMappingValue)) {
return classRequestMappingValue + methodRequestMappingValue;
} else {
return clazz.getName() + '.' + targetMethod.getName();
}
}
}
... ...
package com.yoho.search.common.downgrade.persional;
public class PersionalRateLimitConfig {
private int limit;
private int second;
public PersionalRateLimitConfig(int limit, int second) {
this.limit = limit;
this.second = second;
}
public PersionalRateLimitConfig(PersionalRateLimit rateLimit) {
super();
this.limit = rateLimit.limit();
this.second = rateLimit.second();
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public PersionalRateLimitConfig(String zkConfigValue) {
String[] values = zkConfigValue.split(":");
this.limit = Integer.valueOf(values[0]);
this.second = Integer.valueOf(values[1]);
}
public String toZkValue() {
return this.limit + ":" + this.second;
}
public String toLogInfo() {
StringBuilder sb = new StringBuilder();
sb.append(this.limit).append("c/").append(this.second).append("s");
return sb.toString();
}
}
package com.yoho.search.aop.downgrade;
public class PersionalRateLimitConfig {
private int limit;
private int second;
public PersionalRateLimitConfig(int limit, int second) {
this.limit = limit;
this.second = second;
}
public PersionalRateLimitConfig(PersionalRateLimit rateLimit) {
super();
this.limit = rateLimit.limit();
this.second = rateLimit.second();
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
this.limit = limit;
}
public int getSecond() {
return second;
}
public void setSecond(int second) {
this.second = second;
}
public PersionalRateLimitConfig(String zkConfigValue) {
String[] values = zkConfigValue.split(":");
this.limit = Integer.valueOf(values[0]);
this.second = Integer.valueOf(values[1]);
}
public String toZkValue() {
return this.limit + ":" + this.second;
}
public String toLogInfo() {
StringBuilder sb = new StringBuilder();
sb.append(this.limit).append("c/").append(this.second).append("s");
return sb.toString();
}
}
... ...
package com.yoho.search.common.downgrade.persional;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.service.base.SearchDynamicConfigService;
@Service
public class PersionalRateLimitService {
private static final Logger DOWNGRADE = LoggerFactory.getLogger("DOWNGRADE");
private Map<String, KeyCountWithExpiredTime> keyCountMap = new ConcurrentHashMap<String, KeyCountWithExpiredTime>();
private Map<String, Integer> oldCountMap = new ConcurrentHashMap<String, Integer>();
public boolean isPersionalRateLimit(String rateLimitName, PersionalRateLimitConfig limitConfig) {
try {
long expireTime = System.currentTimeMillis() + limitConfig.getSecond() * 1000L;
KeyCountWithExpiredTime keyCountWithExpiredTime = keyCountMap.putIfAbsent(rateLimitName, new KeyCountWithExpiredTime(expireTime));
if (keyCountWithExpiredTime == null) {
keyCountWithExpiredTime = keyCountMap.get(rateLimitName);
}
int currentCount = keyCountWithExpiredTime.incrementAndGet(expireTime);
Integer oldCount = oldCountMap.get(rateLimitName);
//第二轮再开始打上一轮降级日志
if (currentCount == 1 && oldCount != null) {
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}], oldCount is[{}], limitConfig is [{}]", rateLimitName,oldCount, limitConfig.toLogInfo());
oldCountMap.remove(rateLimitName);
}
if (currentCount <= limitConfig.getLimit()) {
return false;
}
oldCountMap.put(rateLimitName, currentCount);
return true;
}catch (Exception e){
DOWNGRADE.error(e.getMessage(),e);
return false;
}
}
}
package com.yoho.search.aop.downgrade;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service
public class PersionalRateLimitService {
private static final Logger DOWNGRADE = LoggerFactory.getLogger("DOWNGRADE");
private Map<String, KeyCountWithExpiredTime> keyCountMap = new ConcurrentHashMap<String, KeyCountWithExpiredTime>();
private Map<String, Integer> oldCountMap = new ConcurrentHashMap<String, Integer>();
public boolean isPersionalRateLimit(String rateLimitName, PersionalRateLimitConfig limitConfig) {
try {
long expireTime = System.currentTimeMillis() + limitConfig.getSecond() * 1000L;
KeyCountWithExpiredTime keyCountWithExpiredTime = keyCountMap.putIfAbsent(rateLimitName, new KeyCountWithExpiredTime(expireTime));
if (keyCountWithExpiredTime == null) {
keyCountWithExpiredTime = keyCountMap.get(rateLimitName);
}
int currentCount = keyCountWithExpiredTime.incrementAndGet(expireTime);
Integer oldCount = oldCountMap.get(rateLimitName);
//第二轮再开始打上一轮降级日志
if (currentCount == 1 && oldCount != null) {
DOWNGRADE.error("PersionalRateLimit happen ,rateLimitName is [{}], oldCount is[{}], limitConfig is [{}]", rateLimitName,oldCount, limitConfig.toLogInfo());
oldCountMap.remove(rateLimitName);
}
if (currentCount <= limitConfig.getLimit()) {
return false;
}
oldCountMap.put(rateLimitName, currentCount);
return true;
}catch (Exception e){
DOWNGRADE.error(e.getMessage(),e);
return false;
}
}
}
... ...
package com.yoho.search.models;
package com.yoho.search.aop.productlist;
import java.io.Serializable;
import java.util.ArrayList;
... ...
package com.yoho.search.common.productlist.aop;
package com.yoho.search.aop.productlist;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.ProductListWithSkn;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.beans.cache.SknReturnInfoCacheBean;
import org.aspectj.lang.ProceedingJoinPoint;
... ... @@ -29,7 +28,7 @@ public class ProductListWithSknAspect {
@Autowired
private SknReturnInfoCacheBean sknReturnInfoCacheBean;
@Around("@annotation(com.yoho.search.common.productlist.aop.ProductListWithSknRetention)")
@Around("@annotation(com.yoho.search.aop.productlist.ProductListWithSknRetention)")
public Object doTransferProductListWithSkn(ProceedingJoinPoint pjp) throws Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
final Class<?> returnType = signature.getMethod().getReturnType();
... ...
package com.yoho.search.common.productlist.aop;
package com.yoho.search.aop.productlist;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
... ...
package com.yoho.search.common.cache;
public enum CacheType {
EHCACHE, SEARCH_REDIS;
}
package com.yoho.search.cache;
public enum CacheType {
EHCACHE, SEARCH_REDIS;
}
... ...
package com.yoho.search.service.scene.common;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import com.yoho.search.common.cache.SearchCacheFactory;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.service.base.SearchCacheService;
public abstract class AbstractCacheAbleService {
@Autowired
protected SearchCacheService searchCacheService;
@Autowired
protected SearchCacheFactory searchCacheFactory;
protected SearchCache searchCache;
public abstract SearchCache getSearchCache();
@PostConstruct
void init(){
this.searchCache = getSearchCache();
}
}
package com.yoho.search.cache.beans;
import javax.annotation.PostConstruct;
import com.yoho.search.cache.model.SearchCache;
import org.springframework.beans.factory.annotation.Autowired;
public abstract class AbstractCacheAbleService {
@Autowired
protected SearchCacheService searchCacheService;
@Autowired
protected SearchCacheFactory searchCacheFactory;
protected SearchCache searchCache;
public abstract SearchCache getSearchCache();
@PostConstruct
void init(){
this.searchCache = getSearchCache();
}
}
... ...
package com.yoho.search.recall.beans.cache;
package com.yoho.search.cache.beans;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.impls.EhCache;
import com.yoho.search.cache.impls.SearchRedis;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.ICacheRequest;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ...
package com.yoho.search.recall.beans.persional;
package com.yoho.search.cache.beans;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.cache.impls.EhCache;
import com.yoho.search.cache.impls.SearchRedis;
import com.yoho.search.cache.model.CacheObject;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public abstract class AbstractPageComponent<T> {
@Autowired
... ...
package com.yoho.search.common.cache;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.cache.impls.CacheInterface;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.common.cache.model.SearchCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class SearchCacheFactory {
@Autowired
private EhCache ehCache;
@Autowired
private SearchRedis searchRedis;
private Map<String, SearchCache> cacheMap = new ConcurrentHashMap<String, SearchCache>();
private CacheInterface getCacheInterface(CacheType cacheType) {
if (cacheType == CacheType.EHCACHE) {
return ehCache;
}
if (cacheType == CacheType.SEARCH_REDIS) {
return searchRedis;
}
return null;
}
private SearchCache getOrCreateSearchCache(String cacheKey, CacheType cacheType, int cacheInMinute) {
CacheInterface cacheInterface = this.getCacheInterface(cacheType);
String cacheName = new StringBuilder(cacheKey).append("_").append(cacheType.name()).append("_").append(cacheInMinute).toString();
return cacheMap.computeIfAbsent(cacheName, key -> new SearchCache(cacheName, cacheInterface, cacheInMinute));
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getAggregationSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("AGGREGATION", cacheType, cacheInMinute);
}
/**
* 获取默认的搜索缓存
*
* @return
*/
public SearchCache getProductCountSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PRODUCT_COUNT", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForAppCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_APP", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForPcCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_PC", cacheType, cacheInMinute);
}
/**
* 个性化聚合推荐相关的缓存
*
* @return
*/
public SearchCache getRecommendCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("RECOMMEND", cacheType, cacheInMinute);
}
/**
* 品牌相关的缓存
*
* @return
*/
public SearchCache getBrandRelatedCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("BRAND_RELATED", cacheType, cacheInMinute);
}
/**
* aop的缓存
*
* @return
*/
public SearchCache getAspectSearhCache(SearchCacheAble searchCacheAble) {
CacheType cacheType = searchCacheAble.cacheType();
return this.getOrCreateSearchCache("AOP_" + searchCacheAble.cacheName(), cacheType, searchCacheAble.cacheInMinute());
}
/**
* 场景化筛选项的缓存
*
* @return
*/
public SearchCache getSceneAggregationsCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SCENE_AGGREGATIONS", cacheType, cacheInMinute);
}
/**
* 促销专区的缓存
*
* @return
*/
public SearchCache getPromotionSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PROMOTION", cacheType, cacheInMinute);
}
/**
* PC列表的缓存
*
* @return
*/
public SearchCache getWebProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("WEB_PRODUCT_LIST", cacheType, cacheInMinute);
}
/**
* 有好货的缓存
*
* @return
*/
public SearchCache goodProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("GOOD_PRODUCT", cacheType, cacheInMinute);
}
}
package com.yoho.search.cache.beans;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.cache.CacheType;
import com.yoho.search.cache.impls.CacheInterface;
import com.yoho.search.cache.impls.EhCache;
import com.yoho.search.cache.impls.SearchRedis;
import com.yoho.search.cache.model.SearchCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Service
public class SearchCacheFactory {
@Autowired
private EhCache ehCache;
@Autowired
private SearchRedis searchRedis;
private Map<String, SearchCache> cacheMap = new ConcurrentHashMap<String, SearchCache>();
private CacheInterface getCacheInterface(CacheType cacheType) {
if (cacheType == CacheType.EHCACHE) {
return ehCache;
}
if (cacheType == CacheType.SEARCH_REDIS) {
return searchRedis;
}
return null;
}
private SearchCache getOrCreateSearchCache(String cacheKey, CacheType cacheType, int cacheInMinute) {
CacheInterface cacheInterface = this.getCacheInterface(cacheType);
String cacheName = new StringBuilder(cacheKey).append("_").append(cacheType.name()).append("_").append(cacheInMinute).toString();
return cacheMap.computeIfAbsent(cacheName, key -> new SearchCache(cacheName, cacheInterface, cacheInMinute));
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getAggregationSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("AGGREGATION", cacheType, cacheInMinute);
}
/**
* 获取默认的搜索缓存
*
* @return
*/
public SearchCache getProductCountSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PRODUCT_COUNT", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForAppCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_APP", cacheType, cacheInMinute);
}
/**
* 获取聚合相关的缓存
*
* @return
*/
public SearchCache getSelectionsForPcCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SELECTIONS_PC", cacheType, cacheInMinute);
}
/**
* 个性化聚合推荐相关的缓存
*
* @return
*/
public SearchCache getRecommendCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("RECOMMEND", cacheType, cacheInMinute);
}
/**
* 品牌相关的缓存
*
* @return
*/
public SearchCache getBrandRelatedCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("BRAND_RELATED", cacheType, cacheInMinute);
}
/**
* aop的缓存
*
* @return
*/
public SearchCache getAspectSearhCache(SearchCacheAble searchCacheAble) {
CacheType cacheType = searchCacheAble.cacheType();
return this.getOrCreateSearchCache("AOP_" + searchCacheAble.cacheName(), cacheType, searchCacheAble.cacheInMinute());
}
/**
* 场景化筛选项的缓存
*
* @return
*/
public SearchCache getSceneAggregationsCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("SCENE_AGGREGATIONS", cacheType, cacheInMinute);
}
/**
* 促销专区的缓存
*
* @return
*/
public SearchCache getPromotionSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("PROMOTION", cacheType, cacheInMinute);
}
/**
* PC列表的缓存
*
* @return
*/
public SearchCache getWebProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("WEB_PRODUCT_LIST", cacheType, cacheInMinute);
}
/**
* 有好货的缓存
*
* @return
*/
public SearchCache goodProductListSearchCache() {
CacheType cacheType = CacheType.SEARCH_REDIS;
int cacheInMinute = 15;
return this.getOrCreateSearchCache("GOOD_PRODUCT", cacheType, cacheInMinute);
}
}
... ...
package com.yoho.search.service.base;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.common.SearchServiceConfiger;
import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.SearchParamUtils;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
@Service
public class SearchCacheService {
@Autowired
private SearchServiceConfiger searchServiceConfiger;
private void addObjectToCache(RedisKeyBuilder redisKeyBuilder, Object object, SearchCache searchCache) {
// 1、如果不适用缓存,则直接返回
if (!searchServiceConfiger.useCache()) {
return;
}
// 2、如果缓存不存在,则直接返回
if (searchCache == null || searchCache.getCache() == null) {
return;
}
// 3、加入缓存
CacheObject cacheObject = null;
if (object instanceof JSONObject) {
cacheObject = new CacheObject((JSONObject) object);
} else if (object instanceof JSONArray) {
cacheObject = new CacheObject((JSONArray) object);
} else {
cacheObject = new CacheObject(object);
}
searchCache.getCache().addOrUpdate(redisKeyBuilder, cacheObject, searchCache.getCacheInMinute());
}
/**
* 从缓存中取数据
*
* @param redisKeyBuilder
* @return
*/
private CacheObject getCacheObjectFromCache(RedisKeyBuilder redisKeyBuilder, SearchCache searchCache) {
// 1、如果不适用缓存,则直接返回
if (!searchServiceConfiger.useCache()) {
return null;
}
// 2、如果缓存不存在,则直接返回
if (searchCache == null || searchCache.getCache() == null) {
return null;
}
// 3、增加缓存访问次数
searchCache.incTotalCount();
// 4、从缓存中获取cacheObject
CacheObject cacheObject = searchCache.getCache().get(redisKeyBuilder);
// 5、如果从缓存中拿不到数据,则直接返回
if (cacheObject == null) {
return null;
}
// 6、增加缓存命中次数,并返回缓存对象
searchCache.incMatchCount();
return cacheObject;
}
/*********************************** JSONObject *****************************************/
public RedisKeyBuilder genSearchParamString(String indexName, SearchParam searchParam) {
//1、拼装内容
StringBuilder redisKeyValue = new StringBuilder();
redisKeyValue.append("indexName:").append(indexName).append(';');
redisKeyValue.append("searchType:").append(searchParam.getSearchType() == null ? "" : searchParam.getSearchType().name()).append(';');
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
redisKeyValue.append("searchSource:").append(searchSourceBuilder).append(';');
//2、构建RedisKeyBuilder
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:");
redisKeyBuilder.appendFixed("DEFAULT1:");
redisKeyBuilder.appendVar(MD5Util.string2MD5(redisKeyValue.toString()));
return redisKeyBuilder;
}
private RedisKeyBuilder genSearchParamString(String indexName, List<SearchParam> searchParams) {
//1、拼装内容
StringBuilder redisKeyValue = new StringBuilder();
// 拼装索引名称
redisKeyValue.append("indexName:").append(indexName).append(';');
for (SearchParam searchParam : searchParams) {
// 拼装搜索类型
redisKeyValue.append("searchType:").append(searchParam.getSearchType() == null ? "" : searchParam.getSearchType().name()).append(';');
// 拼装报文
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
redisKeyValue.append("searchSource:").append(searchSourceBuilder).append(';');
}
//2、构建RedisKeyBuilder
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:");
redisKeyBuilder.appendFixed("DEFAULT2:");
redisKeyBuilder.appendVar(MD5Util.string2MD5(redisKeyValue.toString()));
return redisKeyBuilder;
}
public void addJSONObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, JSONObject jsonObject) {
this.addObjectToCache(redisKeyBuilder, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder) {
CacheObject cacheObject = this.getCacheObjectFromCache(redisKeyBuilder, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
public void addJSONObjectToCache(SearchCache searchCache, String indexName, SearchParam searchParam, JSONObject jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, String indexName, SearchParam searchParam) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
public void addJSONObjectToCache(SearchCache searchCache, String indexName, List<SearchParam> searchParams, JSONObject jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParams);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, String indexName, List<SearchParam> searchParams) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParams);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
/*********************************** JSONArray *****************************************/
public void addJSONArrayToCache(SearchCache searchCache, String indexName, SearchParam searchParam, JSONArray jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONArray getJSONArrayFromCache(SearchCache searchCache, String indexName, SearchParam searchParam) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONArray();
}
/*********************************** SearchApiResult *****************************************/
@SuppressWarnings("unchecked")
public <T extends Serializable> T getSerializableObjectFromCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, Class<T> clazz, boolean useJsonSerializable) {
try {
CacheObject cacheObject = this.getCacheObjectFromCache(redisKeyBuilder, searchCache);
if (cacheObject == null) {
return null;
}
if (useJsonSerializable) {
JSONObject searchApiResultJSONObject = cacheObject.toJSONObject();
return JSON.toJavaObject(searchApiResultJSONObject, clazz);
} else {
return (T) cacheObject.getValue();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public <T extends Serializable> void addSerializableObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, T object, boolean useJsonSerializable) {
if (useJsonSerializable) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(object);
this.addObjectToCache(redisKeyBuilder, jsonObject, searchCache);
} else {
this.addObjectToCache(redisKeyBuilder, object, searchCache);
}
}
}
package com.yoho.search.cache.beans;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.common.SearchServiceConfiger;
import com.yoho.search.cache.model.CacheObject;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.SearchParamUtils;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;
@Service
public class SearchCacheService {
@Autowired
private SearchServiceConfiger searchServiceConfiger;
private void addObjectToCache(RedisKeyBuilder redisKeyBuilder, Object object, SearchCache searchCache) {
// 1、如果不适用缓存,则直接返回
if (!searchServiceConfiger.useCache()) {
return;
}
// 2、如果缓存不存在,则直接返回
if (searchCache == null || searchCache.getCache() == null) {
return;
}
// 3、加入缓存
CacheObject cacheObject = null;
if (object instanceof JSONObject) {
cacheObject = new CacheObject((JSONObject) object);
} else if (object instanceof JSONArray) {
cacheObject = new CacheObject((JSONArray) object);
} else {
cacheObject = new CacheObject(object);
}
searchCache.getCache().addOrUpdate(redisKeyBuilder, cacheObject, searchCache.getCacheInMinute());
}
/**
* 从缓存中取数据
*
* @param redisKeyBuilder
* @return
*/
private CacheObject getCacheObjectFromCache(RedisKeyBuilder redisKeyBuilder, SearchCache searchCache) {
// 1、如果不适用缓存,则直接返回
if (!searchServiceConfiger.useCache()) {
return null;
}
// 2、如果缓存不存在,则直接返回
if (searchCache == null || searchCache.getCache() == null) {
return null;
}
// 3、增加缓存访问次数
searchCache.incTotalCount();
// 4、从缓存中获取cacheObject
CacheObject cacheObject = searchCache.getCache().get(redisKeyBuilder);
// 5、如果从缓存中拿不到数据,则直接返回
if (cacheObject == null) {
return null;
}
// 6、增加缓存命中次数,并返回缓存对象
searchCache.incMatchCount();
return cacheObject;
}
/*********************************** JSONObject *****************************************/
public RedisKeyBuilder genSearchParamString(String indexName, SearchParam searchParam) {
//1、拼装内容
StringBuilder redisKeyValue = new StringBuilder();
redisKeyValue.append("indexName:").append(indexName).append(';');
redisKeyValue.append("searchType:").append(searchParam.getSearchType() == null ? "" : searchParam.getSearchType().name()).append(';');
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
redisKeyValue.append("searchSource:").append(searchSourceBuilder).append(';');
//2、构建RedisKeyBuilder
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:");
redisKeyBuilder.appendFixed("DEFAULT1:");
redisKeyBuilder.appendVar(MD5Util.string2MD5(redisKeyValue.toString()));
return redisKeyBuilder;
}
private RedisKeyBuilder genSearchParamString(String indexName, List<SearchParam> searchParams) {
//1、拼装内容
StringBuilder redisKeyValue = new StringBuilder();
// 拼装索引名称
redisKeyValue.append("indexName:").append(indexName).append(';');
for (SearchParam searchParam : searchParams) {
// 拼装搜索类型
redisKeyValue.append("searchType:").append(searchParam.getSearchType() == null ? "" : searchParam.getSearchType().name()).append(';');
// 拼装报文
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
redisKeyValue.append("searchSource:").append(searchSourceBuilder).append(';');
}
//2、构建RedisKeyBuilder
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
redisKeyBuilder.appendFixed("YOHOSEARCH:");
redisKeyBuilder.appendFixed("DEFAULT2:");
redisKeyBuilder.appendVar(MD5Util.string2MD5(redisKeyValue.toString()));
return redisKeyBuilder;
}
public void addJSONObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, JSONObject jsonObject) {
this.addObjectToCache(redisKeyBuilder, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder) {
CacheObject cacheObject = this.getCacheObjectFromCache(redisKeyBuilder, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
public void addJSONObjectToCache(SearchCache searchCache, String indexName, SearchParam searchParam, JSONObject jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, String indexName, SearchParam searchParam) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
public void addJSONObjectToCache(SearchCache searchCache, String indexName, List<SearchParam> searchParams, JSONObject jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParams);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONObject getJSONObjectFromCache(SearchCache searchCache, String indexName, List<SearchParam> searchParams) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParams);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONObject();
}
/*********************************** JSONArray *****************************************/
public void addJSONArrayToCache(SearchCache searchCache, String indexName, SearchParam searchParam, JSONArray jsonObject) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
this.addObjectToCache(key, jsonObject, searchCache);
}
public JSONArray getJSONArrayFromCache(SearchCache searchCache, String indexName, SearchParam searchParam) {
RedisKeyBuilder key = this.genSearchParamString(indexName, searchParam);
CacheObject cacheObject = this.getCacheObjectFromCache(key, searchCache);
if (cacheObject == null) {
return null;
}
return cacheObject.toJSONArray();
}
/*********************************** SearchApiResult *****************************************/
@SuppressWarnings("unchecked")
public <T extends Serializable> T getSerializableObjectFromCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, Class<T> clazz, boolean useJsonSerializable) {
try {
CacheObject cacheObject = this.getCacheObjectFromCache(redisKeyBuilder, searchCache);
if (cacheObject == null) {
return null;
}
if (useJsonSerializable) {
JSONObject searchApiResultJSONObject = cacheObject.toJSONObject();
return JSON.toJavaObject(searchApiResultJSONObject, clazz);
} else {
return (T) cacheObject.getValue();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public <T extends Serializable> void addSerializableObjectToCache(SearchCache searchCache, RedisKeyBuilder redisKeyBuilder, T object, boolean useJsonSerializable) {
if (useJsonSerializable) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(object);
this.addObjectToCache(redisKeyBuilder, jsonObject, searchCache);
} else {
this.addObjectToCache(redisKeyBuilder, object, searchCache);
}
}
}
... ...
package com.yoho.search.common.cache.impls;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.common.cache.model.CacheObject;
import java.util.*;
public interface CacheInterface {
public boolean exist(RedisKeyBuilder redisKeyBuilder);
public CacheObject get(RedisKeyBuilder redisKeyBuilder);
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute);
public void mutiSet(final Map<RedisKeyBuilder,String> map, final int expiredTimeInMinute);
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) ;
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute);
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets);
}
package com.yoho.search.cache.impls;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.cache.model.CacheObject;
import java.util.*;
public interface CacheInterface {
public boolean exist(RedisKeyBuilder redisKeyBuilder);
public CacheObject get(RedisKeyBuilder redisKeyBuilder);
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute);
public void mutiSet(final Map<RedisKeyBuilder,String> map, final int expiredTimeInMinute);
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) ;
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute);
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets);
}
... ...
package com.yoho.search.common.cache.impls;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.common.cache.model.CacheObject;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Statistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.InputStream;
import java.util.*;
@Service("ehCache")
public class EhCache implements CacheInterface {
private static final Logger logger = LoggerFactory.getLogger(EhCache.class);
private CacheManager manager;
private Cache cache;
private EhCache() {
}
@PostConstruct
private void init() {
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ehcache.xml");
this.manager = CacheManager.create(inputStream);
this.cache = manager.getCache("yohosearch");
} catch (Throwable e) {
e.printStackTrace();
}
}
public Statistics getStatistics(){
return cache.getStatistics();
}
@PreDestroy
private void destroy() {
if (this.manager != null) {
this.manager.shutdown();
}
}
@Override
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
try {
Element element = new Element(redisKeyBuilder.getKey(), value);
element.setTimeToLive(expiredTimeInMinute * 60);
cache.put(element);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
try {
Element e = cache.get(redisKeyBuilder.getKey());
return (e == null) ? null : (CacheObject) e.getObjectValue();
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
@Override
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
return this.get(redisKeyBuilder) == null ? false : true;
}
@Override
public void mutiSet(final Map<RedisKeyBuilder,String> map, final int expiredTimeInMinute) {
try {
Collection<Element> elements = new ArrayList<>();
for (Map.Entry<RedisKeyBuilder, ? extends String> entry: map.entrySet()) {
Element element = new Element(entry.getKey().getKey(), entry.getValue());
element.setTimeToLive(expiredTimeInMinute * 60);
elements.add(element);
}
cache.putAll(elements);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) {
Collection<String> keys = new ArrayList<>();
for (RedisKeyBuilder redisKeyBuilder:redisKeyBuilders) {
keys.add(redisKeyBuilder.getKey());
}
Map<Object, Element> elementMap = cache.getAll(keys);
List<String> values = new ArrayList<>();
for (RedisKeyBuilder redisKeyBuilder:redisKeyBuilders) {
Element element = elementMap.get(redisKeyBuilder.getKey());
if(element==null){
values.add(null);
}else{
values.add((String)element.getObjectValue());
}
}
return values;
}
@Override
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute) {
try {
Element element = new Element(redisKeyBuilder.getKey(),bitSet);
element.setTimeToLive(expiredTimeInMinute * 60);
cache.put(element);
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets){
try {
Element e = this.cache.get(key.getKey());
if(e==null){
return null;
}
BitSet cacheBitSet = (BitSet)e.getObjectValue();
Map<Integer, Boolean> results = new HashMap<>();
for (Integer offset:offsets) {
results.put(offset,cacheBitSet.get(offset));
}
return results;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
}
package com.yoho.search.cache.impls;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.cache.model.CacheObject;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Statistics;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.InputStream;
import java.util.*;
@Service("ehCache")
public class EhCache implements CacheInterface {
private static final Logger logger = LoggerFactory.getLogger(EhCache.class);
private CacheManager manager;
private Cache cache;
private EhCache() {
}
@PostConstruct
private void init() {
try {
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("ehcache.xml");
this.manager = CacheManager.create(inputStream);
this.cache = manager.getCache("yohosearch");
} catch (Throwable e) {
e.printStackTrace();
}
}
public Statistics getStatistics(){
return cache.getStatistics();
}
@PreDestroy
private void destroy() {
if (this.manager != null) {
this.manager.shutdown();
}
}
@Override
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
try {
Element element = new Element(redisKeyBuilder.getKey(), value);
element.setTimeToLive(expiredTimeInMinute * 60);
cache.put(element);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
try {
Element e = cache.get(redisKeyBuilder.getKey());
return (e == null) ? null : (CacheObject) e.getObjectValue();
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
@Override
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
return this.get(redisKeyBuilder) == null ? false : true;
}
@Override
public void mutiSet(final Map<RedisKeyBuilder,String> map, final int expiredTimeInMinute) {
try {
Collection<Element> elements = new ArrayList<>();
for (Map.Entry<RedisKeyBuilder, ? extends String> entry: map.entrySet()) {
Element element = new Element(entry.getKey().getKey(), entry.getValue());
element.setTimeToLive(expiredTimeInMinute * 60);
elements.add(element);
}
cache.putAll(elements);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) {
Collection<String> keys = new ArrayList<>();
for (RedisKeyBuilder redisKeyBuilder:redisKeyBuilders) {
keys.add(redisKeyBuilder.getKey());
}
Map<Object, Element> elementMap = cache.getAll(keys);
List<String> values = new ArrayList<>();
for (RedisKeyBuilder redisKeyBuilder:redisKeyBuilders) {
Element element = elementMap.get(redisKeyBuilder.getKey());
if(element==null){
values.add(null);
}else{
values.add((String)element.getObjectValue());
}
}
return values;
}
@Override
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute) {
try {
Element element = new Element(redisKeyBuilder.getKey(),bitSet);
element.setTimeToLive(expiredTimeInMinute * 60);
cache.put(element);
return true;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets){
try {
Element e = this.cache.get(key.getKey());
if(e==null){
return null;
}
BitSet cacheBitSet = (BitSet)e.getObjectValue();
Map<Integer, Boolean> results = new HashMap<>();
for (Integer offset:offsets) {
results.put(offset,cacheBitSet.get(offset));
}
return results;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
}
... ...
package com.yoho.search.common.cache.impls;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.common.utils.RedisCacheUtils;
import com.yoho.search.core.redis.components.YohoSearchRedisComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Service("searchRedis")
public class SearchRedis implements CacheInterface {
private static final Logger logger = LoggerFactory.getLogger(SearchRedis.class);
@Autowired
private YohoSearchRedisComponent yohoSearchRedisComponent;
@Override
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
try {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
return RedisCacheUtils.exist(redisTemplate, redisKeyBuilder);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
try {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
return RedisCacheUtils.get(valueOperations, redisKeyBuilder, CacheObject.class);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
@Override
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
try {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
RedisCacheUtils.add(valueOperations, redisKeyBuilder, value, expiredTimeInMinute);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public void mutiSet(Map<RedisKeyBuilder, String> map, int expiredTimeInMinute) {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
RedisCacheUtils.mutiSet(redisTemplate, map, expiredTimeInMinute);
}
@Override
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
return RedisCacheUtils.mutiGet(valueOperations, redisKeyBuilders);
}
@Override
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute) {
try {
return RedisCacheUtils.setBitSet(yohoSearchRedisComponent.getRedisTemplate(), redisKeyBuilder, bitSet, expiredTimeInMinute);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets) {
try {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
if (!redisTemplate.hasKey(key)) {
return null;
}
return RedisCacheUtils.getBits(redisTemplate, key, offsets);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
}
package com.yoho.search.cache.impls;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.cache.model.CacheObject;
import com.yoho.search.common.utils.RedisCacheUtils;
import com.yoho.search.core.redis.components.YohoSearchRedisComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.BitSet;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@Service("searchRedis")
public class SearchRedis implements CacheInterface {
private static final Logger logger = LoggerFactory.getLogger(SearchRedis.class);
@Autowired
private YohoSearchRedisComponent yohoSearchRedisComponent;
@Override
public boolean exist(RedisKeyBuilder redisKeyBuilder) {
try {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
return RedisCacheUtils.exist(redisTemplate, redisKeyBuilder);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public CacheObject get(RedisKeyBuilder redisKeyBuilder) {
try {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
return RedisCacheUtils.get(valueOperations, redisKeyBuilder, CacheObject.class);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
@Override
public void addOrUpdate(RedisKeyBuilder redisKeyBuilder, CacheObject value, int expiredTimeInMinute) {
try {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
RedisCacheUtils.add(valueOperations, redisKeyBuilder, value, expiredTimeInMinute);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public void mutiSet(Map<RedisKeyBuilder, String> map, int expiredTimeInMinute) {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
RedisCacheUtils.mutiSet(redisTemplate, map, expiredTimeInMinute);
}
@Override
public List<String> mutiGet(Collection<RedisKeyBuilder> redisKeyBuilders) {
YHValueOperations valueOperations = yohoSearchRedisComponent.getValueOperations();
return RedisCacheUtils.mutiGet(valueOperations, redisKeyBuilders);
}
@Override
public boolean setBitSet(RedisKeyBuilder redisKeyBuilder, BitSet bitSet, int expiredTimeInMinute) {
try {
return RedisCacheUtils.setBitSet(yohoSearchRedisComponent.getRedisTemplate(), redisKeyBuilder, bitSet, expiredTimeInMinute);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return false;
}
}
@Override
public Map<Integer, Boolean> getFromBitSet(RedisKeyBuilder key, Collection<Integer> offsets) {
try {
YHRedisTemplate redisTemplate = yohoSearchRedisComponent.getRedisTemplate();
if (!redisTemplate.hasKey(key)) {
return null;
}
return RedisCacheUtils.getBits(redisTemplate, key, offsets);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return null;
}
}
}
... ...
package com.yoho.search.common.cache;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yoho.search.base.utils.HttpServletRequestUtils;
public class SearchCacheMatchLogger {
private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) {
if(CACHE_MATCH_REQUEST.isInfoEnabled()){
CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap));
}
}
public static void doSearchCacheMatchLog(String method, String key) {
if(CACHE_MATCH_REQUEST.isInfoEnabled()){
CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key);
}
}
}
package com.yoho.search.cache.log;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.yoho.search.base.utils.HttpServletRequestUtils;
public class SearchCacheMatchLogger {
private static final Logger CACHE_MATCH_REQUEST = LoggerFactory.getLogger("CACHE_MATCH_REQUEST");
public static void doSearchCacheMatchLog(String url, Map<String, String> paramMap) {
if(CACHE_MATCH_REQUEST.isInfoEnabled()){
CACHE_MATCH_REQUEST.info("match cache , url is :{}?{}", url, HttpServletRequestUtils.genParamString(paramMap));
}
}
public static void doSearchCacheMatchLog(String method, String key) {
if(CACHE_MATCH_REQUEST.isInfoEnabled()){
CACHE_MATCH_REQUEST.info("match cache , method is :{}, key is {}", method, key);
}
}
}
... ...
package com.yoho.search.recall.models.common;
package com.yoho.search.cache.model;
public abstract class AbstractCacheRequestResponse<Request extends ICacheRequest,Response> extends AbstractCacheResponse<Response> {
... ...
package com.yoho.search.recall.models.common;
package com.yoho.search.cache.model;
import com.yoho.search.base.utils.Transfer;
... ...
package com.yoho.search.common.cache.model;
import java.util.concurrent.atomic.AtomicLong;
public class CacheCount {
private AtomicLong totalCount = null;
private AtomicLong matchCount = null;
public CacheCount(){
this.totalCount = new AtomicLong(0);
this.matchCount = new AtomicLong(0);
}
public CacheCount(long totalCountVal,long matchCountVal){
this.totalCount = new AtomicLong(totalCountVal);
this.matchCount = new AtomicLong(matchCountVal);
}
public void clear() {
this.totalCount = new AtomicLong(0);
this.matchCount = new AtomicLong(0);
}
public void incTotalCount() {
totalCount.incrementAndGet();
}
public void incMatchCount() {
matchCount.incrementAndGet();
}
public AtomicLong getTotalCount() {
return totalCount;
}
public AtomicLong getMatchCount() {
return matchCount;
}
public int getMatchPercent() {
long matchCnt = matchCount.longValue();
long totalCnt = totalCount.longValue();
if (totalCnt == 0) {
return 0;
}
return (int) (matchCnt * 100L / totalCnt);
}
@Override
public String toString() {
return "CacheCount [totalCount=" + totalCount + ", matchCount=" + matchCount + ", matchPercent=" + getMatchPercent() + "]";
}
}
package com.yoho.search.cache.model;
import java.util.concurrent.atomic.AtomicLong;
public class CacheCount {
private AtomicLong totalCount = null;
private AtomicLong matchCount = null;
public CacheCount(){
this.totalCount = new AtomicLong(0);
this.matchCount = new AtomicLong(0);
}
public CacheCount(long totalCountVal,long matchCountVal){
this.totalCount = new AtomicLong(totalCountVal);
this.matchCount = new AtomicLong(matchCountVal);
}
public void clear() {
this.totalCount = new AtomicLong(0);
this.matchCount = new AtomicLong(0);
}
public void incTotalCount() {
totalCount.incrementAndGet();
}
public void incMatchCount() {
matchCount.incrementAndGet();
}
public AtomicLong getTotalCount() {
return totalCount;
}
public AtomicLong getMatchCount() {
return matchCount;
}
public int getMatchPercent() {
long matchCnt = matchCount.longValue();
long totalCnt = totalCount.longValue();
if (totalCnt == 0) {
return 0;
}
return (int) (matchCnt * 100L / totalCnt);
}
@Override
public String toString() {
return "CacheCount [totalCount=" + totalCount + ", matchCount=" + matchCount + ", matchPercent=" + getMatchPercent() + "]";
}
}
... ...
package com.yoho.search.common.cache.model;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CacheMatchLogger {
private static final Logger CACHE_MATCH = LoggerFactory.getLogger("CACHE_MATCH");
private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
private CacheCount cacheCount = new CacheCount();
public void init(String cacheName,int cacheInMinute,int logPeriodInMinute) {
// 每1分钟记录下缓存命中率
scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// 记录cacheService的缓存命中率
if(cacheCount.getTotalCount().get()>0){
CACHE_MATCH.info("cacheName is [{}] , cacheInMinute is [{}],[{}]",cacheName,cacheInMinute,cacheCount);
}
cacheCount.clear();
}
}, logPeriodInMinute, logPeriodInMinute, TimeUnit.MINUTES);
}
public void incTotalCount(){
cacheCount.incTotalCount();
}
public void incMatchCount(){
cacheCount.incMatchCount();
}
}
package com.yoho.search.cache.model;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import com.yoho.search.cache.model.CacheCount;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CacheMatchLogger {
private static final Logger CACHE_MATCH = LoggerFactory.getLogger("CACHE_MATCH");
private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
private CacheCount cacheCount = new CacheCount();
public void init(String cacheName,int cacheInMinute,int logPeriodInMinute) {
// 每1分钟记录下缓存命中率
scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
// 记录cacheService的缓存命中率
if(cacheCount.getTotalCount().get()>0){
CACHE_MATCH.info("cacheName is [{}] , cacheInMinute is [{}],[{}]",cacheName,cacheInMinute,cacheCount);
}
cacheCount.clear();
}
}, logPeriodInMinute, logPeriodInMinute, TimeUnit.MINUTES);
}
public void incTotalCount(){
cacheCount.incTotalCount();
}
public void incMatchCount(){
cacheCount.incMatchCount();
}
}
... ...
package com.yoho.search.common.cache.model;
import java.io.Serializable;
package com.yoho.search.cache.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import java.io.Serializable;
/**
* 暂时只支持JSONObject和jsonArray
*
... ...
package com.yoho.search.recall.models.common;
package com.yoho.search.cache.model;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
... ...
package com.yoho.search.common.cache.model;
import com.yoho.search.common.cache.impls.CacheInterface;
public class SearchCache {
private static final int logPeriodInMinute = 1;// 默认每分钟打印一次日志
private CacheInterface cacheInterface;// 缓存类型
private int cacheInMinute = 5;// 缓存时间
private CacheMatchLogger cacheMatchLogger;
public SearchCache(String cacheName, CacheInterface cacheInterface, int cacheInMinute) {
super();
this.cacheInMinute = cacheInMinute;
this.cacheInterface = cacheInterface;
this.cacheMatchLogger = new CacheMatchLogger();
cacheMatchLogger.init(cacheName, cacheInMinute, logPeriodInMinute);
}
public CacheInterface getCache() {
return cacheInterface;
}
public void incTotalCount() {
cacheMatchLogger.incTotalCount();
}
public void incMatchCount() {
cacheMatchLogger.incMatchCount();
}
public int getCacheInMinute() {
return cacheInMinute;
}
}
package com.yoho.search.cache.model;
import com.yoho.search.cache.impls.CacheInterface;
public class SearchCache {
private static final int logPeriodInMinute = 1;// 默认每分钟打印一次日志
private CacheInterface cacheInterface;// 缓存类型
private int cacheInMinute = 5;// 缓存时间
private CacheMatchLogger cacheMatchLogger;
public SearchCache(String cacheName, CacheInterface cacheInterface, int cacheInMinute) {
super();
this.cacheInMinute = cacheInMinute;
this.cacheInterface = cacheInterface;
this.cacheMatchLogger = new CacheMatchLogger();
cacheMatchLogger.init(cacheName, cacheInMinute, logPeriodInMinute);
}
public CacheInterface getCache() {
return cacheInterface;
}
public void incTotalCount() {
cacheMatchLogger.incTotalCount();
}
public void incMatchCount() {
cacheMatchLogger.incMatchCount();
}
public int getCacheInMinute() {
return cacheInMinute;
}
}
... ...
... ... @@ -4,7 +4,7 @@ import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.core.personalized.PersonalizedSearch;
import com.yoho.search.core.personalized.models.SortPriceAreas;
import com.yoho.search.recall.beans.persional.ProductFeatureFactorHepler;
import com.yoho.search.recall.beans.persional.ProductFeatureFactorComponent;
import com.yoho.search.recall.config.RecallConfigConstants;
import com.yoho.search.recall.config.RecallConfigService;
import com.yoho.search.recall.models.personal.UserFeatureFactor;
... ... @@ -34,7 +34,7 @@ public class UserRecallResponseBuilder {
@Autowired
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
@Autowired
private ProductFeatureFactorHepler productFeatureFactorHepler;
private ProductFeatureFactorComponent productFeatureFactorComponent;
@Autowired
private SknBaseInfoCacheBean sknBaseInfoCacheBean;
@Autowired
... ... @@ -200,7 +200,7 @@ public class UserRecallResponseBuilder {
continue;
}
//3)向量计算-如果为1,则使用百分之1的人气替代
score = productFeatureFactorHepler.calProductFeatureFactor(userFeatureFactor, sknResult.getFactor());
score = productFeatureFactorComponent.calProductFeatureFactor(userFeatureFactor, sknResult.getFactor());
if (score == 0) {
score = sknResult.getHeatValue() / 100;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.beans.AbstractCacheBean;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.models.req.RecallRequestResponse;
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.beans.AbstractCacheBean;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.models.req.*;
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.beans.AbstractCacheBean;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.models.req.SknCodeRequest;
... ...
... ... @@ -3,13 +3,11 @@ package com.yoho.search.recall.beans.cache;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.beans.ZkConfigManager;
import com.yoho.search.base.constants.ZkConfigConstants;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.common.cache.impls.CacheInterface;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.cache.impls.CacheInterface;
import com.yoho.search.cache.impls.SearchRedis;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
... ...
... ... @@ -3,6 +3,7 @@ package com.yoho.search.recall.beans.cache;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.beans.AbstractCacheBean;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.models.req.SknReturnInfoResqusetResponse;
... ...
package com.yoho.search.recall.beans.cache;
import com.yoho.search.cache.beans.AbstractCacheBean;
import com.yoho.search.recall.beans.builder.CommonRecallRequestBuilder;
import com.yoho.search.recall.beans.builder.RecallMergerResultBuilder;
import com.yoho.search.recall.beans.builder.SortBrandRecallRequestBuilder;
... ...
... ... @@ -3,11 +3,12 @@ package com.yoho.search.recall.beans.persional;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.beans.AbstractPageComponent;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
import com.yoho.search.service.base.SearchCommonService;
... ...
... ... @@ -5,7 +5,7 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import com.yoho.search.recall.models.personal.PageSknCodeBitSet;
import com.yoho.search.service.base.SearchCommonService;
... ...
... ... @@ -12,9 +12,9 @@ import java.util.ArrayList;
import java.util.List;
@Component
public class ProductFeatureFactorHepler {
public class ProductFeatureFactorComponent {
private static final Logger logger = LoggerFactory.getLogger(ProductFeatureFactorHepler.class);
private static final Logger logger = LoggerFactory.getLogger(ProductFeatureFactorComponent.class);
private static double baseConstant = 1;
private static double factorConstant = 1;
... ... @@ -61,7 +61,7 @@ public class ProductFeatureFactorHepler {
PersonalizedSearch personalizedSearch = new PersonalizedSearch("1", "20180408", "0.342045,-0.547933,0.291732,-0.056515,-0.182701,0.31113,0.151578,0.087678,-0.045536,-0.525699,-0.394715,-0.103153,-0.05575,-0.540641,0.028046,-0.193109,-0.003591,0.180923,0.290261,0.532309,-0.202463,-0.047271,-0.246197,0.324561,0.188814,0.36475,0.079007,0.455753,-0.11848,-0.135874,-0.187155,-0.055342,-0.12525,0.210669,-0.388331,-0.197123,0.132309,-0.4231,0.217752,-0.203266,0.190836,0.373428,-0.0102,-0.038654,0.2379,0.044424,0.071826,-0.201054,0.257434,0.141901,-0.390064,0.437099,0.559701,-0.040162,-0.193089,0.442338,-0.141678,-0.049696,0.315545,-0.028972,0.278694,-0.064345,-0.327943,0.103025,-0.40344,-0.34269,-0.237931,0.287046,0.139693,-0.38454,0.019959,-0.156907,0.374996,-0.074558,-0.019391,0.050522,0.315171,0.211605,-0.15418,0.502362,0.10184,0.153274,0.592659,-0.010284,0.28029,0.319741,-0.164559,0.286884,0.420483,-0.628866,-0.172259,0.027954,-0.411674,0.376585,0.322832,0.352039,0.078705,0.045152,0.139083,-0.164182");
UserFeatureFactor userFeatureFactor = new UserFeatureFactor(personalizedSearch);
String productFeatureFactor = "20180408|0.342045,-0.547933,0.291732,-0.056515,-0.182701,0.31113,0.151578,0.087678,-0.045536,-0.525699,-0.394715,-0.103153,-0.05575,-0.540641,0.028046,-0.193109,-0.003591,0.180923,0.290261,0.532309,-0.202463,-0.047271,-0.246197,0.324561,0.188814,0.36475,0.079007,0.455753,-0.11848,-0.135874,-0.187155,-0.055342,-0.12525,0.210669,-0.388331,-0.197123,0.132309,-0.4231,0.217752,-0.203266,0.190836,0.373428,-0.0102,-0.038654,0.2379,0.044424,0.071826,-0.201054,0.257434,0.141901,-0.390064,0.437099,0.559701,-0.040162,-0.193089,0.442338,-0.141678,-0.049696,0.315545,-0.028972,0.278694,-0.064345,-0.327943,0.103025,-0.40344,-0.34269,-0.237931,0.287046,0.139693,-0.38454,0.019959,-0.156907,0.374996,-0.074558,-0.019391,0.050522,0.315171,0.211605,-0.15418,0.502362,0.10184,0.153274,0.592659,-0.010284,0.28029,0.319741,-0.164559,0.286884,0.420483,-0.628866,-0.172259,0.027954,-0.411674,0.376585,0.322832,0.352039,0.078705,0.045152,0.139083,-0.164182";
System.out.println(new ProductFeatureFactorHepler().calProductFeatureFactor(userFeatureFactor,productFeatureFactor));
System.out.println(new ProductFeatureFactorComponent().calProductFeatureFactor(userFeatureFactor,productFeatureFactor));
}
}
... ...
package com.yoho.search.recall.beans.strategy.impls;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.search.recall.beans.strategy.impls;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
... ...
package com.yoho.search.recall.beans.strategy.impls;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
... ...
package com.yoho.search.recall.beans.strategy.impls;
import com.alibaba.fastjson.JSON;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.search.recall.beans.strategy.impls;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
... ...
package com.yoho.search.recall.beans.strategy.impls;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
... ...
... ... @@ -4,7 +4,7 @@ import com.yoho.search.recall.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
... ...
... ... @@ -5,7 +5,7 @@ import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
public abstract class SortBrandAbstractStrategy implements IStrategy {
... ...
... ... @@ -5,7 +5,7 @@ import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.model.ICacheRequest;
import com.yoho.search.recall.models.common.IRecallRequest;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import org.elasticsearch.index.query.BoolQueryBuilder;
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.search.recall.models.req;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
public class RecallRequestResponse extends AbstractCacheRequestResponse<RecallRequest,RecallResponse> {
... ...
... ... @@ -2,8 +2,8 @@ package com.yoho.search.recall.models.req;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.model.ICacheRequest;
import java.util.Arrays;
import java.util.List;
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.search.recall.models.req;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
public class SknBaseInfoRequestResponse extends AbstractCacheRequestResponse<SknBaseInfoRequest, SknBaseInfoResponse> {
... ...
... ... @@ -2,8 +2,8 @@ package com.yoho.search.recall.models.req;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.model.ICacheRequest;
import java.util.Arrays;
import java.util.List;
... ...
package com.yoho.search.recall.models.req;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
public class SknCodeRequestResponse extends AbstractCacheRequestResponse<SknCodeRequest, Integer> {
... ...
package com.yoho.search.recall.models.req;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.model.ICacheRequest;
public class SknReturnInfoResquest implements ICacheRequest {
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.search.recall.models.req;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
import java.util.HashMap;
import java.util.Map;
... ...
... ... @@ -3,9 +3,9 @@ package com.yoho.search.recall.models.req;
import com.alibaba.fastjson.JSON;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import com.yoho.search.recall.models.common.ICacheRequest;
import com.yoho.search.cache.model.ICacheRequest;
import org.apache.commons.lang.StringUtils;
import java.util.List;
... ...
... ... @@ -2,7 +2,7 @@ package com.yoho.search.recall.models.req;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.models.common.AbstractCacheRequestResponse;
import com.yoho.search.cache.model.AbstractCacheRequestResponse;
public class UserRecallRequestResponse extends AbstractCacheRequestResponse<UserRecallRequest,UserRecallResponse> {
... ...
... ... @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IBrandService;
... ...
package com.yoho.search.restapi;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.list.ProductListSwitchService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IAggRecommendService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IDiscountService;
... ...
... ... @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IBrandWithShopsService;
... ...
package com.yoho.search.restapi.miniapp;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.miniapp.MiniappFuzzySceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IHelperService;
... ...
package com.yoho.search.restapi.others;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IImageRepertoryService;
... ...
package com.yoho.search.restapi.others;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.IRobotQuestionService;
... ...
... ... @@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.service.TblProductService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.AggProductListService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.BrandSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.BreakSizeSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.CommonSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.CouponSceneService;
... ...
package com.yoho.search.restapi.scene;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.FreeShippingOrderSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.FuzzySceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.NewGoodProductSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.NewArrivalSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ProductPoolSceneService;
... ...
... ... @@ -3,7 +3,7 @@ package com.yoho.search.restapi.scene;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.PromotionConditions;
import com.yoho.search.models.SearchApiResult;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ReducePriceSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ShopSceneService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.SortSceneService;
... ...
... ... @@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.WebProductListService;
... ...
... ... @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.search.common.downgrade.persional.PersionalRateLimit;
import com.yoho.search.aop.downgrade.PersionalRateLimit;
import com.yoho.search.common.utils.HttpServletRequestUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.ZqSceneService;
... ...
... ... @@ -14,8 +14,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.model.CacheObject;
import com.yoho.search.cache.impls.EhCache;
import com.yoho.search.cache.model.CacheObject;
import com.yoho.search.service.list.ProductListSwitchService;
@Controller
... ...
package com.yoho.search.restapi.tools;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.cache.impls.SearchRedis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
... ...
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.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;
... ...
... ... @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.ProductListWithSkn;
import com.yoho.search.aop.productlist.ProductListWithSkn;
import com.yoho.search.recall.beans.strategy.NotRecallTypeEnum;
import com.yoho.search.service.base.ProductListSortService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
... ...
package com.yoho.search.recall.beans.helper;
package com.yoho.search.service.helper;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
... ...
... ... @@ -15,7 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ...
package com.yoho.search.service.list;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.productlist.aop.ProductListWithSknRetention;
import com.yoho.search.cache.CacheType;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.aop.productlist.ProductListWithSknRetention;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.ProductListWithSkn;
import com.yoho.search.aop.productlist.ProductListWithSkn;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.beans.strategy.NotRecallTypeEnum;
import com.yoho.search.service.base.SearchCommonService;
... ...
... ... @@ -2,12 +2,12 @@ package com.yoho.search.service.list;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.cache.CacheType;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.productlist.aop.ProductListWithSknRetention;
import com.yoho.search.cache.CacheType;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.aop.productlist.ProductListWithSknRetention;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.ProductListWithSkn;
import com.yoho.search.aop.productlist.ProductListWithSkn;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.beans.strategy.NotRecallTypeEnum;
import com.yoho.search.service.base.SearchCommonService;
... ...
... ... @@ -6,7 +6,7 @@ import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.core.es.utils.IgnoreSomeException;
... ...
... ... @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.agg.IAggregation;
import com.yoho.search.core.es.model.SearchParam;
... ...
... ... @@ -4,13 +4,13 @@ import com.google.common.base.Splitter;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.recall.beans.cache.SknImgsCacheBean;
import com.yoho.search.recall.models.req.SknImgsResponse;
import com.yoho.search.service.scene.img.SknImgsResponse;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.list.ProductListSwitchService;
import com.yoho.search.service.scene.common.AbstractSceneService;
import com.yoho.search.service.scene.common.SceneRecommendBrandsService;
import com.yoho.search.service.scene.common.SceneSelectionsService;
import com.yoho.search.service.scene.img.SknImgsCacheBean;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ...
... ... @@ -18,7 +18,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ...
... ... @@ -30,8 +30,8 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.common.cache.aop.SearchCacheAble;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.aop.cache.SearchCacheAble;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
... ... @@ -39,7 +39,7 @@ import com.yoho.search.models.YohoFilterFunctionBuilders;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchServiceHelper;
import com.yoho.search.service.scene.common.AbstractCacheAbleService;
import com.yoho.search.cache.beans.AbstractCacheAbleService;
import com.yoho.search.service.scorer.IScorer;
import com.yoho.search.service.scorer.impl.FirstProductSknScorer;
import com.yoho.search.service.scorer.impl.RandomScorer;
... ...
... ... @@ -2,26 +2,7 @@ package com.yoho.search.service.scene;
import java.util.*;
import com.alibaba.fastjson.JSONArray;
import com.yoho.error.event.SearchEvent;
import com.yoho.search.base.utils.EventReportEnum;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.common.cache.SearchCacheMatchLogger;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.models.SearchSort;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -29,7 +10,7 @@ import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.common.cache.model.SearchCache;
import com.yoho.search.cache.model.SearchCache;
import com.yoho.search.common.utils.SearchApiResultUtils;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
... ... @@ -43,7 +24,7 @@ import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchKeyWordHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.helper.SearchSortHelper;
import com.yoho.search.service.scene.common.AbstractCacheAbleService;
import com.yoho.search.cache.beans.AbstractCacheAbleService;
import com.yoho.search.service.service.ISearchRecommendService;
import com.yoho.search.service.service.impl.ProductListServiceImpl;
... ...
... ... @@ -6,8 +6,8 @@ import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.beans.builder.UserRecallRequestBuilder;
import com.yoho.search.recall.beans.persional.AbstractPageComponent;
import com.yoho.search.recall.config.CacheTimeConstants;
import com.yoho.search.cache.beans.AbstractPageComponent;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.helper.AggCommonHelper;
... ...