Authored by hugufei

添加按推荐出来的productId实时召回的逻辑

package com.yoho.search.recall.scene.beans.cache;
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.scene.beans.helper.RecallResponseHelper;
import com.yoho.search.recall.scene.beans.strategy.impls.RecommendProductStrategy;
import com.yoho.search.recall.scene.models.common.IRecallRequest;
import com.yoho.search.recall.scene.models.req.*;
import com.yoho.search.service.base.SearchCommonService;
import org.apache.commons.collections.MapUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class RecommendProductRecallCacheBean extends AbstractCacheBean<RecommendProductRequest, RecallResponse, RecommendProductRequestResponse> {
@Autowired
private SearchCommonService searchCommonService;
/**
* 按productId召回的入口
* @param productIds
* @return
*/
public List<RecallRequestResponse> batchRecallAndCache(List<Integer> productIds) {
//1、参数判断
if(productIds==null || productIds.isEmpty()){
return new ArrayList<>();
}
//2、执行查询
List<RecommendProductRequestResponse> responses = this.batchQuery(productIds);
//3、数据转换
List<RecallRequestResponse> results = new ArrayList<>();
for (RecommendProductRequestResponse recommendProductRequestResponse: responses){
RecommendProductRequest request = recommendProductRequestResponse.getRequest();
RecallResponse response = recommendProductRequestResponse.getResponse();
if(request==null || response==null){
continue;
}
Integer productId = request.getProductId();
RecallRequest recallRequest = new RecallRequest(new RecommendProductStrategy(productId));
results.add(new RecallRequestResponse(recallRequest,response));
}
return results;
}
private List<RecommendProductRequestResponse> batchQuery(List<Integer> productIds){
//1、构造结果
final List<RecommendProductRequestResponse> results = new ArrayList<>();
for (Integer productId : productIds) {
results.add(new RecommendProductRequestResponse(new RecommendProductRequest(productId)));
}
//2、调父类方法
super.bacthFillResponseWithCache(results,productIds.size());
//3、返回结果
return results;
}
public void batchAddProductRecallInfoToCache(Map<Integer,RecallResponse> productVectors){
List<RecommendProductRequestResponse> results = new ArrayList<>();
for (Map.Entry<Integer,RecallResponse> entry: productVectors.entrySet()) {
RecommendProductRequestResponse result = new RecommendProductRequestResponse(new RecommendProductRequest(entry.getKey()));
result.setResponse(entry.getValue(),true);
results.add(result);
}
super.batchAddResponseToCache(results);
}
@Override
protected boolean useEhCache() {
return false;
}
@Override
protected Map<RecommendProductRequest, RecallResponse> queryMissCacheRequestResults(List<RecommendProductRequestResponse> missCacheRequests) {
//1、合法性判断
Map<RecommendProductRequest,RecallResponse> results = new HashMap<>();
if(missCacheRequests==null||missCacheRequests.isEmpty()){
return results;
}
//2、获取productId
List<Integer> productIds = new ArrayList<>();
for (RecommendProductRequestResponse recommendProductRequestResponse : missCacheRequests) {
productIds.add(recommendProductRequestResponse.getRequest().getProductId());
}
//3、构建SearchParam并查询
SearchParam searchParam = new SearchParam();
searchParam.setOffset(0);
searchParam.setSize(productIds.size());
searchParam.setFiter(QueryBuilders.termsQuery(ProductIndexEsField.productId, productIds));
searchParam.setIncludeFields( missCacheRequests.get(0).getRequest().includeFields());
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
//4、构建基于ProductId的临时结果
Map<Integer,RecallResponse> productTempMap = new HashMap<>();
for (Map<String, Object> productInfo: searchResult.getResultList()){
Integer productId = MapUtils.getIntValue(productInfo,ProductIndexEsField.productId,0);
RecallResponse.RecallSkn recallSkn = RecallResponseHelper.buildRecallSkn(productInfo);
RecallResponse recallResponse = RecallResponseHelper.buildRecallResponse(recallSkn);
productTempMap.put(productId,recallResponse);
}
//5、构造最终结果
for (RecommendProductRequestResponse recommendProductRequestResponse :missCacheRequests ) {
results.put(recommendProductRequestResponse.getRequest(),productTempMap.get(recommendProductRequestResponse.getRequest().getProductId()));
}
return results;
}
}
package com.yoho.search.recall.scene.beans.cache;
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.scene.beans.helper.RecallResponseHelper;
import com.yoho.search.recall.scene.beans.strategy.impls.RecommendProductStrategy;
import com.yoho.search.recall.scene.models.common.IRecallRequest;
import com.yoho.search.recall.scene.models.req.*;
import com.yoho.search.service.base.SearchCommonService;
import org.apache.commons.collections.MapUtils;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class RecommendProductRecallCacheBean extends AbstractCacheBean<RecommendProductRequest, RecallResponse, RecommendProductRequestResponse> {
@Autowired
private SearchCommonService searchCommonService;
/**
* 按productId召回的入口
* @param productIds
* @return
*/
public List<RecallRequestResponse> batchRecallAndCache(List<Integer> productIds) {
//1、参数判断
if(productIds==null || productIds.isEmpty()){
return new ArrayList<>();
}
//2、执行查询
List<RecommendProductRequestResponse> responses = this.batchQuery(productIds);
//3、数据转换
List<RecallRequestResponse> results = new ArrayList<>();
for (RecommendProductRequestResponse recommendProductRequestResponse: responses){
RecommendProductRequest request = recommendProductRequestResponse.getRequest();
RecallResponse response = recommendProductRequestResponse.getResponse();
if(request==null || response==null){
continue;
}
Integer productId = request.getProductId();
RecallRequest recallRequest = new RecallRequest(new RecommendProductStrategy(productId));
results.add(new RecallRequestResponse(recallRequest,response));
}
return results;
}
private List<RecommendProductRequestResponse> batchQuery(List<Integer> productIds){
//1、构造结果
final List<RecommendProductRequestResponse> results = new ArrayList<>();
for (Integer productId : productIds) {
results.add(new RecommendProductRequestResponse(new RecommendProductRequest(productId)));
}
//2、调父类方法
super.bacthFillResponseWithCache(results,productIds.size());
//3、返回结果
return results;
}
public void batchAddProductRecallInfoToCache(Map<Integer,RecallResponse> productVectors){
List<RecommendProductRequestResponse> results = new ArrayList<>();
for (Map.Entry<Integer,RecallResponse> entry: productVectors.entrySet()) {
RecommendProductRequestResponse result = new RecommendProductRequestResponse(new RecommendProductRequest(entry.getKey()));
result.setResponse(entry.getValue(),true);
results.add(result);
}
super.batchAddResponseToCache(results);
}
@Override
protected boolean useEhCache() {
return false;
}
@Override
protected Map<RecommendProductRequest, RecallResponse> queryMissCacheRequestResults(List<RecommendProductRequestResponse> missCacheRequests) {
//1、合法性判断
Map<RecommendProductRequest,RecallResponse> results = new HashMap<>();
if(missCacheRequests==null||missCacheRequests.isEmpty()){
return results;
}
//2、获取productId
List<Integer> productIds = new ArrayList<>();
for (RecommendProductRequestResponse recommendProductRequestResponse : missCacheRequests) {
productIds.add(recommendProductRequestResponse.getRequest().getProductId());
}
//3、构建SearchParam并查询
SearchParam searchParam = new SearchParam();
searchParam.setOffset(0);
searchParam.setSize(productIds.size());
searchParam.setFiter(QueryBuilders.termsQuery(ProductIndexEsField.productId, productIds));
searchParam.setIncludeFields( missCacheRequests.get(0).getRequest().includeFields());
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
//4、构建基于ProductId的临时结果
Map<Integer,RecallResponse> productTempMap = new HashMap<>();
for (Map<String, Object> productInfo: searchResult.getResultList()){
Integer productId = MapUtils.getIntValue(productInfo,ProductIndexEsField.productId,0);
RecallResponse.RecallSkn recallSkn = RecallResponseHelper.buildRecallSkn(productInfo);
RecallResponse recallResponse = RecallResponseHelper.buildRecallResponse(recallSkn);
productTempMap.put(productId,recallResponse);
}
//5、构造最终结果
for (RecommendProductRequestResponse recommendProductRequestResponse :missCacheRequests ) {
results.put(recommendProductRequestResponse.getRequest(),productTempMap.get(recommendProductRequestResponse.getRequest().getProductId()));
}
return results;
}
}
... ...
package com.yoho.search.recall.scene.beans.helper;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.recall.scene.models.req.RecallResponse;
import org.apache.commons.collections.MapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class RecallResponseHelper {
public static RecallResponse.RecallSkn buildRecallSkn(Map<String, Object> productInfo) {
Integer productSkn = MapUtils.getInteger(productInfo, ProductIndexEsField.productSkn, 0);
Integer brandId = MapUtils.getInteger(productInfo, ProductIndexEsField.brandId, 0);
Integer middleSortId = MapUtils.getInteger(productInfo, ProductIndexEsField.middleSortId, 0);
Integer priceArea = MapUtils.getInteger(productInfo, ProductIndexEsField.priceArea, 0);
return new RecallResponse.RecallSkn(productSkn, brandId, middleSortId,priceArea);
}
public static RecallResponse buildRecallResponse(RecallResponse.RecallSkn recallSkn) {
List<RecallResponse.RecallSkn> recallSknList = new ArrayList<>();
recallSknList.add(recallSkn);
return new RecallResponse(1, recallSknList);
}
public static RecallResponse buildRecallResponse(List<RecallResponse.RecallSkn> recallSknList,long total) {
return new RecallResponse(total, recallSknList);
}
}
package com.yoho.search.recall.scene.beans.helper;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.recall.scene.models.req.RecallResponse;
import org.apache.commons.collections.MapUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class RecallResponseHelper {
public static RecallResponse.RecallSkn buildRecallSkn(Map<String, Object> productInfo) {
Integer productSkn = MapUtils.getInteger(productInfo, ProductIndexEsField.productSkn, 0);
Integer brandId = MapUtils.getInteger(productInfo, ProductIndexEsField.brandId, 0);
Integer middleSortId = MapUtils.getInteger(productInfo, ProductIndexEsField.middleSortId, 0);
Integer priceArea = MapUtils.getInteger(productInfo, ProductIndexEsField.priceArea, 0);
return new RecallResponse.RecallSkn(productSkn, brandId, middleSortId,priceArea);
}
public static RecallResponse buildRecallResponse(RecallResponse.RecallSkn recallSkn) {
List<RecallResponse.RecallSkn> recallSknList = new ArrayList<>();
recallSknList.add(recallSkn);
return new RecallResponse(1, recallSknList);
}
public static RecallResponse buildRecallResponse(List<RecallResponse.RecallSkn> recallSknList,long total) {
return new RecallResponse(total, recallSknList);
}
}
... ...
package com.yoho.search.recall.scene.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.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
import com.yoho.search.recall.scene.models.personal.PageProductIdBitSet;
import com.yoho.search.service.base.SearchCommonService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Component
public class PageProductIdBitSetComponent extends AbstractPageComponent {
@Autowired
private SearchCommonService searchCommonService;
/**
* 获取页面上的skn的bitset
*
* @param paramQueryFilter
* @return
*/
public PageProductIdBitSet queryPageProductIdBitSet(ParamQueryFilter paramQueryFilter) {
Object value = super.queryWithCache(paramQueryFilter);
return value==null?null:(PageProductIdBitSet)value;
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:PAGE_PRODUCT_BITSET:").appendVar(paramQueryFilter.getParamMd5Key());
}
@Override
protected int cacheTimeInSecond() {
return CacheTimeConstants.PAGE_SKN_BITSET;
}
@Override
protected Object doRealQuery(ParamQueryFilter paramQueryFilter) {
//1、构造请求参数
SearchParam searchParam = new SearchParam();
searchParam.setQuery(paramQueryFilter.getParamQuery());
searchParam.setFiter(paramQueryFilter.getParamFilter());
searchParam.setSize(0);
//2、构造聚合参数
List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<>();
aggregationBuilders.add(AggregationBuilders.terms("productIdAgg").field(ProductIndexEsField.productId).size(10000).order(Terms.Order.term(false)));//品类-品牌聚合
searchParam.setAggregationBuilders(aggregationBuilders);
//3、执行查询
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
//4、构造结果
Map<String, Aggregation> aggregationMap = searchResult.getAggMaps();
PageProductIdBitSet pageProductIdBitSet = this.getPageSknBitSetFromAggregationMap(aggregationMap,"productIdAgg");
return pageProductIdBitSet;
}
private PageProductIdBitSet getPageSknBitSetFromAggregationMap(Map<String, Aggregation> aggregationMap, String firstAggName){
if(!aggregationMap.containsKey(firstAggName)){
return null;
}
List<Integer> productIdList = new ArrayList<Integer>();
MultiBucketsAggregation firstAggregation = (MultiBucketsAggregation) aggregationMap.get(firstAggName);
Iterator<? extends MultiBucketsAggregation.Bucket> firstAggregationIterator = firstAggregation.getBuckets().iterator();
while (firstAggregationIterator.hasNext()) {
MultiBucketsAggregation.Bucket bucket = firstAggregationIterator.next();
Integer value = Integer.valueOf(bucket.getKeyAsString());
productIdList.add(value);
}
PageProductIdBitSet pageProductIdBitSet = new PageProductIdBitSet();
for (Integer productId: productIdList) {
pageProductIdBitSet.add(productId);
}
return pageProductIdBitSet;
}
}
package com.yoho.search.recall.scene.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.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
import com.yoho.search.recall.scene.models.personal.PageProductIdBitSet;
import com.yoho.search.service.base.SearchCommonService;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Component
public class PageProductIdBitSetComponent extends AbstractPageComponent {
@Autowired
private SearchCommonService searchCommonService;
/**
* 获取页面上的skn的bitset
*
* @param paramQueryFilter
* @return
*/
public PageProductIdBitSet queryPageProductIdBitSet(ParamQueryFilter paramQueryFilter) {
Object value = super.queryWithCache(paramQueryFilter);
return value==null?null:(PageProductIdBitSet)value;
}
@Override
protected RedisKeyBuilder genRedisKeyBuilder(ParamQueryFilter paramQueryFilter) {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:PAGE_PRODUCT_BITSET:").appendVar(paramQueryFilter.getParamMd5Key());
}
@Override
protected int cacheTimeInSecond() {
return CacheTimeConstants.PAGE_SKN_BITSET;
}
@Override
protected Object doRealQuery(ParamQueryFilter paramQueryFilter) {
//1、构造请求参数
SearchParam searchParam = new SearchParam();
searchParam.setQuery(paramQueryFilter.getParamQuery());
searchParam.setFiter(paramQueryFilter.getParamFilter());
searchParam.setSize(0);
//2、构造聚合参数
List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<>();
aggregationBuilders.add(AggregationBuilders.terms("productIdAgg").field(ProductIndexEsField.productId).size(10000).order(Terms.Order.term(false)));//品类-品牌聚合
searchParam.setAggregationBuilders(aggregationBuilders);
//3、执行查询
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
//4、构造结果
Map<String, Aggregation> aggregationMap = searchResult.getAggMaps();
PageProductIdBitSet pageProductIdBitSet = this.getPageSknBitSetFromAggregationMap(aggregationMap,"productIdAgg");
return pageProductIdBitSet;
}
private PageProductIdBitSet getPageSknBitSetFromAggregationMap(Map<String, Aggregation> aggregationMap, String firstAggName){
if(!aggregationMap.containsKey(firstAggName)){
return null;
}
List<Integer> productIdList = new ArrayList<Integer>();
MultiBucketsAggregation firstAggregation = (MultiBucketsAggregation) aggregationMap.get(firstAggName);
Iterator<? extends MultiBucketsAggregation.Bucket> firstAggregationIterator = firstAggregation.getBuckets().iterator();
while (firstAggregationIterator.hasNext()) {
MultiBucketsAggregation.Bucket bucket = firstAggregationIterator.next();
Integer value = Integer.valueOf(bucket.getKeyAsString());
productIdList.add(value);
}
PageProductIdBitSet pageProductIdBitSet = new PageProductIdBitSet();
for (Integer productId: productIdList) {
pageProductIdBitSet.add(productId);
}
return pageProductIdBitSet;
}
}
... ...
package com.yoho.search.recall.scene.beans.strategy.impls;
import com.yoho.search.recall.scene.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.scene.beans.strategy.IStrategy;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
/**
* 按productId的召回策略
*
* @author gufei.hu
*
*/
public class RecommendProductStrategy implements IStrategy {
private Integer productId;
public RecommendProductStrategy(Integer productId) {
this.productId = productId;
}
@Override
public StrategyEnum strategtEnum() {
return StrategyEnum.RECOMMEND_PRODUCT;
}
@Override
public QueryBuilder extendFilter() {
return ExtendFilterHelper.productIdFilter(this.productId);
}
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getIdDescSort();
}
@Override
public int size() {
return 1;
}
@Override
public int cacheTimeInSecond() {
return CacheTimeConstants.PRODUCTID_TO_RECALL_RESPONSE;
}
@Override
public String strategyCacheKey() {
StringBuilder sb = defaultStrategyKey();
sb.append(this.productId==null?"0":productId.toString());
return sb.toString();
}
}
package com.yoho.search.recall.scene.beans.strategy.impls;
import com.yoho.search.recall.scene.beans.helper.ExtendFilterHelper;
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
import com.yoho.search.recall.scene.beans.strategy.IStrategy;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.sort.SortBuilder;
/**
* 按productId的召回策略
*
* @author gufei.hu
*
*/
public class RecommendProductStrategy implements IStrategy {
private Integer productId;
public RecommendProductStrategy(Integer productId) {
this.productId = productId;
}
@Override
public StrategyEnum strategtEnum() {
return StrategyEnum.RECOMMEND_PRODUCT;
}
@Override
public QueryBuilder extendFilter() {
return ExtendFilterHelper.productIdFilter(this.productId);
}
@Override
public SortBuilder<?> sortBuilder() {
return SortBuilderHelper.getIdDescSort();
}
@Override
public int size() {
return 1;
}
@Override
public int cacheTimeInSecond() {
return CacheTimeConstants.PRODUCTID_TO_RECALL_RESPONSE;
}
@Override
public String strategyCacheKey() {
StringBuilder sb = defaultStrategyKey();
sb.append(this.productId==null?"0":productId.toString());
return sb.toString();
}
}
... ...
package com.yoho.search.recall.scene.models.personal;
import java.io.Serializable;
import java.util.BitSet;
public class PageProductIdBitSet implements Serializable{
public static final int maxValue = 2000000;
private static final long serialVersionUID = 7185024266096124078L;
private BitSet sknBitSet;
public PageProductIdBitSet(){
this.sknBitSet = new BitSet(maxValue);
}
public void add(int bitSetIndex) {
if(bitSetIndex>maxValue){
return;
}
this.sknBitSet.set(bitSetIndex);
}
public boolean exist(int bitSetIndex) {
return sknBitSet.get(bitSetIndex);
}
}
package com.yoho.search.recall.scene.models.personal;
import java.io.Serializable;
import java.util.BitSet;
public class PageProductIdBitSet implements Serializable{
public static final int maxValue = 2000000;
private static final long serialVersionUID = 7185024266096124078L;
private BitSet sknBitSet;
public PageProductIdBitSet(){
this.sknBitSet = new BitSet(maxValue);
}
public void add(int bitSetIndex) {
if(bitSetIndex>maxValue){
return;
}
this.sknBitSet.set(bitSetIndex);
}
public boolean exist(int bitSetIndex) {
return sknBitSet.get(bitSetIndex);
}
}
... ...
package com.yoho.search.recall.scene.models.req;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import com.yoho.search.recall.scene.models.common.ICacheRequest;
import com.yoho.search.recall.scene.models.common.IRecallRequest;
import java.util.Arrays;
import java.util.List;
public class RecommendProductRequest implements ICacheRequest,IRecallRequest {
private Integer productId;
public RecommendProductRequest(Integer productId){
this.productId = productId;
}
@Override
public RedisKeyBuilder redisKeyBuilder() {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("RECOMMEND_PRODUCT:").appendVar(cacheTimeInSecond()).appendFixed(":").appendVar(productId);
}
@Override
public int cacheTimeInSecond() {
return CacheTimeConstants.PRODUCTID_TO_RECALL_RESPONSE;
}
public Integer getProductId() {
return productId;
}
@Override
public StrategyEnum requestStrategy() {
return StrategyEnum.RECOMMEND_PRODUCT;
}
@Override
public SearchParam searchParam() {
return null;
}
/**
* 请求返回的字段
* @return
*/
public List<String> includeFields(){
return Arrays.asList(ProductIndexEsField.productId,ProductIndexEsField.productSkn,ProductIndexEsField.brandId,ProductIndexEsField.middleSortId,ProductIndexEsField.productFeatureFactor,ProductIndexEsField.priceArea);
}
}
package com.yoho.search.recall.scene.models.req;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.recall.scene.beans.strategy.StrategyEnum;
import com.yoho.search.recall.scene.constants.CacheTimeConstants;
import com.yoho.search.recall.scene.models.common.ICacheRequest;
import com.yoho.search.recall.scene.models.common.IRecallRequest;
import java.util.Arrays;
import java.util.List;
public class RecommendProductRequest implements ICacheRequest,IRecallRequest {
private Integer productId;
public RecommendProductRequest(Integer productId){
this.productId = productId;
}
@Override
public RedisKeyBuilder redisKeyBuilder() {
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("RECOMMEND_PRODUCT:").appendVar(cacheTimeInSecond()).appendFixed(":").appendVar(productId);
}
@Override
public int cacheTimeInSecond() {
return CacheTimeConstants.PRODUCTID_TO_RECALL_RESPONSE;
}
public Integer getProductId() {
return productId;
}
@Override
public StrategyEnum requestStrategy() {
return StrategyEnum.RECOMMEND_PRODUCT;
}
@Override
public SearchParam searchParam() {
return null;
}
/**
* 请求返回的字段
* @return
*/
public List<String> includeFields(){
return Arrays.asList(ProductIndexEsField.productId,ProductIndexEsField.productSkn,ProductIndexEsField.brandId,ProductIndexEsField.middleSortId,ProductIndexEsField.productFeatureFactor,ProductIndexEsField.priceArea);
}
}
... ...
package com.yoho.search.recall.scene.models.req;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.scene.models.common.AbstractCacheRequestResponse;
public class RecommendProductRequestResponse extends AbstractCacheRequestResponse<RecommendProductRequest, RecallResponse> {
public RecommendProductRequestResponse(RecommendProductRequest request) {
super(request);
}
@Override
public Transfer<String, RecallResponse> getToResponseTransfer() {
return RecallRequestResponse.toResponseTransfer;
}
@Override
public Transfer<RecallResponse, String> getFromResponseTransfer() {
return RecallRequestResponse.fromResponseTransfer;
}
}
package com.yoho.search.recall.scene.models.req;
import com.yoho.search.base.utils.Transfer;
import com.yoho.search.recall.scene.models.common.AbstractCacheRequestResponse;
public class RecommendProductRequestResponse extends AbstractCacheRequestResponse<RecommendProductRequest, RecallResponse> {
public RecommendProductRequestResponse(RecommendProductRequest request) {
super(request);
}
@Override
public Transfer<String, RecallResponse> getToResponseTransfer() {
return RecallRequestResponse.toResponseTransfer;
}
@Override
public Transfer<RecallResponse, String> getFromResponseTransfer() {
return RecallRequestResponse.fromResponseTransfer;
}
}
... ...