示例#1
0
 @Override
 public double getFacetSelectivity(BoboSegmentReader reader) {
   FacetDataCache<?> dataCache = facetDataCacheBuilder.build(reader);
   final OpenBitSet openBitSet = getBitSet(dataCache);
   int[] frequencies = dataCache.freqs;
   double selectivity = 0;
   int accumFreq = 0;
   int index = openBitSet.nextSetBit(0);
   while (index >= 0) {
     accumFreq += frequencies[index];
     index = openBitSet.nextSetBit(index + 1);
   }
   int total = reader.maxDoc();
   selectivity = (double) accumFreq / (double) total;
   if (selectivity > 0.999) {
     selectivity = 1.0;
   }
   return selectivity;
 }
示例#2
0
  @Override
  public RandomAccessDocIdSet getRandomAccessDocIdSet(final BoboSegmentReader reader)
      throws IOException {
    final FacetDataCache<?> dataCache = facetDataCacheBuilder.build(reader);
    final OpenBitSet openBitSet = getBitSet(dataCache);
    long count = openBitSet.cardinality();
    if (count == 0) {
      return EmptyDocIdSet.getInstance();
    } else {
      final boolean multi = dataCache instanceof MultiValueFacetDataCache;
      final MultiValueFacetDataCache<?> multiCache =
          multi ? (MultiValueFacetDataCache<?>) dataCache : null;

      return new RandomAccessDocIdSet() {
        @Override
        public DocIdSetIterator iterator() {

          if (multi) {
            return new MultiValueORFacetFilter.MultiValueOrFacetDocIdSetIterator(
                multiCache, openBitSet);
          } else {
            return new FacetOrFilter.FacetOrDocIdSetIterator(dataCache, openBitSet);
          }
        }

        @Override
        public boolean get(int docId) {
          if (multi) {
            return multiCache._nestedArray.contains(docId, openBitSet);
          } else {
            return openBitSet.fastGet(dataCache.orderArray.get(docId));
          }
        }
      };
    }
  }