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

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

本文整理了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

  1. @Override
  2. public int nextDoc() {
  3. if (docID+1 == dvs.docsWithField.length()) {
  4. docID = NO_MORE_DOCS;
  5. } else {
  6. docID = dvs.docsWithField.nextSetBit(docID+1);
  7. }
  8. return docID;
  9. }

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

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

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

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

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

  1. private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) {
  2. int currentDeleted = 0;
  3. while (currentDeleted < matchingDocs.length() &&
  4. (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) {
  5. int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted-1));
  6. for (int i = previousParent + 1; i < currentDeleted; i++) {
  7. matchingDocs.set(i);
  8. }
  9. currentDeleted++;
  10. }
  11. }

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

  1. private int findRootDocumentIfNested(SearchContext context, LeafReaderContext subReaderContext, int subDocId) throws IOException {
  2. if (context.mapperService().hasNested()) {
  3. BitSet bits = context.bitsetFilterCache()
  4. .getBitSetProducer(Queries.newNonNestedFilter(context.indexShard().indexSettings().getIndexVersionCreated()))
  5. .getBitSet(subReaderContext);
  6. if (!bits.get(subDocId)) {
  7. return bits.nextSetBit(subDocId);
  8. }
  9. }
  10. return -1;
  11. }

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

  1. @Override
  2. public boolean get(int docID) {
  3. assert parents.get(docID) : "this selector may only be used on parent documents";
  4. if (docID == 0) {
  5. // no children
  6. return false;
  7. }
  8. final int firstChild = parents.prevSetBit(docID - 1) + 1;
  9. for (int child = children.nextSetBit(firstChild); child < docID; child = children.nextSetBit(child + 1)) {
  10. if (docsWithValue.get(child)) {
  11. return true;
  12. }
  13. }
  14. return false;
  15. }

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

  1. private static BitSetProducer newParentDocBitSetProducer(Version indexVersionCreated) {
  2. return context -> {
  3. Query query = Queries.newNonNestedFilter(indexVersionCreated);
  4. final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
  5. final IndexSearcher searcher = new IndexSearcher(topLevelContext);
  6. searcher.setQueryCache(null);
  7. final Weight weight = searcher.createNormalizedWeight(query, false);
  8. Scorer s = weight.scorer(context);
  9. return s == null ? null : BitSet.of(s.iterator(), context.reader().maxDoc());
  10. };
  11. }
  12. }

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

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

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

  1. @Override
  2. public int advance(int target) {
  3. docID = dvs.docsWithField.nextSetBit(target);
  4. return docID;
  5. }

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

  1. private void upgradeToBitSet() {
  2. assert bitSet == null;
  3. bitSet = new FixedBitSet(maxDoc);
  4. for (int i = 0; i < bufferSize; ++i) {
  5. bitSet.set(buffer[i]);
  6. }
  7. this.buffer = null;
  8. this.bufferSize = 0;
  9. }

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

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

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

  1. /** Build a {@link BitSet} from the content of the provided {@link DocIdSetIterator}.
  2. * NOTE: this will fully consume the {@link DocIdSetIterator}. */
  3. public static BitSet of(DocIdSetIterator it, int maxDoc) throws IOException {
  4. final long cost = it.cost();
  5. final int threshold = maxDoc >>> 7;
  6. BitSet set;
  7. if (cost < threshold) {
  8. set = new SparseFixedBitSet(maxDoc);
  9. } else {
  10. set = new FixedBitSet(maxDoc);
  11. }
  12. set.or(it);
  13. return set;
  14. }

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

  1. @Override
  2. public long ramBytesUsed() {
  3. return BASE_RAM_BYTES_USED + set.ramBytesUsed();
  4. }

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

  1. if (parents == null || parents.cardinality() == 0) {
  2. throw new IllegalStateException("Every segment should have at least one parent, but " + context.reader() + " does not have any");
  3. if (parents.get(context.reader().maxDoc() - 1) == false) {
  4. 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

  1. /** Sole constructor. */
  2. public BitSetIterator(BitSet bits, long cost) {
  3. if (cost < 0) {
  4. throw new IllegalArgumentException("cost must be >= 0, got " + cost);
  5. }
  6. this.bits = bits;
  7. this.length = bits.length();
  8. this.cost = cost;
  9. }

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

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

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

  1. @Override
  2. public void finish() {
  3. if (previous + 1 < length()) {
  4. clear(previous + 1, length());
  5. }
  6. }

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

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

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

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

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

  1. private void markChildDocs(BitSet parentDocs, BitSet matchingDocs) {
  2. int currentDeleted = 0;
  3. while (currentDeleted < matchingDocs.length() &&
  4. (currentDeleted = matchingDocs.nextSetBit(currentDeleted)) != DocIdSetIterator.NO_MORE_DOCS) {
  5. int previousParent = parentDocs.prevSetBit(Math.max(0, currentDeleted-1));
  6. for (int i = previousParent + 1; i < currentDeleted; i++) {
  7. matchingDocs.set(i);
  8. }
  9. currentDeleted++;
  10. }
  11. }

相关文章