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:org.opengrok.suggest.SuggesterSearcher.java

License:Open Source License

private int getDocumentFrequency(final IntsHolder documentIds, final int docBase,
        final PostingsEnum postingsEnum) throws IOException {

    int weight = 0;
    while (postingsEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
        if (documentIds.has(docBase + postingsEnum.docID())) {
            weight++;/*from ww  w.j  a  va 2 s  .co  m*/
        }
    }
    return normalizeDocumentFrequency(weight, documentIds.numberOfElements());
}

From source file:org.sakaiproject.nakamura.solr.NakamuraQueryComponent.java

License:Apache License

private ConstantScoreQuery buildFilterForPrincipals(final String[] principals) {
    Filter f = new Filter() {
        public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) {
            long start = System.currentTimeMillis();

            AtomicReader rdr = context.reader();
            OpenBitSet bits = new OpenBitSet(rdr.maxDoc());

            for (String principal : principals) {
                try {
                    DocsEnum td = rdr.termDocsEnum(null, "readers", new BytesRef(principal.trim()), false);

                    if (td == null) {
                        continue;
                    }/*w  w w  . j av  a  2 s.  c o m*/

                    while (td.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
                        bits.set(td.docID());
                    }

                } catch (IOException e) {
                    return null;
                }
            }

            LOGGER.debug("Building {}-bit filter for segment [{}] took: {} msecs",
                    new Object[] { rdr.maxDoc(), rdr, (System.currentTimeMillis() - start) });

            return bits;
        }
    };

    return new ConstantScoreQuery(new CachingWrapperFilter(f));
}

From source file:org.sindice.siren.search.AbstractTestSirenScorer.java

License:Apache License

/**
 * Return a term scorer which is positioned to the first element, i.e.
 * {@link SirenScorer#next()} has been called one time.
 *//*w ww .j a  v  a  2 s  . c om*/
protected SirenTermScorer getPositionedTermScorer(final String term) throws IOException {
    final IndexReader reader = _helper.getIndexReader();
    final TermPositions termPositions = reader.termPositions(new Term(QueryTestingHelper.DEFAULT_FIELD, term));
    final SirenTermScorer s = new SirenTermScorer(new ConstantWeight(), termPositions, new DefaultSimilarity(),
            reader.norms(QueryTestingHelper.DEFAULT_FIELD));
    assertNotSame(DocIdSetIterator.NO_MORE_DOCS, s.nextDoc());
    return s;
}

From source file:org.sindice.siren.search.node.TestLuceneProxyNodeScorer.java

License:Apache License

@Test
public void testNextDoc() throws Exception {
    this.addDocuments("{ \"aaa bbb\" : \"aaa ccc\" , \"ccc\" \"bbb ccc\" }", "{ \"aaa\" : \"aaa bbb ddd\" }");

    final Scorer scorer1 = this.getScorer(ntq("aaa").getLuceneProxyQuery());

    assertTrue(scorer1.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(0, scorer1.docID());/*from  w ww.  j a v  a  2s  .  c  om*/
    assertEquals(2, scorer1.freq(), 0);
    assertTrue(scorer1.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(1, scorer1.docID());
    assertEquals(2, scorer1.freq(), 0);
    assertTrue(scorer1.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);

    final Scorer scorer2 = this.getScorer(ntq("ccc").getLuceneProxyQuery());

    assertTrue(scorer2.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(0, scorer2.docID());
    assertEquals(3, scorer2.freq(), 0);
    assertTrue(scorer2.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);

    final Scorer scorer3 = this.getScorer(ntq("ddd").getLuceneProxyQuery());

    assertTrue(scorer3.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(1, scorer3.docID());
    assertEquals(1, scorer3.freq(), 0);
    assertTrue(scorer3.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
}

From source file:org.sindice.siren.search.node.TestLuceneProxyNodeScorer.java

License:Apache License

@Test
public void testAdvance() throws Exception {
    this.addDocuments("{ \"baba\" : \"aaa ccc\" , \"ccc\" \"bbb ccc\" }", "{ \"aaa\" : \"aaa bbb ddd\" }",
            "{ \"ddd\" : [ \"bobo\", \"bibi\" ] }");

    final Scorer scorer1 = this.getScorer(ntq("bobo").getLuceneProxyQuery());

    assertTrue(scorer1.advance(2) != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(2, scorer1.docID());//from   w w  w . j a  v  a  2s  .  c o m
    assertEquals(1, scorer1.freq(), 0);
    assertTrue(scorer1.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);

    final Scorer scorer2 = this.getScorer(ntq("baba").getLuceneProxyQuery());
    assertTrue(scorer2.advance(2) == DocIdSetIterator.NO_MORE_DOCS);
}

From source file:org.sindice.siren.search.node.TestLuceneProxyNodeScorer.java

License:Apache License

@Test
public void testAdvanceInfiniteLoop() throws Exception {
    this.addDocuments("{ \"baba\" : \"bibi ccc\" , \"ccc\" \"bbb ccc\" }",
            "{ \"baba bibi baba bibi\" : \"aaa bbb ddd\" }", "{ \"baba bibi\" : \"aaa bbb ddd\" }");

    final Scorer scorer1 = this.getScorer(nbq(must("baba", "bibi")).getLuceneProxyQuery());

    assertTrue(scorer1.advance(0) != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(1, scorer1.docID());//w w w. jav  a  2 s.  c o m
    assertEquals(2, scorer1.freq(), 0);
    final float score1 = scorer1.score();
    assertTrue(scorer1.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
    assertEquals(2, scorer1.docID());
    assertEquals(2, scorer1.freq(), 0);
    final float score2 = scorer1.score();
    assertTrue(score1 > score2);
    assertTrue(scorer1.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
}

From source file:org.sindice.siren.search.SirenPhrasePositions.java

License:Apache License

public int nextDoc() throws IOException { // increments to next entity
    if (!termPositions.next()) {
        termPositions.close(); // close stream
        dataset = entity = tuple = cell = pos = Integer.MAX_VALUE; // set to sentinel value
        return DocIdSetIterator.NO_MORE_DOCS;
    }/*from ww  w. j a  v a  2s  .com*/
    entity = termPositions.doc();
    dataset = tuple = cell = pos = -1;
    _hasSkippedPosition = false;
    return entity;
}

From source file:org.sindice.siren.search.SirenPhrasePositions.java

License:Apache License

public int advance(final int entityID) throws IOException {
    if (!termPositions.skipTo(entityID)) {
        termPositions.close();/*  w ww .ja  v  a 2  s  .c  o m*/
        dataset = entity = tuple = cell = pos = Integer.MAX_VALUE; // set to sentinel value
        return DocIdSetIterator.NO_MORE_DOCS;
    }
    entity = termPositions.doc();
    _hasSkippedPosition = false;
    return entity;
}

From source file:org.sindice.siren.search.SirenPhrasePositions.java

License:Apache License

public int advance(final int entityID, final int tupleID) throws IOException {
    if (!termPositions.skipTo(entityID, tupleID)) {
        termPositions.close();/*w ww.j  a v  a 2  s  .  co m*/
        dataset = entity = tuple = cell = pos = Integer.MAX_VALUE; // set to sentinel value
        return DocIdSetIterator.NO_MORE_DOCS;
    }
    entity = termPositions.entity();
    tuple = termPositions.tuple();
    cell = termPositions.cell();
    pos = termPositions.pos() - offset;
    _hasSkippedPosition = true;
    return entity;
}

From source file:org.sindice.siren.search.SirenPhrasePositions.java

License:Apache License

public int advance(final int entityID, final int tupleID, final int cellID) throws IOException {
    if (!termPositions.skipTo(entityID, tupleID, cellID)) {
        dataset = entity = tuple = cell = pos = Integer.MAX_VALUE; // set to sentinel value
        return DocIdSetIterator.NO_MORE_DOCS;
    }/*from   ww w  . j  av a 2s .com*/
    entity = termPositions.entity();
    tuple = termPositions.tuple();
    cell = termPositions.cell();
    pos = termPositions.pos() - offset;
    _hasSkippedPosition = true;
    return entity;
}