Example usage for org.apache.lucene.util BitDocIdSet iterator

List of usage examples for org.apache.lucene.util BitDocIdSet iterator

Introduction

In this page you can find the example usage for org.apache.lucene.util BitDocIdSet iterator.

Prototype

@Override
    public DocIdSetIterator iterator() 

Source Link

Usage

From source file:org.elasticsearch.index.search.child.AbstractChildTestCase.java

License:Apache License

static String reason(BitDocIdSet actual, BitDocIdSet expected, IndexSearcher indexSearcher) throws IOException {
    StringBuilder builder = new StringBuilder();
    builder.append("expected cardinality:").append(expected.bits().cardinality()).append('\n');
    DocIdSetIterator iterator = expected.iterator();
    for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
        builder.append("Expected doc[").append(doc).append("] with id value ")
                .append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
    }//from   w  w  w .j a v  a  2 s .  com
    builder.append("actual cardinality: ").append(actual.bits().cardinality()).append('\n');
    iterator = actual.iterator();
    for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
        builder.append("Actual doc[").append(doc).append("] with id value ")
                .append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)).append('\n');
    }
    return builder.toString();
}

From source file:org.hibernate.search.spatial.impl.SpatialHashQuery.java

License:LGPL

/**
 * Search the index for document having the correct spatial hash cell id at given grid level.
 *
 * @param context the {@link LeafReaderContext} for which to return the {@link DocIdSet}.
 * @return a {@link DocIdSetIterator} with the matching document ids
 *///ww  w  .  java  2 s  .  co m
private DocIdSetIterator createDocIdSetIterator(LeafReaderContext context) throws IOException {
    if (spatialHashCellsIds.size() == 0) {
        return null;
    }

    final LeafReader atomicReader = context.reader();

    BitDocIdSet matchedDocumentsIds = new BitDocIdSet(new FixedBitSet(atomicReader.maxDoc()));
    boolean found = false;
    for (int i = 0; i < spatialHashCellsIds.size(); i++) {
        Term spatialHashCellTerm = new Term(fieldName, spatialHashCellsIds.get(i));
        PostingsEnum spatialHashCellsDocs = atomicReader.postings(spatialHashCellTerm);
        if (spatialHashCellsDocs != null) {
            while (true) {
                final int docId = spatialHashCellsDocs.nextDoc();
                if (docId == DocIdSetIterator.NO_MORE_DOCS) {
                    break;
                } else {
                    matchedDocumentsIds.bits().set(docId);
                    found = true;
                }
            }
        }
    }

    if (found) {
        return matchedDocumentsIds.iterator();
    } else {
        return DocIdSetIterator.empty();
    }
}