Examples of FixedBitSet


Examples of org.apache.lucene.util.FixedBitSet

    /** Return the new doc ID according to its old value. */
    public abstract int map(int old);

    /** Useful from an assert. */
    boolean isConsistent(int maxDoc) {
      final FixedBitSet targets = new FixedBitSet(maxDoc);
      for (int i = 0; i < maxDoc; ++i) {
        final int target = map(i);
        if (target < 0 || target >= maxDoc) {
          assert false : "out of range: " + target + " not in [0-" + maxDoc + "[";
          return false;
        } else if (targets.get(target)) {
          assert false : target + " is already taken (" + i + ")";
          return false;
        }
      }
      return true;
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    Weight w = s.createNormalizedWeight(bq);

    assertEquals(1, s.getIndexReader().leaves().size());
    Scorer scorer = w.scorer(s.getIndexReader().leaves().get(0), false, true, null);

    final FixedBitSet hits = new FixedBitSet(docCount);
    final AtomicInteger end = new AtomicInteger();
    Collector c = new Collector() {
        @Override
        public void setNextReader(AtomicReaderContext sub) {
        }

        @Override
        public void collect(int doc) {
          assertTrue("collected doc=" + doc + " beyond max=" + end, doc < end.intValue());
          hits.set(doc);
        }

        @Override
        public void setScorer(Scorer scorer) {
        }

        @Override
        public boolean acceptsDocsOutOfOrder() {
          return true;
        }
      };

    while (end.intValue() < docCount) {
      final int inc = _TestUtil.nextInt(random(), 1, 1000);
      end.getAndAdd(inc);
      scorer.score(c, end.intValue(), -1);
    }

    assertEquals(docCount, hits.cardinality());
    r.close();
    dir.close();
  }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

 
  private static class RandomBits implements Bits {
    FixedBitSet bits;
   
    RandomBits(int maxDoc, double pctLive, Random random) {
      bits = new FixedBitSet(maxDoc);
      for (int i = 0; i < maxDoc; i++) {
        if (random.nextDouble() <= pctLive) {       
          bits.set(i);
        }
      }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    @Override
    public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
      final int maxDoc = context.reader().maxDoc();
      final FieldCache.Ints idSource = FieldCache.DEFAULT.getInts(context.reader(), "id", false);
      assertNotNull(idSource);
      final FixedBitSet bits = new FixedBitSet(maxDoc);
      for(int docID=0;docID<maxDoc;docID++) {
        if (random.nextFloat() <= density && (acceptDocs == null || acceptDocs.get(docID))) {
          bits.set(docID);
          //System.out.println("  acc id=" + idSource.getInt(docID) + " docID=" + docID);
          matchValues.add(docValues.get(idSource.get(docID)));
        }
      }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    final DirectoryReader indexReader = writer.getReader();
    writer.close();

    final AtomicReader reader = getOnlySegmentReader(indexReader);
    final Filter parentsFilter = new FixedBitSetCachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("parent", "true"))));
    final FixedBitSet parentBits = (FixedBitSet) parentsFilter.getDocIdSet(reader.getContext(), null);

    final NumericDocValues parentValues = reader.getNumericDocValues("parent_val");
    final Sorter.DocComparator parentComparator = new Sorter.DocComparator() {
      @Override
      public int compare(int docID1, int docID2) {
        assertTrue(parentBits.get(docID1));
        assertTrue(parentBits.get(docID2));
        final long v1 = parentValues.get(docID1);
        final long v2 = parentValues.get(docID2);
        return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
      }
    };

    final NumericDocValues childValues = reader.getNumericDocValues("child_val");
    final Sorter.DocComparator childComparator = new Sorter.DocComparator() {
      @Override
      public int compare(int docID1, int docID2) {
        assertFalse(parentBits.get(docID1));
        assertFalse(parentBits.get(docID2));
        final long v1 = childValues.get(docID1);
        final long v2 = childValues.get(docID2);
        return v1 < v2 ? -1 : v1 == v2 ? 0 : 1;
      }
    };

    final Sorter sorter = new BlockJoinSorter(parentsFilter) {
     
      @Override
      public String getID() {
        return "Dummy";
      }
     
      @Override
      protected DocComparator getParentComparator(AtomicReader r) {
        assertEquals(reader, r);
        return parentComparator;
      }

      @Override
      protected DocComparator getChildComparator(AtomicReader r) {
        assertEquals(reader, r);
        return childComparator;
      }

    };
    final Sorter.DocMap docMap = sorter.sort(reader);
    assertEquals(reader.maxDoc(), docMap.size());

    int[] children = new int[1];
    int numChildren = 0;
    int previousParent = -1;
    for (int i = 0; i < docMap.size(); ++i) {
      final int oldID = docMap.newToOld(i);
      if (parentBits.get(oldID)) {
        // check that we have the right children
        for (int j = 0; j < numChildren; ++j) {
          assertEquals(oldID, parentBits.nextSetBit(children[j]));
        }
        // check that children are sorted
        for (int j = 1; j < numChildren; ++j) {
          final int doc1 = children[j-1];
          final int doc2 = children[j];
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    }

    @Override
    protected DocIdSet cacheImpl(DocIdSetIterator iterator, AtomicReader reader)
        throws IOException {
      final FixedBitSet cached = new FixedBitSet(reader.maxDoc());
      cached.or(iterator);
      return cached;
    }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

  private static boolean isEmpty(DocIdSet set) {
    return set == null;
  }

  private static FixedBitSet toFixedBitSet(DocIdSetIterator iterator, int numBits) throws IOException {
    FixedBitSet set = new FixedBitSet(numBits);
    int doc;
    while ((doc = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
      set.set(doc);
    }
    return set;
  }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    final FixedBitSet alreadyEmittedDocs;

    MVInnerScorer(Weight weight, Bits acceptDocs, TermsEnum termsEnum, int maxDoc, long cost) {
      super(weight, acceptDocs, termsEnum, cost);
      alreadyEmittedDocs = new FixedBitSet(maxDoc);
    }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

    int currentDoc = -1;

    SVInOrderScorer(Weight weight, Bits acceptDocs, TermsEnum termsEnum, int maxDoc, long cost) throws IOException {
      super(weight);
      FixedBitSet matchingDocs = new FixedBitSet(maxDoc);
      this.scores = new float[maxDoc];
      fillDocsAndScores(matchingDocs, acceptDocs, termsEnum);
      this.matchingDocsIterator = matchingDocs.iterator();
      this.cost = cost;
    }
View Full Code Here

Examples of org.apache.lucene.util.FixedBitSet

  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;
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.