当前位置: 首页>>代码示例>>Java>>正文


Java FixedBitSet类代码示例

本文整理汇总了Java中org.apache.lucene.util.FixedBitSet的典型用法代码示例。如果您正苦于以下问题:Java FixedBitSet类的具体用法?Java FixedBitSet怎么用?Java FixedBitSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FixedBitSet类属于org.apache.lucene.util包,在下文中一共展示了FixedBitSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: markSeqNoAsCompleted

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
/**
 * Marks the processing of the provided sequence number as completed as updates the checkpoint if possible.
 *
 * @param seqNo the sequence number to mark as completed
 */
public synchronized void markSeqNoAsCompleted(final long seqNo) {
    // make sure we track highest seen sequence number
    if (seqNo >= nextSeqNo) {
        nextSeqNo = seqNo + 1;
    }
    if (seqNo <= checkpoint) {
        // this is possible during recovery where we might replay an operation that was also replicated
        return;
    }
    final FixedBitSet bitSet = getBitSetForSeqNo(seqNo);
    final int offset = seqNoToBitSetOffset(seqNo);
    bitSet.set(offset);
    if (seqNo == checkpoint + 1) {
        updateCheckpoint();
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:LocalCheckpointTracker.java

示例2: testSingleValuedLongs

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
public void testSingleValuedLongs() throws Exception {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final long[] array = new long[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = randomLong();
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else if (docsWithValue != null && randomBoolean()) {
            docsWithValue.set(i);
        }
    }
    final NumericDocValues singleValues = new NumericDocValues() {
        @Override
        public long get(int docID) {
            return array[docID];
        }
    };
    final SortedNumericDocValues multiValues = DocValues.singleton(singleValues, docsWithValue);
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MultiValueModeTests.java

示例3: testSingleValuedDoubles

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
public void testSingleValuedDoubles() throws Exception  {
    final int numDocs = scaledRandomIntBetween(1, 100);
    final double[] array = new double[numDocs];
    final FixedBitSet docsWithValue = randomBoolean() ? null : new FixedBitSet(numDocs);
    for (int i = 0; i < array.length; ++i) {
        if (randomBoolean()) {
            array[i] = randomDouble();
            if (docsWithValue != null) {
                docsWithValue.set(i);
            }
        } else if (docsWithValue != null && randomBoolean()) {
            docsWithValue.set(i);
        }
    }
    final NumericDoubleValues singleValues = new NumericDoubleValues() {
        @Override
        public double get(int docID) {
            return array[docID];
        }
    };
    final SortedNumericDoubleValues multiValues = FieldData.singleton(singleValues, docsWithValue);
    verify(multiValues, numDocs);
    final FixedBitSet rootDocs = randomRootDocs(numDocs);
    final FixedBitSet innerDocs = randomInnerDocs(rootDocs);
    verify(multiValues, numDocs, rootDocs, innerDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:MultiValueModeTests.java

示例4: getSeqNosSet

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
private static FixedBitSet getSeqNosSet(final IndexReader reader, final long highestSeqNo) throws IOException {
    // _seq_no are stored as doc values for the time being, so this is how we get them
    // (as opposed to using an IndexSearcher or IndexReader)
    final FixedBitSet bitSet = new FixedBitSet((int) highestSeqNo + 1);
    final List<LeafReaderContext> leaves = reader.leaves();
    if (leaves.isEmpty()) {
        return bitSet;
    }

    for (int i = 0; i < leaves.size(); i++) {
        final LeafReader leaf = leaves.get(i).reader();
        final NumericDocValues values = leaf.getNumericDocValues(SeqNoFieldMapper.NAME);
        if (values == null) {
            continue;
        }
        final Bits bits = leaf.getLiveDocs();
        for (int docID = 0; docID < leaf.maxDoc(); docID++) {
            if (bits == null || bits.get(docID)) {
                final long seqNo = values.get(docID);
                assertFalse("should not have more than one document with the same seq_no[" + seqNo + "]", bitSet.get((int) seqNo));
                bitSet.set((int) seqNo);
            }
        }
    }
    return bitSet;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:27,代码来源:InternalEngineTests.java

示例5: unionTermGroups

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
/** union (term group) bit-sets until they are disjoint (O(n^^2)), and each group have different terms */
private void unionTermGroups(ArrayList<FixedBitSet> bb) {
  int incr;
  for (int i=0; i<bb.size()-1; i+=incr) {
    incr = 1;
    int j = i+1;
    while (j<bb.size()) {
      if (bb.get(i).intersects(bb.get(j))) {
        bb.get(i).or(bb.get(j));
        bb.remove(j);
        incr = 0;
      } else {
        ++j;
      }
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:SloppyPhraseScorer.java

示例6: addValue

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
public void addValue(int docID, long value) {
  if (docID < pending.size()) {
    throw new IllegalArgumentException("DocValuesField \"" + fieldInfo.name + "\" appears more than once in this document (only one value is allowed per field)");
  }

  // Fill in any holes:
  for (int i = (int)pending.size(); i < docID; ++i) {
    pending.add(MISSING);
  }

  pending.add(value);
  if (docsWithField != null) {
    docsWithField = FixedBitSet.ensureCapacity(docsWithField, docID);
    docsWithField.set(docID);
  }

  updateBytesUsed();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:NumericDocValuesWriter.java

示例7: bits

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
/**
 * Create a bit vector representing the live documents of the
 * virtual collection to be used in searches.
 * This will respect deleted documents.
 * 
 * @param The
 *            {@link LeafReaderContext} to search in.
 * @return A bit vector representing the live documents of the
 *         virtual collection.
 * @throws IOException
 */
public FixedBitSet bits (LeafReaderContext atomic) throws IOException {
    LeafReader r = atomic.reader();
    FixedBitSet bitset = new FixedBitSet(r.maxDoc());
    DocIdSet docids = this.getDocIdSet(atomic, (Bits) r.getLiveDocs());

    if (docids == null) {
        if (this.cbi != null) {
            bitset.clear(0, bitset.length());
        }
        else {
            bitset.set(0, bitset.length());
        };
    }
    else
        bitset.or(docids.iterator());

    return bitset;
}
 
开发者ID:KorAP,项目名称:Krill,代码行数:30,代码来源:KrillCollection.java

示例8: getLeafCollector

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
@Override
public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
  current = new FixedBitSet(context.reader().maxDoc());
  fixedBitSets.add(context.ord, current);

  return new LeafCollector() {

    @Override
    public void setScorer(Scorer scorer) throws IOException {}

    @Override
    public void collect(int doc) throws IOException {
      current.set(doc);
      totalHits++;
    }

  };
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:19,代码来源:BitSetHitStream.java

示例9: deserialize

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
public static FuzzySet deserialize(DataInput in) throws IOException
{
  int version=in.readInt();
  if (version == VERSION_SPI) {
    in.readString();
  }
  final HashFunction hashFunction = hashFunctionForVersion(version);
  int bloomSize=in.readInt();
  int numLongs=in.readInt();
  long[]longs=new long[numLongs];
  for (int i = 0; i < numLongs; i++) {
    longs[i]=in.readLong();
  }
  FixedBitSet bits = new FixedBitSet(longs,bloomSize+1);
  return new FuzzySet(bits,bloomSize,hashFunction);
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:FuzzySet.java

示例10: openBitSetContains

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
private boolean openBitSetContains(int[] expectedDocs, FixedBitSet actual, int maxDoc) throws IOException {
  if (expectedDocs.length != actual.cardinality()) {
    return false;
  }

  FixedBitSet expected = new FixedBitSet(maxDoc);
  for (int expectedDoc : expectedDocs) {
    expected.set(expectedDoc);
  }

  int docId;
  DocIdSetIterator iterator = expected.iterator();
  while ((docId = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
    if (!actual.get(docId)) {
      return false;
    }
  }

  return true;
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:AllGroupHeadsCollectorTest.java

示例11: randomLiveDocs

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
Bits randomLiveDocs(int maxDoc) {
  if (rarely()) {
    if (random().nextBoolean()) {
      return null;
    } else {
      return new Bits.MatchNoBits(maxDoc);
    }
  }
  final FixedBitSet bits = new FixedBitSet(maxDoc);
  final int bitsSet = TestUtil.nextInt(random(), 1, maxDoc - 1);
  for (int i = 0; i < bitsSet; ++i) {
    while (true) {
      final int index = random().nextInt(maxDoc);
      if (!bits.get(index)) {
        bits.set(index);
        break;
      }
    }
  }
  return bits;
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SorterTestBase.java

示例12: createDocs

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
/**
 * Creates a {@link Docs} to record hits. The default uses {@link FixedBitSet}
 * to record hits and you can override to e.g. record the docs in your own
 * {@link DocIdSet}.
 */
protected Docs createDocs(final int maxDoc) {
  return new Docs() {
    private final FixedBitSet bits = new FixedBitSet(maxDoc);
    
    @Override
    public void addDoc(int docId) throws IOException {
      bits.set(docId);
    }
    
    @Override
    public DocIdSet getDocIdSet() {
      return bits;
    }
  };
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:FacetsCollector.java

示例13: weightedSuperposition

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
public static Vector weightedSuperposition(
    BinaryVector v1, double weight1, BinaryVector v2, double weight2) {
  BinaryVector conclusion = (BinaryVector) VectorFactory.createZeroVector(VectorType.BINARY, v1.getDimension());
  FixedBitSet cVote = conclusion.bitSet;
  FixedBitSet v1vote = v1.bitSet;
  FixedBitSet v2vote = v2.bitSet;

  Random random = new Random();
  random.setSeed(Bobcat.asLong(v1.writeLongToString())); 

  for (int x = 0; x < v1.getDimension(); x++) {
    double probability = 0;
    if (v1vote.get(x)) probability += weight1 / (weight1 + weight2);
    if (v2vote.get(x)) probability += weight2 / (weight1 + weight2);

    if (random.nextDouble() <= probability)
      cVote.set(x);
  }
  return conclusion;
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:21,代码来源:BinaryVectorUtils.java

示例14: fillDocsAndScores

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
protected void fillDocsAndScores(FixedBitSet matchingDocs, Bits acceptDocs, TermsEnum termsEnum) throws IOException {
  BytesRef spare = new BytesRef();
  DocsEnum docsEnum = null;
  for (int i = 0; i < terms.size(); i++) {
    if (termsEnum.seekExact(terms.get(ords[i], spare))) {
      docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
      float score = TermsIncludingScoreQuery.this.scores[ords[i]];
      for (int doc = docsEnum.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = docsEnum.nextDoc()) {
        matchingDocs.set(doc);
        // In the case the same doc is also related to a another doc, a score might be overwritten. I think this
        // can only happen in a many-to-many relation
        scores[doc] = score;
      }
    }
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:TermsIncludingScoreQuery.java

示例15: superposeBitSet

import org.apache.lucene.util.FixedBitSet; //导入依赖的package包/类
/**
 * This method is the first of two required to facilitate superposition. The underlying representation
 * (i.e. the voting record) is an ArrayList of FixedBitSet, each with dimension "dimension", which can
 * be thought of as an expanding 2D array of bits. Each column keeps count (in binary) for the respective
 * dimension, and columns are incremented in parallel by sweeping a bitset across the rows. In any dimension
 * in which the BitSet to be added contains a "1", the effect will be that 1's are changed to 0's until a
 * new 1 is added (e.g. the column '110' would become '001' and so forth).
 * 
 * The first method deals with floating point issues, and accelerates superposition by decomposing
 * the task into segments.
 * 
 * @param incomingBitSet
 * @param weight
 */
protected synchronized void superposeBitSet(FixedBitSet incomingBitSet, double weight) {
  // If fractional weights are used, encode all weights as integers (1000 x double value).
  weight = (int) Math.round(weight * Math.pow(10, BINARY_VECTOR_DECIMAL_PLACES));
  if (weight == 0) return;

  // Keep track of number (or cumulative weight) of votes.
  totalNumberOfVotes.set(totalNumberOfVotes.get() + (int) weight);

  // Decompose superposition task such that addition of some power of 2 (e.g. 64) is accomplished
  // by beginning the process at the relevant row (e.g. 7) instead of starting multiple (e.g. 64)
  // superposition processes at the first row.
  int logFloorOfWeight = (int) (Math.floor(Math.log(weight)/Math.log(2)));

  if (logFloorOfWeight < votingRecord.size() - 1) {
    while (logFloorOfWeight > 0) {
      superposeBitSetFromRowFloor(incomingBitSet, logFloorOfWeight);	
      weight = weight - (int) Math.pow(2,logFloorOfWeight);
      logFloorOfWeight = (int) (Math.floor(Math.log(weight)/Math.log(2)));	
    }
  }

  // Add remaining component of weight incrementally.
  for (int x = 0; x < weight; x++)
    superposeBitSetFromRowFloor(incomingBitSet, 0);
}
 
开发者ID:semanticvectors,项目名称:semanticvectors,代码行数:40,代码来源:BinaryVector.java


注:本文中的org.apache.lucene.util.FixedBitSet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。