...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.search.recall.scene.models; |
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.search.base.utils.MD5Util;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.recall.scene.strategy.IStrategy;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
...
|
...
|
@@ -18,37 +19,26 @@ import java.util.List; |
|
|
public class RecallRequest implements IRecallRequest {
|
|
|
|
|
|
private ParamQueryFilter paramQueryFilter;
|
|
|
private QueryBuilder extendFilter;
|
|
|
private List<SortBuilder<?>> sortBuilders;
|
|
|
private Integer size;
|
|
|
private String requestType;
|
|
|
private IStrategy strategy;
|
|
|
private RedisKeyBuilder redisKeyBuilder;
|
|
|
private int cacheTimeInSecond;
|
|
|
|
|
|
public RecallRequest(ParamQueryFilter paramQueryFilter, QueryBuilder extendFilter, SortBuilder<?> sortBuilder, Integer size, String requestType, int cacheTimeInSecond) {
|
|
|
public RecallRequest(ParamQueryFilter paramQueryFilter, IStrategy strategy) {
|
|
|
this.paramQueryFilter = paramQueryFilter;
|
|
|
this.extendFilter = extendFilter;
|
|
|
this.sortBuilders = Arrays.asList(sortBuilder);
|
|
|
this.size = size;
|
|
|
this.requestType = requestType;
|
|
|
this.cacheTimeInSecond = cacheTimeInSecond;
|
|
|
this.strategy = strategy;
|
|
|
this.redisKeyBuilder = genRedisKeyBuilder();
|
|
|
}
|
|
|
|
|
|
private RedisKeyBuilder genRedisKeyBuilder() {
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.append("paramMd5Key:").append(paramQueryFilter == null ? "" : paramQueryFilter.getParamMd5Key());
|
|
|
sb.append("extendFilter:").append(extendFilter == null ? "" : extendFilter.toString());
|
|
|
sb.append("sortBuilders:").append(sortBuilders == null ? "" : sortBuilders.toString());
|
|
|
sb.append("size:").append(size == null ? "0" : size.toString());
|
|
|
sb.append("cacheTimeInSecond:").append(cacheTimeInSecond);
|
|
|
sb.append("strategyCacheKey:").append(strategy == null ? "" : strategy.strategyCacheKey());
|
|
|
String cacheKey = MD5Util.string2MD5(sb.toString());
|
|
|
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendVar(requestType).appendFixed(":").appendVar(cacheKey);
|
|
|
return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("RECALL:").appendVar(cacheKey);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String requestType() {
|
|
|
return this.requestType;
|
|
|
return this.strategy.nameEnum().name();
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -58,7 +48,7 @@ public class RecallRequest implements IRecallRequest { |
|
|
|
|
|
@Override
|
|
|
public int cacheTimeInSecond() {
|
|
|
return this.cacheTimeInSecond;
|
|
|
return this.strategy.cacheTimeInSecond();
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -67,19 +57,19 @@ public class RecallRequest implements IRecallRequest { |
|
|
searchParam.setQuery(this.paramQueryFilter.getParamQuery());
|
|
|
searchParam.setFiter(this.getRealFilter());
|
|
|
searchParam.setIncludeFields(this.includeFields());
|
|
|
searchParam.setSortBuilders(this.sortBuilders);
|
|
|
searchParam.setSortBuilders(Arrays.asList(this.strategy.sortBuilder()));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(this.size);
|
|
|
searchParam.setSize(this.strategy.size());
|
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
private QueryBuilder getRealFilter() {
|
|
|
if (extendFilter == null) {
|
|
|
if (this.strategy==null || strategy.extendFilter() == null) {
|
|
|
return this.paramQueryFilter.getParamFilter();
|
|
|
}
|
|
|
BoolQueryBuilder realFilter = QueryBuilders.boolQuery();
|
|
|
realFilter.must(this.paramQueryFilter.getParamFilter());
|
|
|
realFilter.must(this.extendFilter);
|
|
|
realFilter.must(this.strategy.extendFilter());
|
|
|
return realFilter;
|
|
|
}
|
|
|
|
...
|
...
|
|