01: package org.apache.lucene.index;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
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.
18: */
19:
20: import java.io.IOException;
21:
22: /** TermDocs provides an interface for enumerating <document, frequency>
23: pairs for a term. <p> The document portion names each document containing
24: the term. Documents are indicated by number. The frequency portion gives
25: the number of times the term occurred in each document. <p> The pairs are
26: ordered by document number.
27:
28: @see IndexReader#termDocs()
29: */
30:
31: public interface TermDocs {
32: /** Sets this to the data for a term.
33: * The enumeration is reset to the start of the data for this term.
34: */
35: void seek(Term term) throws IOException;
36:
37: /** Sets this to the data for the current term in a {@link TermEnum}.
38: * This may be optimized in some implementations.
39: */
40: void seek(TermEnum termEnum) throws IOException;
41:
42: /** Returns the current document number. <p> This is invalid until {@link
43: #next()} is called for the first time.*/
44: int doc();
45:
46: /** Returns the frequency of the term within the current document. <p> This
47: is invalid until {@link #next()} is called for the first time.*/
48: int freq();
49:
50: /** Moves to the next pair in the enumeration. <p> Returns true iff there is
51: such a next pair in the enumeration. */
52: boolean next() throws IOException;
53:
54: /** Attempts to read multiple entries from the enumeration, up to length of
55: * <i>docs</i>. Document numbers are stored in <i>docs</i>, and term
56: * frequencies are stored in <i>freqs</i>. The <i>freqs</i> array must be as
57: * long as the <i>docs</i> array.
58: *
59: * <p>Returns the number of entries read. Zero is only returned when the
60: * stream has been exhausted. */
61: int read(int[] docs, int[] freqs) throws IOException;
62:
63: /** Skips entries to the first beyond the current whose document number is
64: * greater than or equal to <i>target</i>. <p>Returns true iff there is such
65: * an entry. <p>Behaves as if written: <pre>
66: * boolean skipTo(int target) {
67: * do {
68: * if (!next())
69: * return false;
70: * } while (target > doc());
71: * return true;
72: * }
73: * </pre>
74: * Some implementations are considerably more efficient than that.
75: */
76: boolean skipTo(int target) throws IOException;
77:
78: /** Frees associated resources. */
79: void close() throws IOException;
80: }
|