1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import java.io.Closeable;
23 /** TermDocs provides an interface for enumerating <document, frequency>
24 pairs for a term. <p> The document portion names each document containing
25 the term. Documents are indicated by number. The frequency portion gives
26 the number of times the term occurred in each document. <p> The pairs are
27 ordered by document number.
29 @see IndexReader#termDocs()
32 public interface TermDocs extends Closeable {
33 /** Sets this to the data for a term.
34 * The enumeration is reset to the start of the data for this term.
36 void seek(Term term) throws IOException;
38 /** Sets this to the data for the current term in a {@link TermEnum}.
39 * This may be optimized in some implementations.
41 void seek(TermEnum termEnum) throws IOException;
43 /** Returns the current document number. <p> This is invalid until {@link
44 #next()} is called for the first time.*/
47 /** Returns the frequency of the term within the current document. <p> This
48 is invalid until {@link #next()} is called for the first time.*/
51 /** Moves to the next pair in the enumeration. <p> Returns true iff there is
52 such a next pair in the enumeration. */
53 boolean next() throws IOException;
55 /** Attempts to read multiple entries from the enumeration, up to length of
56 * <i>docs</i>. Document numbers are stored in <i>docs</i>, and term
57 * frequencies are stored in <i>freqs</i>. The <i>freqs</i> array must be as
58 * long as the <i>docs</i> array.
60 * <p>Returns the number of entries read. Zero is only returned when the
61 * stream has been exhausted. */
62 int read(int[] docs, int[] freqs) throws IOException;
64 /** Skips entries to the first beyond the current whose document number is
65 * greater than or equal to <i>target</i>. <p>Returns true iff there is such
66 * an entry. <p>Behaves as if written: <pre>
67 * boolean skipTo(int target) {
71 * } while (target > doc());
75 * Some implementations are considerably more efficient than that.
77 boolean skipTo(int target) throws IOException;
79 /** Frees associated resources. */
80 void close() throws IOException;