Authored by hugufei

skn bit set

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"));
}
}
... ...
... ... @@ -5,6 +5,8 @@ public enum StrategyEnum {
FIRST_SKN(110),
DIRECT_TRAIN(109),
RECOMMEND_SKN(99),
SORT_BRAND_HEAT_VALUE(31),
SORT_BRAND_REDUCE_PRICE(32),
SORT_BRAND_PROMOTION(33),
... ...
package com.yoho.search.recall.scene.models.personal;
import java.io.Serializable;
import java.util.BitSet;
public class PageSknBitSet implements Serializable{
private static final long serialVersionUID = 7185024266096124078L;
private BitSet sknBitSet;
public BitSet getSknBitSet() {
return sknBitSet;
}
public void setSknBitSet(BitSet sknBitSet) {
this.sknBitSet = sknBitSet;
}
public boolean exist(int bitSetIndex) {
if(this.sknBitSet==null){
return false;
}
return sknBitSet.get(bitSetIndex);
}
}
... ...