org.apache.lucene.util.BitSet类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(107)

本文整理了Java中org.apache.lucene.util.BitSet类的一些代码示例,展示了BitSet类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet类的具体详情如下:
包路径:org.apache.lucene.util.BitSet
类名称:BitSet

BitSet介绍

[英]Base implementation for a bit set.
[中]位集的基本实现。

代码示例

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public int nextDoc() {
 if (docID+1 == dvs.docsWithField.length()) {
  docID = NO_MORE_DOCS;
 } else {
  docID = dvs.docsWithField.nextSetBit(docID+1);
 }
 return docID;
}

代码示例来源:origin: org.apache.lucene/lucene-core

/** Does in-place OR of the bits provided by the iterator. The state of the
 *  iterator after this operation terminates is undefined. */
public void or(DocIdSetIterator iter) throws IOException {
 checkUnpositioned(iter);
 for (int doc = iter.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iter.nextDoc()) {
  set(doc);
 }
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public boolean advanceExact(int target) throws IOException {
 docID = target;
 return dvs.docsWithField.get(target);
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) {
  int currentDeleted = 0;
  while (currentDeleted < matchingDocs.length() &&
    (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) {
    int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted-1));
    for (int i = previousParent + 1; i < currentDeleted; i++) {
      matchingDocs.set(i);
    }
    currentDeleted++;
  }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private int findRootDocumentIfNested(SearchContext context, LeafReaderContext subReaderContext, int subDocId) throws IOException {
  if (context.mapperService().hasNested()) {
    BitSet bits = context.bitsetFilterCache()
      .getBitSetProducer(Queries.newNonNestedFilter(context.indexShard().indexSettings().getIndexVersionCreated()))
      .getBitSet(subReaderContext);
    if (!bits.get(subDocId)) {
      return bits.nextSetBit(subDocId);
    }
  }
  return -1;
}

代码示例来源:origin: harbby/presto-connectors

@Override
public boolean get(int docID) {
 assert parents.get(docID) : "this selector may only be used on parent documents";
 if (docID == 0) {
  // no children
  return false;
 }
 final int firstChild = parents.prevSetBit(docID - 1) + 1;
 for (int child = children.nextSetBit(firstChild); child < docID; child = children.nextSetBit(child + 1)) {
  if (docsWithValue.get(child)) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private static BitSetProducer newParentDocBitSetProducer(Version indexVersionCreated) {
    return context -> {
        Query query = Queries.newNonNestedFilter(indexVersionCreated);
        final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
        final IndexSearcher searcher = new IndexSearcher(topLevelContext);
        searcher.setQueryCache(null);
        final Weight weight = searcher.createNormalizedWeight(query, false);
        Scorer s = weight.scorer(context);
        return s == null ? null : BitSet.of(s.iterator(), context.reader().maxDoc());
      };
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Return an approximation of the cardinality of this set. Some
 * implementations may trade accuracy for speed if they have the ability to
 * estimate the cardinality of the set without iterating over all the data.
 * The default implementation returns {@link #cardinality()}.
 */
public int approximateCardinality() {
 return cardinality();
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public int advance(int target) {
 docID = dvs.docsWithField.nextSetBit(target);
 return docID;
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private void upgradeToBitSet() {
 assert bitSet == null;
 bitSet = new FixedBitSet(maxDoc);
 for (int i = 0; i < bufferSize; ++i) {
  bitSet.set(buffer[i]);
 }
 this.buffer = null;
 this.bufferSize = 0;
}

代码示例来源:origin: org.elasticsearch/elasticsearch

int previousParent = parentBits.prevSetBit(currentParent);
for (int docId = childIter.advance(previousParent + 1); docId < nestedSubDocId && docId != DocIdSetIterator.NO_MORE_DOCS;
    docId = childIter.nextDoc()) {
int nextParent = parentBits.nextSetBit(currentParent);
for (int docId = childIter.advance(currentParent + 1); docId < nextParent && docId != DocIdSetIterator.NO_MORE_DOCS;
    docId = childIter.nextDoc()) {

代码示例来源:origin: org.apache.lucene/lucene-core

/** Build a {@link BitSet} from the content of the provided {@link DocIdSetIterator}.
 *  NOTE: this will fully consume the {@link DocIdSetIterator}. */
public static BitSet of(DocIdSetIterator it, int maxDoc) throws IOException {
 final long cost = it.cost();
 final int threshold = maxDoc >>> 7;
 BitSet set;
 if (cost < threshold) {
  set = new SparseFixedBitSet(maxDoc);
 } else {
  set = new FixedBitSet(maxDoc);
 }
 set.or(it);
 return set;
}

代码示例来源:origin: org.apache.lucene/lucene-core

@Override
public long ramBytesUsed() {
 return BASE_RAM_BYTES_USED + set.ramBytesUsed();
}

代码示例来源:origin: harbby/presto-connectors

if (parents == null || parents.cardinality() == 0) {
 throw new IllegalStateException("Every segment should have at least one parent, but " + context.reader() + " does not have any");
if (parents.get(context.reader().maxDoc() - 1) == false) {
 throw new IllegalStateException("The last document of a segment must always be a parent, but " + context.reader() + " has a child as a last doc");

代码示例来源:origin: org.apache.lucene/lucene-core

/** Sole constructor. */
public BitSetIterator(BitSet bits, long cost) {
 if (cost < 0) {
  throw new IllegalArgumentException("cost must be >= 0, got " + cost);
 }
 this.bits = bits;
 this.length = bits.length();
 this.cost = cost;
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

/** Does in-place OR of the bits provided by the iterator. The state of the
 *  iterator after this operation terminates is undefined. */
public void or(DocIdSetIterator iter) throws IOException {
 assertUnpositioned(iter);
 for (int doc = iter.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iter.nextDoc()) {
  set(doc);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@Override
public void finish() {
 if (previous + 1 < length()) {
  clear(previous + 1, length());
 }
}

代码示例来源:origin: org.elasticsearch/elasticsearch

@Override
  public void collect(int parentDoc, long bucket) throws IOException {
    // if parentDoc is 0 then this means that this parent doesn't have child docs (b/c these appear always before the parent
    // doc), so we can skip:
    if (parentDoc == 0 || parentDocs == null || childDocs == null) {
      return;
    }
    final int prevParentDoc = parentDocs.prevSetBit(parentDoc - 1);
    int childDocId = childDocs.docID();
    if (childDocId <= prevParentDoc) {
      childDocId = childDocs.advance(prevParentDoc + 1);
    }
    for (; childDocId < parentDoc; childDocId = childDocs.nextDoc()) {
      collectBucket(sub, childDocId, bucket);
    }
  }
};

代码示例来源:origin: org.apache.lucene/lucene-core

/**
 * Same as {@link #BitDocIdSet(BitSet, long)} but uses the set's
 * {@link BitSet#approximateCardinality() approximate cardinality} as a cost.
 */
public BitDocIdSet(BitSet set) {
 this(set, set.approximateCardinality());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.elasticsearch

private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) {
  int currentDeleted = 0;
  while (currentDeleted < matchingDocs.length() &&
    (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) {
    int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted-1));
    for (int i = previousParent + 1; i < currentDeleted; i++) {
      matchingDocs.set(i);
    }
    currentDeleted++;
  }
}

相关文章