Authored by hugufei

skn bit set

  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 +}
@@ -5,6 +5,8 @@ public enum StrategyEnum { @@ -5,6 +5,8 @@ public enum StrategyEnum {
5 FIRST_SKN(110), 5 FIRST_SKN(110),
6 DIRECT_TRAIN(109), 6 DIRECT_TRAIN(109),
7 7
  8 + RECOMMEND_SKN(99),
  9 +
8 SORT_BRAND_HEAT_VALUE(31), 10 SORT_BRAND_HEAT_VALUE(31),
9 SORT_BRAND_REDUCE_PRICE(32), 11 SORT_BRAND_REDUCE_PRICE(32),
10 SORT_BRAND_PROMOTION(33), 12 SORT_BRAND_PROMOTION(33),
  1 +package com.yoho.search.recall.scene.models.personal;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.BitSet;
  5 +
  6 +public class PageSknBitSet implements Serializable{
  7 +
  8 + private static final long serialVersionUID = 7185024266096124078L;
  9 + private BitSet sknBitSet;
  10 +
  11 + public BitSet getSknBitSet() {
  12 + return sknBitSet;
  13 + }
  14 +
  15 + public void setSknBitSet(BitSet sknBitSet) {
  16 + this.sknBitSet = sknBitSet;
  17 + }
  18 +
  19 + public boolean exist(int bitSetIndex) {
  20 + if(this.sknBitSet==null){
  21 + return false;
  22 + }
  23 + return sknBitSet.get(bitSetIndex);
  24 + }
  25 +}