Package org.apache.lucene.util

Examples of org.apache.lucene.util.FixedBitSet


      final BytesRef nextTerm = termsEnum.next();
      assertEquals(sortedTerms[i], nextTerm);
      assertEquals(sortedTerms[i], termsEnum.term());
      assertEquals(1, termsEnum.docFreq());

      final FixedBitSet bits = new FixedBitSet(1);
      DocsEnum docsEnum = termsEnum.docs(bits, random().nextBoolean() ? null : this.docsEnum.get());
      assertEquals(DocsEnum.NO_MORE_DOCS, docsEnum.nextDoc());
      bits.set(0);

      docsEnum = termsEnum.docs(random().nextBoolean() ? bits : null, random().nextBoolean() ? null : docsEnum);
      assertNotNull(docsEnum);
      assertEquals(0, docsEnum.nextDoc());
      assertEquals(0, docsEnum.docID());
      assertEquals(tk.freqs.get(termsEnum.term().utf8ToString()), (Integer) docsEnum.freq());
      assertEquals(DocsEnum.NO_MORE_DOCS, docsEnum.nextDoc());
      this.docsEnum.set(docsEnum);

      bits.clear(0);
      DocsAndPositionsEnum docsAndPositionsEnum = termsEnum.docsAndPositions(bits, random().nextBoolean() ? null : this.docsAndPositionsEnum.get());
      assertEquals(ft.storeTermVectorOffsets() || ft.storeTermVectorPositions(), docsAndPositionsEnum != null);
      if (docsAndPositionsEnum != null) {
        assertEquals(DocsEnum.NO_MORE_DOCS, docsAndPositionsEnum.nextDoc());
      }
      bits.set(0);

      docsAndPositionsEnum = termsEnum.docsAndPositions(random().nextBoolean() ? bits : null, random().nextBoolean() ? null : docsAndPositionsEnum);
      assertEquals(ft.storeTermVectorOffsets() || ft.storeTermVectorPositions(), docsAndPositionsEnum != null);
      if (terms.hasPositions() || terms.hasOffsets()) {
        assertEquals(0, docsAndPositionsEnum.nextDoc());
View Full Code Here


    if (allCollectors != null) {
      searcher.search(query, luceneFilter, allCollectors);
    }

    if (getGroupedDocSet && allGroupHeadsCollector != null) {
      FixedBitSet fixedBitSet = allGroupHeadsCollector.retrieveGroupHeads(maxDoc);
      long[] bits = fixedBitSet.getBits();
      OpenBitSet openBitSet = new OpenBitSet(bits, bits.length);
      qr.setDocSet(new BitDocSet(openBitSet));
    } else if (getDocSet) {
      qr.setDocSet(setCollector.getDocSet());
    }
View Full Code Here

    @Override
    protected final void doSetNextReader(AtomicReaderContext context) throws IOException {
      if (bits != null) {
        matchingDocs.add(new MatchingDocs(this.context, bits, totalHits, scores));
      }
      bits = new FixedBitSet(context.reader().maxDoc());
      totalHits = 0;
      scores = new float[64]; // some initial size
      this.context = context;
    }
View Full Code Here

    @Override
    protected final void doSetNextReader(AtomicReaderContext context) throws IOException {
      if (bits != null) {
        matchingDocs.add(new MatchingDocs(this.context, bits, totalHits, null));
      }
      bits = new FixedBitSet(context.reader().maxDoc());
      totalHits = 0;
      this.context = context;
    }
View Full Code Here

    int[] counts = new int[CHUNK];

    docIDs[0] = -1;
    int nextChunkStart = CHUNK;

    final FixedBitSet seen = new FixedBitSet(CHUNK);

    while (true) {
      //if (DEBUG) {
      //  System.out.println("\ncycle nextChunkStart=" + nextChunkStart + " docIds[0]=" + docIDs[0]);
      //}

      // First dim:
      //if (DEBUG) {
      //  System.out.println("  dim0");
      //}
      for(DocsEnum docsEnum : docsEnums[0]) {
        if (docsEnum == null) {
          continue;
        }
        int docID = docsEnum.docID();
        while (docID < nextChunkStart) {
          int slot = docID & MASK;

          if (docIDs[slot] != docID) {
            seen.set(slot);
            // Mark slot as valid:
            //if (DEBUG) {
            //  System.out.println("    set docID=" + docID + " id=" + context.reader().document(docID).get("id"));
            //}
            docIDs[slot] = docID;
            missingDims[slot] = 1;
            counts[slot] = 1;
          }

          docID = docsEnum.nextDoc();
        }
      }

      // Second dim:
      //if (DEBUG) {
      //  System.out.println("  dim1");
      //}
      for(DocsEnum docsEnum : docsEnums[1]) {
        if (docsEnum == null) {
          continue;
        }
        int docID = docsEnum.docID();
        while (docID < nextChunkStart) {
          int slot = docID & MASK;

          if (docIDs[slot] != docID) {
            // Mark slot as valid:
            seen.set(slot);
            //if (DEBUG) {
            //  System.out.println("    set docID=" + docID + " missingDim=0 id=" + context.reader().document(docID).get("id"));
            //}
            docIDs[slot] = docID;
            missingDims[slot] = 0;
            counts[slot] = 1;
          } else {
            // TODO: single-valued dims will always be true
            // below; we could somehow specialize
            if (missingDims[slot] >= 1) {
              missingDims[slot] = 2;
              counts[slot] = 2;
              //if (DEBUG) {
              //  System.out.println("    set docID=" + docID + " missingDim=2 id=" + context.reader().document(docID).get("id"));
              //}
            } else {
              counts[slot] = 1;
              //if (DEBUG) {
              //  System.out.println("    set docID=" + docID + " missingDim=" + missingDims[slot] + " id=" + context.reader().document(docID).get("id"));
              //}
            }
          }

          docID = docsEnum.nextDoc();
        }
      }

      // After this we can "upgrade" to conjunction, because
      // any doc not seen by either dim 0 or dim 1 cannot be
      // a hit or a near miss:

      //if (DEBUG) {
      //  System.out.println("  baseScorer");
      //}

      // Fold in baseScorer, using advance:
      int filledCount = 0;
      int slot0 = 0;
      while (slot0 < CHUNK && (slot0 = seen.nextSetBit(slot0)) != -1) {
        int ddDocID = docIDs[slot0];
        assert ddDocID != -1;

        int baseDocID = baseScorer.docID();
        if (baseDocID < ddDocID) {
          baseDocID = baseScorer.advance(ddDocID);
        }
        if (baseDocID == ddDocID) {
          //if (DEBUG) {
          //  System.out.println("    keep docID=" + ddDocID + " id=" + context.reader().document(ddDocID).get("id"));
          //}
          scores[slot0] = baseScorer.score();
          filledSlots[filledCount++] = slot0;
          counts[slot0]++;
        } else {
          //if (DEBUG) {
          //  System.out.println("    no docID=" + ddDocID + " id=" + context.reader().document(ddDocID).get("id"));
          //}
          docIDs[slot0] = -1;

          // TODO: we could jump slot0 forward to the
          // baseDocID ... but we'd need to set docIDs for
          // intervening slots to -1
        }
        slot0++;
      }
      seen.clear(0, CHUNK);

      if (filledCount == 0) {
        if (nextChunkStart >= maxDoc) {
          break;
        }
View Full Code Here

    assertDocIdSetCacheable(reader, FieldCacheRangeFilter.newIntRange("test", Integer.valueOf(10), Integer.valueOf(20), true, true), true);
    // a fixedbitset filter is always cacheable
    assertDocIdSetCacheable(reader, new Filter() {
      @Override
      public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) {
        return new FixedBitSet(context.reader().maxDoc());
      }
    }, true);

    reader.close();
    dir.close();
View Full Code Here

    private PagedMutable docs;
    private PagedGrowableWriter values;
    private int size;
   
    public PackedNumericFieldUpdates(int maxDoc) {
      docsWithField = new FixedBitSet(64);
      docs = new PagedMutable(1, 1024, PackedInts.bitsRequired(maxDoc - 1), PackedInts.COMPACT);
      values = new PagedGrowableWriter(1, 1024, 1, PackedInts.FAST);
      size = 0;
    }
View Full Code Here

        docs = docs.grow(size + 1);
        values = values.grow(size + 1);
        int numWords = (int) (docs.size() >> 6);
        if (docsWithField.getBits().length <= numWords) {
          numWords = ArrayUtil.oversize(numWords + 1, RamUsageEstimator.NUM_BYTES_LONG);
          docsWithField = new FixedBitSet(docsWithField, numWords << 6);
        }
      }
     
      if (value != NumericUpdate.MISSING) {
        // only mark the document as having a value in that field if the value wasn't set to null (MISSING)
View Full Code Here

    @Override
    public UpdatesIterator getUpdates() {
      final PagedMutable docs = this.docs;
      final PagedGrowableWriter values = this.values;
      final FixedBitSet docsWithField = this.docsWithField;
      new InPlaceMergeSorter() {
        @Override
        protected void swap(int i, int j) {
          long tmpDoc = docs.get(j);
          docs.set(j, docs.get(i));
          docs.set(i, tmpDoc);
         
          long tmpVal = values.get(j);
          values.set(j, values.get(i));
          values.set(i, tmpVal);
         
          boolean tmpBool = docsWithField.get(j);
          if (docsWithField.get(i)) {
            docsWithField.set(j);
          } else {
            docsWithField.clear(j);
          }
          if (tmpBool) {
            docsWithField.set(i);
          } else {
            docsWithField.clear(i);
          }
        }
       
        @Override
        protected int compare(int i, int j) {
          int x = (int) docs.get(i);
          int y = (int) docs.get(j);
          return (x < y) ? -1 : ((x == y) ? 0 : 1);
        }
      }.sort(0, size);

      final int size = this.size;
      return new UpdatesIterator() {
        private long idx = 0; // long so we don't overflow if size == Integer.MAX_VALUE
        private int doc = -1;
        private Long value = null;
       
        @Override
        Long value() {
          return value;
        }
       
        @Override
        int nextDoc() {
          if (idx >= size) {
            value = null;
            return doc = DocIdSetIterator.NO_MORE_DOCS;
          }
          doc = (int) docs.get(idx);
          ++idx;
          while (idx < size && docs.get(idx) == doc) {
            ++idx;
          }
          if (!docsWithField.get((int) (idx - 1))) {
            value = null;
          } else {
            // idx points to the "next" element
            value = Long.valueOf(values.get(idx - 1));
          }
View Full Code Here

        docs = docs.grow(size + packedOther.size);
        values = values.grow(size + packedOther.size);
        int numWords = (int) (docs.size() >> 6);
        if (docsWithField.getBits().length <= numWords) {
          numWords = ArrayUtil.oversize(numWords + 1, RamUsageEstimator.NUM_BYTES_LONG);
          docsWithField = new FixedBitSet(docsWithField, numWords << 6);
        }
        for (int i = 0; i < packedOther.size; i++) {
          int doc = (int) packedOther.docs.get(i);
          if (packedOther.docsWithField.get(i)) {
            docsWithField.set(size);
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.FixedBitSet

Copyright © 2018 www.massapicom. 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.