|
|
1
|
+package com.yoho.search.recall.scene.beans.persional;
|
|
|
2
|
+
|
|
|
3
|
+import com.google.common.hash.BloomFilter;
|
|
|
4
|
+import com.google.common.hash.Funnels;
|
|
|
5
|
+import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
6
|
+import com.yoho.search.common.cache.impls.EhCache;
|
|
|
7
|
+import com.yoho.search.common.cache.model.CacheObject;
|
|
|
8
|
+import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
|
|
|
9
|
+import com.yoho.search.recall.scene.models.personal.PageSknBitSet;
|
|
|
10
|
+import org.apache.lucene.util.RamUsageEstimator;
|
|
|
11
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12
|
+import org.springframework.stereotype.Component;
|
|
|
13
|
+
|
|
|
14
|
+import java.nio.charset.Charset;
|
|
|
15
|
+
|
|
|
16
|
+@Component
|
|
|
17
|
+public class PageSknBitSetComponent {
|
|
|
18
|
+
|
|
|
19
|
+ @Autowired
|
|
|
20
|
+ private EhCache ehCache;
|
|
|
21
|
+
|
|
|
22
|
+ /**
|
|
|
23
|
+ * 获取页面上的skn列表
|
|
|
24
|
+ *
|
|
|
25
|
+ * @param paramQueryFilter
|
|
|
26
|
+ * @return
|
|
|
27
|
+ */
|
|
|
28
|
+ public PageSknBitSet queryPageSknBitSet(ParamQueryFilter paramQueryFilter) {
|
|
|
29
|
+ RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
|
|
|
30
|
+ redisKeyBuilder.appendFixed("YOHOSEARCH:").appendFixed("PAGESKN").appendVar(paramQueryFilter.getParamMd5Key());
|
|
|
31
|
+ CacheObject cacheObject = ehCache.get(redisKeyBuilder);
|
|
|
32
|
+ if(cacheObject!=null){
|
|
|
33
|
+ return (PageSknBitSet)cacheObject.toObject();
|
|
|
34
|
+ }
|
|
|
35
|
+ PageSknBitSet pageSknBitSet = new PageSknBitSet();
|
|
|
36
|
+ cacheObject = new CacheObject(pageSknBitSet);
|
|
|
37
|
+ ehCache.addOrUpdate(redisKeyBuilder,cacheObject,30);
|
|
|
38
|
+ return pageSknBitSet;
|
|
|
39
|
+ }
|
|
|
40
|
+
|
|
|
41
|
+ public static void main(String[] args) {
|
|
|
42
|
+ Charset charset = Charset.forName("utf-8");
|
|
|
43
|
+ BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(charset),2<<21);//指定bloomFilter的容量
|
|
|
44
|
+ for(int i =0;i<100000;i++){
|
|
|
45
|
+ bloomFilter.put(i+"");
|
|
|
46
|
+ }
|
|
|
47
|
+ System.out.println(bloomFilter.mightContain("1000000"));
|
|
|
48
|
+ }
|
|
|
49
|
+
|
|
|
50
|
+} |