@Override
  public RandomAccessDocIdSet getRandomAccessDocIdSet(BoboIndexReader reader) throws IOException {
    final MultiValueFacetDataCache dataCache =
        (MultiValueFacetDataCache) _facetHandler.getFacetData(reader);
    final int[] index = _valueConverter.convert(dataCache, _vals);
    final BigNestedIntArray nestedArray = dataCache._nestedArray;
    final OpenBitSet bitset = new OpenBitSet(dataCache.valArray.size());

    for (int i : index) {
      bitset.fastSet(i);
    }

    if (_takeCompliment) {
      // flip the bits
      int size = dataCache.valArray.size();
      for (int i = 0; i < size; ++i) {
        bitset.fastFlip(i);
      }
    }

    long count = bitset.cardinality();

    if (count == 0) {
      final DocIdSet empty = EmptyDocIdSet.getInstance();
      return new RandomAccessDocIdSet() {
        @Override
        public boolean get(int docId) {
          return false;
        }

        @Override
        public DocIdSetIterator iterator() throws IOException {
          return empty.iterator();
        }
      };
    } else {
      return new RandomAccessDocIdSet() {
        @Override
        public DocIdSetIterator iterator() {
          return new MultiValueOrFacetDocIdSetIterator(dataCache, bitset);
        }

        @Override
        public final boolean get(int docId) {
          return nestedArray.contains(docId, bitset);
        }
      };
    }
  }
Example #2
0
  @Override
  public RandomAccessDocIdSet getRandomAccessDocIdSet(BoboIndexReader reader) throws IOException {

    RandomAccessDocIdSet innerDocSet = _facetFilter.getRandomAccessDocIdSet(reader);
    if (innerDocSet == EmptyDocIdSet.getInstance()) {
      return innerDocSet;
    }

    FacetDataCache dataCache = _facetDataCacheBuilder.build(reader);
    int totalCount = reader.maxDoc();
    TermValueList valArray = dataCache.valArray;
    int freqCount = 0;

    ArrayList<String> validVals = new ArrayList<String>(_valSet.size());
    for (String val : _valSet) {
      int idx = valArray.indexOf(val);
      if (idx >= 0) {
        validVals.add(valArray.get(idx)); // get and format the value
        freqCount += dataCache.freqs[idx];
      }
    }

    if (validVals.size() == 0) {
      return EmptyDocIdSet.getInstance();
    }

    // takeComplement is only used to choose between TermListRandomAccessDocIdSet and innerDocSet
    int validFreqCount = _takeComplement ? (totalCount - freqCount) : freqCount;

    if (_facetDataCacheBuilder.getName() != null && ((validFreqCount << 1) < totalCount)) {
      return new TermListRandomAccessDocIdSet(
          _facetDataCacheBuilder.getName(), innerDocSet, validVals, reader);
    } else {
      return innerDocSet;
    }
  }
Example #3
0
 @Override
 public DocIdSetIterator iterator() throws IOException {
   if (_vals.size() == 0) {
     return EmptyDocIdSet.getInstance().iterator();
   }
   if (_vals.size() == 1) {
     return new TermDocIdSet(_reader, _name, _vals.get(0)).iterator();
   } else {
     if (_vals.size() < OR_THRESHOLD) {
       ArrayList<DocIdSet> docSetList = new ArrayList<DocIdSet>(_vals.size());
       for (String val : _vals) {
         docSetList.add(new TermDocIdSet(_reader, _name, val));
       }
       return new OrDocIdSet(docSetList).iterator();
     } else {
       return _innerSet.iterator();
     }
   }
 }
Example #4
0
      @Override
      public DocIdSetIterator iterator() throws IOException {
        final TermDocs td = reader.termDocs(term);
        if (td == null) {
          return EmptyDocIdSet.getInstance().iterator();
        }
        return new DocIdSetIterator() {

          private int _doc = -1;

          @Override
          public int advance(int target) throws IOException {
            if (td.skipTo(target)) {
              _doc = td.doc();
            } else {
              td.close();
              _doc = DocIdSetIterator.NO_MORE_DOCS;
            }
            return _doc;
          }

          @Override
          public int docID() {
            return _doc;
          }

          @Override
          public int nextDoc() throws IOException {
            if (td.next()) {
              _doc = td.doc();
            } else {
              td.close();
              _doc = DocIdSetIterator.NO_MORE_DOCS;
            }
            return _doc;
          }
        };
      }
Example #5
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));
          }
        }
      };
    }
  }