LocalCacheKeyUtils.java
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.yoho.search.common.utils;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.utils.SearchParamUtils;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.util.List;
import java.util.Set;
/**
* Created by henry on 2016/9/21.
*/
public class LocalCacheKeyUtils {
public static String guavaCacheKey(String indexName,SearchParam searchParam){
StringBuilder sb = new StringBuilder();
// 拼装索引名称
sb.append("indexName:").append(indexName).append(';');
// 拼装报文
SearchSourceBuilder searchSourceBuilder = SearchParamUtils.genSearchSourceBuilderFromSearchParam(searchParam);
sb.append("searchSource:").append(searchSourceBuilder.toString()).append(';');
String cacheKey = "YOHOSEARCH:" + MD5Util.string2MD5(sb.toString());
return cacheKey;
}
public static String genMultiGetParamKey(String indexName, Set<String> idList, List<String> fields) {
StringBuilder sb = new StringBuilder();
// 拼装索引名称
sb.append("indexName:").append(indexName).append(';');
// 拼装搜索类型
sb.append("idList:").append(idList.toString()).append(';');
// 拼装报文
sb.append("fields:").append(fields == null ? "" : fields.toString()).append(';');
// 打印拼装结果
return "YOHOSEARCH:" + MD5Util.string2MD5(sb.toString());
}
}