Package org.apache.lucene.search

Examples of org.apache.lucene.search.DocIdSetIterator


    MultiReader mr = new MultiReader(subs);
    return mr;
  }

  public void doTestIteratorEqual(DocIdSet a, DocIdSet b) throws IOException {
    DocIdSetIterator ia = a.iterator();
    DocIdSetIterator ib = b.iterator();

    // test for next() equivalence
    for(;;) {
      int da = ia.nextDoc();
      int db = ib.nextDoc();
      assertEquals(da, db);
      assertEquals(ia.docID(), ib.docID());
      if (da==DocIdSetIterator.NO_MORE_DOCS) break;
    }

    for (int i=0; i<10; i++) {
      // test random skipTo() and next()
      ia = a.iterator();
      ib = b.iterator();
      int doc = -1;
      for (;;) {
        int da,db;
        if (rand.nextBoolean()) {
          da = ia.nextDoc();
          db = ib.nextDoc();
        } else {
          int target = doc + rand.nextInt(10) + 1// keep in mind future edge cases like probing (increase if necessary)
          da = ia.advance(target);
          db = ib.advance(target);
        }

        assertEquals(da, db);
        assertEquals(ia.docID(), ib.docID());
        if (da==DocIdSetIterator.NO_MORE_DOCS) break;
        doc = da;
      }
    }
  }
View Full Code Here


    // If there are no deleted docs
    if (!reader.hasDeletions()) {
      return; // return immediately
    }

    DocIdSetIterator it = set.iterator();
    int doc = DocIdSetIterator.NO_MORE_DOCS;
    while ((doc = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
      if (reader.isDeleted(doc)) {
        set.fastClear(doc);
      }
    }
  }
View Full Code Here

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

          @Override
          public DocIdSetIterator iterator() throws IOException {
            return new DocIdSetIterator() {

              private int next = -1;

              @Override
              public int advance(int target) throws IOException {
View Full Code Here

    return new ScoredDocIDs() {
      private int size = -1;
      public DocIdSet getDocIDs() { return docIdSet; }

      public ScoredDocIDsIterator iterator() throws IOException {
        final DocIdSetIterator docIterator = docIdSet.iterator();
        return new ScoredDocIDsIterator() {
          public boolean next() {
            try {
              return docIterator.nextDoc() != DocIdSetIterator.NO_MORE_DOCS;
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }

          public float getScore() { return DEFAULT_SCORE; }

          public int getDocID() { return docIterator.docID(); }
        };
      }

      public int size() {
        // lazy size computation
View Full Code Here

          return true;
        }

        @Override
        public DocIdSetIterator iterator() throws IOException {
          return new DocIdSetIterator() {
            private int next = -1;

            @Override
            public int advance(int target) throws IOException {
              if (target <= next) {
View Full Code Here

      };
    }

    public ScoredDocIDsIterator iterator() {
      try {
        final DocIdSetIterator iter = getDocIDs().iterator();
        return new ScoredDocIDsIterator() {
          public boolean next() {
            try {
              return iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS;
            } catch (IOException e) {
              // cannot happen
              return false;
            }
          }

          public float getScore() {
            return DEFAULT_SCORE;
          }

          public int getDocID() {
            return iter.docID();
          }
        };
      } catch (IOException e) {
        // cannot happen
        throw new RuntimeException(e);
View Full Code Here

          return true;
        }

        @Override
        public DocIdSetIterator iterator() throws IOException {
          return new DocIdSetIterator() {
            private int next = -1;

            @Override
            public int advance(int target) throws IOException {
              if (target > next) {
View Full Code Here

      };
    }

    public ScoredDocIDsIterator iterator() {
      try {
        final DocIdSetIterator iter = getDocIDs().iterator();
        return new ScoredDocIDsIterator() {
          public boolean next() {
            try {
              return iter.nextDoc() != DocIdSetIterator.NO_MORE_DOCS;
            } catch (IOException e) {
              // cannot happen
              return false;
            }
          }

          public float getScore() {
            return DEFAULT_SCORE;
          }

          public int getDocID() {
            return iter.docID();
          }
        };
      } catch (IOException e) {
        // cannot happen
        throw new RuntimeException(e);
View Full Code Here

    MultiReader mr = new MultiReader(subs);
    return mr;
  }

  public void doTestIteratorEqual(DocIdSet a, DocIdSet b) throws IOException {
    DocIdSetIterator ia = a.iterator();
    DocIdSetIterator ib = b.iterator();

    // test for next() equivalence
    for(;;) {
      int da = ia.nextDoc();
      int db = ib.nextDoc();
      assertEquals(da, db);
      assertEquals(ia.docID(), ib.docID());
      if (da==DocIdSetIterator.NO_MORE_DOCS) break;
    }

    for (int i=0; i<10; i++) {
      // test random skipTo() and next()
      ia = a.iterator();
      ib = b.iterator();
      int doc = -1;
      for (;;) {
        int da,db;
        if (rand.nextBoolean()) {
          da = ia.nextDoc();
          db = ib.nextDoc();
        } else {
          int target = doc + rand.nextInt(10) + 1// keep in mind future edge cases like probing (increase if necessary)
          da = ia.advance(target);
          db = ib.advance(target);
        }

        assertEquals(da, db);
        assertEquals(ia.docID(), ib.docID());
        if (da==DocIdSetIterator.NO_MORE_DOCS) break;
        doc = da;
      }
    }
  }
View Full Code Here

        SlicedOpenBitSet bitSet = new SlicedOpenBitSet(new long[OpenBitSet.bits2words(numberOfBits) + 100], OpenBitSet.bits2words(numberOfBits), 100);

        bitSet.fastSet(100);
        assertThat(bitSet.fastGet(100), equalTo(true));

        DocIdSetIterator iterator = bitSet.iterator();
        assertThat(iterator.nextDoc(), equalTo(100));
        assertThat(iterator.nextDoc(), equalTo(DocIdSetIterator.NO_MORE_DOCS));
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.DocIdSetIterator

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.