1 package org.apache.lucene.search.spans;
3 * Copyright 2005 The Apache Software Foundation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import org.apache.lucene.index.Term;
20 import org.apache.lucene.index.TermPositions;
22 import java.io.IOException;
23 import java.util.Collections;
24 import java.util.Collection;
28 * Public for extension only
30 public class TermSpans extends Spans {
31 protected TermPositions positions;
36 protected int position;
39 public TermSpans(TermPositions positions, Term term) throws IOException {
41 this.positions = positions;
47 public boolean next() throws IOException {
49 if (!positions.next()) {
50 doc = Integer.MAX_VALUE;
53 doc = positions.doc();
54 freq = positions.freq();
57 position = positions.nextPosition();
63 public boolean skipTo(int target) throws IOException {
64 if (!positions.skipTo(target)) {
65 doc = Integer.MAX_VALUE;
69 doc = positions.doc();
70 freq = positions.freq();
73 position = positions.nextPosition();
94 // TODO: Remove warning after API has been finalized
96 public Collection<byte[]> getPayload() throws IOException {
97 byte [] bytes = new byte[positions.getPayloadLength()];
98 bytes = positions.getPayload(bytes, 0);
99 return Collections.singletonList(bytes);
102 // TODO: Remove warning after API has been finalized
104 public boolean isPayloadAvailable() {
105 return positions.isPayloadAvailable();
109 public String toString() {
110 return "spans(" + term.toString() + ")@" +
111 (doc == -1 ? "START" : (doc == Integer.MAX_VALUE) ? "END" : doc + "-" + position);
115 public TermPositions getPositions() {