Example usage for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS

List of usage examples for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS

Introduction

In this page you can find the example usage for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS.

Prototype

int NO_MORE_DOCS

To view the source code for org.apache.lucene.search DocIdSetIterator NO_MORE_DOCS.

Click Source Link

Document

When returned by #nextDoc() , #advance(int) and #docID() it means there are no more docs in the iterator.

Usage

From source file:com.b2international.index.lucene.DocIdCollector.java

License:Apache License

/**
 * Returns with the {@link DocIds} instance.
 * @return the document IDs.//ww w. ja v  a2 s. com
 */
public DocIds getDocIDs() {

    return new DocIds() {

        @Override
        public int size() {
            return numDocIds;
        }

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

                private DocIdSetIterator docIdSetItr = new BitDocIdSet(docIds).iterator();
                private int nextDoc;

                @Override
                public boolean next() {

                    try {

                        nextDoc = docIdSetItr.nextDoc();
                        return nextDoc != DocIdSetIterator.NO_MORE_DOCS;

                    } catch (final IOException e) {

                        //this cannot happen as we are iterating over a bit set
                        nextDoc = DocIdSetIterator.NO_MORE_DOCS;

                        return false;

                    }

                }

                @Override
                public int getDocID() {
                    return nextDoc;
                }
            };
        }

        @Override
        public DocIdSet getDocIDs() {
            return new BitDocIdSet(docIds);
        }
    };

}

From source file:com.browseengine.bobo.geosearch.query.GeoScorerTest.java

License:Apache License

private void verifyEndAdvance(int advanceTo) throws IOException {
    int expectedDocid;
    for (int i = 0; i < 10; i++) {
        // no more hits
        docid = scorer.advance(advanceTo);

        expectedDocid = DocIdSetIterator.NO_MORE_DOCS;
        assertTrue("expectedDocid " + expectedDocid + ", got docid " + docid, expectedDocid == docid);
    }//from   ww w.j av a 2  s . co  m

}

From source file:com.browseengine.bobo.geosearch.query.GeoScorerTest.java

License:Apache License

private void verifyEndNextDoc() throws Exception {
    int expectedDocid;

    for (int i = 0; i < 10; i++) {
        // no more hits
        docid = scorer.nextDoc();/* w  w  w .ja  va 2s .  c  o m*/

        expectedDocid = DocIdSetIterator.NO_MORE_DOCS;
        assertTrue("expectedDocid " + expectedDocid + ", got docid " + docid, expectedDocid == docid);
    }

}

From source file:com.browseengine.bobo.search.section.AbstractTerminalNode.java

License:Apache License

@Override
public int fetchDoc(int targetDoc) throws IOException {
    if (targetDoc <= _curDoc)
        targetDoc = _curDoc + 1;/*from w w  w .  j av  a 2 s  . c  om*/

    if (_tp.skipTo(targetDoc)) {
        _curDoc = _tp.doc();
        _posLeft = _tp.freq();
        _curSec = -1;
        _curPos = -1;
        return _curDoc;
    } else {
        _curDoc = DocIdSetIterator.NO_MORE_DOCS;
        _tp.close();
        return _curDoc;
    }
}

From source file:com.browseengine.bobo.search.section.AndNode.java

License:Apache License

public AndNode(SectionSearchQueryPlan[] subqueries) {
    _subqueries = subqueries;
    _curDoc = (subqueries.length > 0 ? -1 : DocIdSetIterator.NO_MORE_DOCS);
}

From source file:com.browseengine.bobo.search.section.AndNode.java

License:Apache License

@Override
public int fetchDoc(int targetDoc) throws IOException {
    if (_curDoc == DocIdSetIterator.NO_MORE_DOCS) {
        return _curDoc;
    }/*  ww  w  . jav  a  2 s.  co m*/

    SectionSearchQueryPlan node = _subqueries[0];
    _curDoc = node.fetchDoc(targetDoc);
    targetDoc = _curDoc;

    int i = 1;
    while (i < _subqueries.length) {
        node = _subqueries[i];
        if (node._curDoc < targetDoc) {
            _curDoc = node.fetchDoc(targetDoc);
            if (_curDoc == DocIdSetIterator.NO_MORE_DOCS) {
                return _curDoc;
            }

            if (_curDoc > targetDoc) {
                targetDoc = _curDoc;
                i = 0;
                continue;
            }
        }
        i++;
    }
    _curSec = -1;
    return _curDoc;
}

From source file:com.browseengine.bobo.search.section.AndNotNode.java

License:Apache License

@Override
public int fetchSec(int targetSec) throws IOException {
    while (_curSec < SectionSearchQueryPlan.NO_MORE_SECTIONS) {
        _curSec = _positiveNode.fetchSec(targetSec);
        if (_curSec == SectionSearchQueryPlan.NO_MORE_SECTIONS)
            break;

        targetSec = _curSec;//from   w ww . j  a  v  a  2s . c o m

        if (_negativeNode._curDoc < _curDoc) {
            if (_negativeNode.fetchDoc(_curDoc) == DocIdSetIterator.NO_MORE_DOCS)
                break;
        }

        if (_negativeNode._curDoc == _curDoc
                && (_negativeNode._curSec == SectionSearchQueryPlan.NO_MORE_SECTIONS
                        || _negativeNode.fetchSec(targetSec) > _curSec)) {
            break;
        }
    }
    return _curSec;
}

From source file:com.browseengine.bobo.search.section.OrNode.java

License:Apache License

public OrNode(SectionSearchQueryPlan[] subqueries) {
    if (subqueries.length == 0) {
        _curDoc = DocIdSetIterator.NO_MORE_DOCS;
    } else {/*from  w w w.j a v  a2 s.com*/
        _pq = new NodeQueue(subqueries.length);
        for (SectionSearchQueryPlan q : subqueries) {
            if (q != null)
                _pq.add(q);
        }
        _curDoc = -1;
    }
}

From source file:com.browseengine.bobo.search.section.OrNode.java

License:Apache License

@Override
public int fetchDoc(int targetDoc) throws IOException {
    if (_curDoc == DocIdSetIterator.NO_MORE_DOCS)
        return _curDoc;

    if (targetDoc <= _curDoc)
        targetDoc = _curDoc + 1;//from   w w  w .  java  2 s  . co m

    _curSec = -1;

    SectionSearchQueryPlan node = (SectionSearchQueryPlan) _pq.top();
    while (true) {
        if (node._curDoc < targetDoc) {
            if (node.fetchDoc(targetDoc) < DocIdSetIterator.NO_MORE_DOCS) {
                node = (SectionSearchQueryPlan) _pq.updateTop();
            } else {
                _pq.pop();
                if (_pq.size() <= 0) {
                    _curDoc = DocIdSetIterator.NO_MORE_DOCS;
                    return _curDoc;
                }
                node = (SectionSearchQueryPlan) _pq.top();
            }
        } else {
            _curDoc = node._curDoc;
            return _curDoc;
        }
    }
}

From source file:com.browseengine.bobo.search.section.SectionSearchQueryPlan.java

License:Apache License

public int fetch(int targetDoc) throws IOException {
    while (fetchDoc(targetDoc) < DocIdSetIterator.NO_MORE_DOCS) {
        if (fetchSec(0) < SectionSearchQueryPlan.NO_MORE_SECTIONS)
            return _curDoc;
    }//from  w w w.ja v a2  s .  co  m
    return _curDoc;
}