Example usage for org.apache.lucene.search.spans Spans cost

List of usage examples for org.apache.lucene.search.spans Spans cost

Introduction

In this page you can find the example usage for org.apache.lucene.search.spans Spans cost.

Prototype

public abstract long cost();

Source Link

Document

Returns the estimated cost of this DocIdSetIterator .

Usage

From source file:com.shaie.annots.SpanAnnotationTermQuery.java

License:Apache License

@Override
public Spans getSpans(LeafReaderContext context, Bits acceptDocs, Map<Term, TermContext> termContexts)
        throws IOException {
    final Spans spans = super.getSpans(context, acceptDocs, termContexts);
    return new Spans() {
        private int start, end;
        final ByteArrayDataInput in = new ByteArrayDataInput();

        @Override//from www . j a v a 2  s.co m
        public int start() {
            return start;
        }

        @Override
        public boolean skipTo(int target) throws IOException {
            return spans.skipTo(target);
        }

        @Override
        public boolean next() throws IOException {
            if (!spans.next()) {
                return false;
            }
            if (!isPayloadAvailable()) {
                return next();
            }
            byte[] payload = getPayload().iterator().next();
            in.reset(payload);
            start = in.readVInt();
            end = in.readVInt() + start - 1; // end is inclusive
            return true;
        }

        @Override
        public boolean isPayloadAvailable() throws IOException {
            return spans.isPayloadAvailable();
        }

        @Override
        public Collection<byte[]> getPayload() throws IOException {
            return spans.getPayload();
        }

        @Override
        public int end() {
            return end;
        }

        @Override
        public int doc() {
            return spans.doc();
        }

        @Override
        public long cost() {
            return spans.cost();
        }
    };
}