|
|
package com.yoho.search.recall.scene.beans.persional;
|
|
|
|
|
|
import com.google.common.hash.BloomFilter;
|
|
|
import com.google.common.hash.Funnels;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.search.common.cache.impls.EhCache;
|
|
|
import com.yoho.search.common.cache.model.CacheObject;
|
|
|
import com.yoho.search.recall.scene.models.common.ParamQueryFilter;
|
|
|
import com.yoho.search.recall.scene.models.personal.PageSknBitSet;
|
|
|
import org.apache.lucene.util.RamUsageEstimator;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
|
|
|
@Component
|
|
|
public class PageSknBitSetComponent {
|
|
|
|
|
|
@Autowired
|
|
|
private EhCache ehCache;
|
|
|
|
|
|
/**
|
|
|
* 获取页面上的skn列表
|
|
|
*
|
|
|
* @param paramQueryFilter
|
|
|
* @return
|
|
|
*/
|
|
|
public PageSknBitSet queryPageSknBitSet(ParamQueryFilter paramQueryFilter) {
|
|
|
RedisKeyBuilder redisKeyBuilder = RedisKeyBuilder.newInstance();
|
|
|
redisKeyBuilder.appendFixed("YOHOSEARCH:").appendFixed("PAGESKN").appendVar(paramQueryFilter.getParamMd5Key());
|
|
|
CacheObject cacheObject = ehCache.get(redisKeyBuilder);
|
|
|
if(cacheObject!=null){
|
|
|
return (PageSknBitSet)cacheObject.toObject();
|
|
|
}
|
|
|
PageSknBitSet pageSknBitSet = new PageSknBitSet();
|
|
|
cacheObject = new CacheObject(pageSknBitSet);
|
|
|
ehCache.addOrUpdate(redisKeyBuilder,cacheObject,30);
|
|
|
return pageSknBitSet;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
Charset charset = Charset.forName("utf-8");
|
|
|
BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(charset),2<<21);//指定bloomFilter的容量
|
|
|
for(int i =0;i<100000;i++){
|
|
|
bloomFilter.put(i+"");
|
|
|
}
|
|
|
System.out.println(bloomFilter.mightContain("1000000"));
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|