Package org.apache.lucene.search

Examples of org.apache.lucene.search.DocIdSetIterator


          }
        });
        // Asserting bit set...
        if (VERBOSE) {
          System.out.println("expected cardinality:" + expectedResult.cardinality());
          DocIdSetIterator iterator = expectedResult.iterator();
          for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
            System.out.println(String.format(Locale.ROOT, "Expected doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id")));
          }
          System.out.println("actual cardinality:" + actualResult.cardinality());
          iterator = actualResult.iterator();
          for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
            System.out.println(String.format(Locale.ROOT, "Actual doc[%d] with id value %s", doc, indexSearcher.doc(doc).get("id")));
          }
        }
        assertEquals(expectedResult, actualResult);
View Full Code Here


   
    boolean hasShouldClauses = false;
    for (final FilterClause fc : clauses) {
      if (fc.getOccur() == Occur.SHOULD) {
        hasShouldClauses = true;
        final DocIdSetIterator disi = getDISI(fc.getFilter(), context);
        if (disi == null) continue;
        if (res == null) {
          res = new FixedBitSet(reader.maxDoc());
        }
        res.or(disi);
      }
    }
    if (hasShouldClauses && res == null)
      return null;
   
    for (final FilterClause fc : clauses) {
      if (fc.getOccur() == Occur.MUST_NOT) {
        if (res == null) {
          assert !hasShouldClauses;
          res = new FixedBitSet(reader.maxDoc());
          res.set(0, reader.maxDoc()); // NOTE: may set bits on deleted docs
        }
        final DocIdSetIterator disi = getDISI(fc.getFilter(), context);
        if (disi != null) {
          res.andNot(disi);
        }
      }
    }
   
    for (final FilterClause fc : clauses) {
      if (fc.getOccur() == Occur.MUST) {
        final DocIdSetIterator disi = getDISI(fc.getFilter(), context);
        if (disi == null) {
          return null; // no documents can match
        }
        if (res == null) {
          res = new FixedBitSet(reader.maxDoc());
View Full Code Here

      }
      assertEquals("invalid maxDoc: " + doc, maxDoc, doc);
     
      DocIdSet docIDs = all.getDocIDs();
      assertTrue("should be cacheable", docIDs.isCacheable());
      DocIdSetIterator docIDsIter = docIDs.iterator();
      assertEquals("nextDoc() hasn't been called yet", -1, docIDsIter.docID());
      assertEquals(0, docIDsIter.nextDoc());
      assertEquals(1, docIDsIter.advance(1));
      // if advance is smaller than current doc, advance to cur+1.
      assertEquals(2, docIDsIter.advance(0));
    } finally {
      reader.close();
      dir.close();
    }
  }
View Full Code Here

          return true;
        }

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

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

    }

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

          @Override
          public float getScore() {
            return DEFAULT_SCORE;
          }

          @Override
          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() {
          return new DocIdSetIterator() {
            final Bits liveDocs = MultiFields.getLiveDocs(reader);
            private int next = -1;

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

    }

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

          @Override
          public float getScore() {
            return DEFAULT_SCORE;
          }

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

    if (isEmpty(innerDocuments)) {
      this.childDocuments = null;
    } else if (innerDocuments instanceof FixedBitSet) {
      this.childDocuments = (FixedBitSet) innerDocuments;
    } else {
      DocIdSetIterator iterator = innerDocuments.iterator();
      if (iterator != null) {
        this.childDocuments = toFixedBitSet(iterator, context.reader().maxDoc());
      } else {
        childDocuments = null;
      }
    }
    DocIdSet rootDocuments = parentFilter.getDocIdSet(context, null);
    if (isEmpty(rootDocuments)) {
      this.parentDocuments = null;
    } else if (rootDocuments instanceof FixedBitSet) {
      this.parentDocuments = (FixedBitSet) rootDocuments;
    } else {
      DocIdSetIterator iterator = rootDocuments.iterator();
      if (iterator != null) {
        this.parentDocuments = toFixedBitSet(iterator, context.reader().maxDoc());
      } else {
        this.parentDocuments = null;
      }
View Full Code Here

    for (QueryAndLimit ent : queriesIter) {
      Query query = ent.query;
      int limit = ent.limit;
      final DocIdSet docs = new QueryWrapperFilter(query).getDocIdSet(readerContext, reader.getLiveDocs());
      if (docs != null) {
        final DocIdSetIterator it = docs.iterator();
        if (it != null) {
          while(true)  {
            int doc = it.nextDoc();
            if (doc >= limit) {
              break;
            }

            if (!any) {
View Full Code Here

    //TODO if some andedDocIdSets are DocIdBitSet, merge them first.
    int size = andedDocIdSets.size();
    DocIdSetIterator[] iterators = new DocIdSetIterator[size];
    for ( int i = 0; i < size; i++ ) {
      // build all iterators
      DocIdSetIterator docIdSetIterator = andedDocIdSets.get( i ).iterator();
      if ( docIdSetIterator == null ) {
        // the Lucene API permits to return null on any iterator for empty matches
        return DocIdSet.EMPTY_DOCIDSET;
      }
      iterators[i] = docIdSetIterator;
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.