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

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

Introduction

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

Prototype

public abstract int nextDoc() throws IOException;

Source Link

Document

Advances to the next document in the set and returns the doc it is currently on, or #NO_MORE_DOCS if there are no more docs in the set.
NOTE: after the iterator has exhausted you should not call this method, as it may result in unpredicted behavior.

Usage

From source file:org.apache.solr.search.facet.FacetFieldProcessorByArrayDV.java

License:Apache License

private void collectCounts(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int doc;//from  w  w  w  .j a v a2  s. com
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        if (multiDv.advanceExact(doc)) {
            for (;;) {
                int segOrd = (int) multiDv.nextOrd();
                if (segOrd < 0)
                    break;
                int ord = (int) toGlobal.get(segOrd);
                countAcc.incrementCount(ord, 1);
            }
        }
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectPerSeg(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int segMax = singleDv.getValueCount() + 1;
    final int[] counts = getCountArr(segMax);

    int doc;/*www  .  j  a va 2 s  .  co m*/
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        counts[singleDv.getOrd(doc) + 1]++;
    }

    for (int i = 1; i < segMax; i++) {
        int segCount = counts[i];
        if (segCount > 0) {
            int slot = toGlobal == null ? (i - 1) : (int) toGlobal.get(i - 1);
            countAcc.incrementCount(slot, segCount);
        }
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectPerSeg(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int segMax = (int) multiDv.getValueCount();
    final int[] counts = getCountArr(segMax);

    int doc;/* www.j  ava 2  s.co m*/
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        multiDv.setDocument(doc);
        for (;;) {
            int segOrd = (int) multiDv.nextOrd();
            if (segOrd < 0)
                break;
            counts[segOrd]++;
        }
    }

    for (int i = 0; i < segMax; i++) {
        int segCount = counts[i];
        if (segCount > 0) {
            int slot = toGlobal == null ? (i) : (int) toGlobal.get(i);
            countAcc.incrementCount(slot, segCount);
        }
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectDocs(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int doc;//from   w w  w. j a v  a 2 s.  c  om
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        int segOrd = singleDv.getOrd(doc);
        if (segOrd < 0)
            continue;
        collect(doc, segOrd, toGlobal);
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectCounts(SortedDocValues singleDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int doc;//  www  .j  a va2s  .c  om
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        int segOrd = singleDv.getOrd(doc);
        if (segOrd < 0)
            continue;
        int ord = (int) toGlobal.get(segOrd);
        countAcc.incrementCount(ord, 1);
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectDocs(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int doc;//from w  ww.  ja  v a 2  s.  co m
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        multiDv.setDocument(doc);
        for (;;) {
            int segOrd = (int) multiDv.nextOrd();
            if (segOrd < 0)
                break;
            collect(doc, segOrd, toGlobal);
        }
    }
}

From source file:org.apache.solr.search.facet.FacetFieldProcessorDV.java

License:Apache License

private void collectCounts(SortedSetDocValues multiDv, DocIdSetIterator disi, LongValues toGlobal)
        throws IOException {
    int doc;//from  w ww .j  a  v  a2 s .c o m
    while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
        multiDv.setDocument(doc);
        for (;;) {
            int segOrd = (int) multiDv.nextOrd();
            if (segOrd < 0)
                break;
            int ord = (int) toGlobal.get(segOrd);
            countAcc.incrementCount(ord, 1);
        }
    }
}

From source file:org.apache.solr.search.facet.FieldUtil.java

License:Apache License

public static void visitOrds(SortedDocValues singleDv, DocIdSetIterator disi, OrdFunc ordFunc)
        throws IOException {
    int doc;/*from w  w  w  .j a  va2s  .  com*/
    if (singleDv instanceof FieldCacheImpl.SortedDocValuesImpl.Iter) {
        FieldCacheImpl.SortedDocValuesImpl.Iter fc = (FieldCacheImpl.SortedDocValuesImpl.Iter) singleDv;
        while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            ordFunc.handleOrd(doc, fc.getOrd(doc));
        }
    } else {
        while ((doc = disi.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            if (singleDv.advanceExact(doc)) {
                ordFunc.handleOrd(doc, singleDv.ordValue());
            } else {
                // TODO: optionally pass in missingOrd?
            }
        }
    }
}

From source file:org.apache.solr.search.TestDocSet.java

License:Apache License

public void doTestIteratorEqual(DocIdSet a, DocIdSet b) throws IOException {
    DocIdSetIterator ia = a.iterator();
    DocIdSetIterator ib = b.iterator();/*from  w  ww  . j a  v a 2  s  .  c om*/

    // 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;
        }
    }
}

From source file:org.apache.solr.search.TestFilteredDocIdSet.java

License:Apache License

public void testFilteredDocIdSet() throws Exception {
    final int maxdoc = 10;
    final DocIdSet innerSet = new DocIdSet() {

        @Override//  w w  w . j  a  v a2 s  . c om
        public long ramBytesUsed() {
            return 0L;
        }

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

                int docid = -1;

                @Override
                public int docID() {
                    return docid;
                }

                @Override
                public int nextDoc() {
                    docid++;
                    return docid < maxdoc ? docid : (docid = NO_MORE_DOCS);
                }

                @Override
                public int advance(int target) throws IOException {
                    return slowAdvance(target);
                }

                @Override
                public long cost() {
                    return 1;
                }
            };
        }
    };

    DocIdSet filteredSet = new FilteredDocIdSet(innerSet) {
        @Override
        protected boolean match(int docid) {
            return docid % 2 == 0; //validate only even docids
        }
    };

    DocIdSetIterator iter = filteredSet.iterator();
    ArrayList<Integer> list = new ArrayList<>();
    int doc = iter.advance(3);
    if (doc != DocIdSetIterator.NO_MORE_DOCS) {
        list.add(Integer.valueOf(doc));
        while ((doc = iter.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
            list.add(Integer.valueOf(doc));
        }
    }

    int[] docs = new int[list.size()];
    int c = 0;
    Iterator<Integer> intIter = list.iterator();
    while (intIter.hasNext()) {
        docs[c++] = intIter.next().intValue();
    }
    int[] answer = new int[] { 4, 6, 8 };
    boolean same = Arrays.equals(answer, docs);
    if (!same) {
        System.out.println("answer: " + Arrays.toString(answer));
        System.out.println("gotten: " + Arrays.toString(docs));
        fail();
    }
}