001 package gate.creole.annic.apache.lucene.index;
002
003 /**
004 * Copyright 2004 The Apache Software Foundation
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 import java.io.IOException;
020 import java.util.Collection;
021
022 import gate.creole.annic.apache.lucene.document.Document;
023
024 /** A <code>FilterIndexReader</code> contains another IndexReader, which it
025 * uses as its basic source of data, possibly transforming the data along the
026 * way or providing additional functionality. The class
027 * <code>FilterIndexReader</code> itself simply implements all abstract methods
028 * of <code>IndexReader</code> with versions that pass all requests to the
029 * contained index reader. Subclasses of <code>FilterIndexReader</code> may
030 * further override some of these methods and may also provide additional
031 * methods and fields.
032 */
033 public class FilterIndexReader extends IndexReader {
034
035 /** Base class for filtering {@link TermDocs} implementations. */
036 public static class FilterTermDocs implements TermDocs {
037 protected TermDocs in;
038
039 public FilterTermDocs(TermDocs in) { this.in = in; }
040
041 public void seek(Term term) throws IOException { in.seek(term); }
042 public void seek(TermEnum termEnum) throws IOException { in.seek(termEnum); }
043 public int doc() { return in.doc(); }
044 public int freq() { return in.freq(); }
045 public boolean next() throws IOException { return in.next(); }
046 public int read(int[] docs, int[] freqs) throws IOException {
047 return in.read(docs, freqs);
048 }
049 public boolean skipTo(int i) throws IOException { return in.skipTo(i); }
050 public void close() throws IOException { in.close(); }
051 }
052
053 /** Base class for filtering {@link TermPositions} implementations. */
054 public static class FilterTermPositions
055 extends FilterTermDocs implements TermPositions {
056
057 public FilterTermPositions(TermPositions in) { super(in); }
058
059 public int nextPosition() throws IOException {
060 return ((TermPositions) this.in).nextPosition();
061 }
062 }
063
064 /** Base class for filtering {@link TermEnum} implementations. */
065 public static class FilterTermEnum extends TermEnum {
066 protected TermEnum in;
067
068 public FilterTermEnum(TermEnum in) { this.in = in; }
069
070 public boolean next() throws IOException { return in.next(); }
071 public Term term() { return in.term(); }
072 public int docFreq() { return in.docFreq(); }
073 public void close() throws IOException { in.close(); }
074 }
075
076 protected IndexReader in;
077
078 /**
079 * <p>Construct a FilterIndexReader based on the specified base reader.
080 * Directory locking for delete, undeleteAll, and setNorm operations is
081 * left to the base reader.</p>
082 * <p>Note that base reader is closed if this FilterIndexReader is closed.</p>
083 * @param in specified base reader.
084 */
085 public FilterIndexReader(IndexReader in) {
086 super(in.directory());
087 this.in = in;
088 }
089
090 public TermFreqVector[] getTermFreqVectors(int docNumber)
091 throws IOException {
092 return in.getTermFreqVectors(docNumber);
093 }
094
095 public TermFreqVector getTermFreqVector(int docNumber, String field)
096 throws IOException {
097 return in.getTermFreqVector(docNumber, field);
098 }
099
100 public int numDocs() { return in.numDocs(); }
101 public int maxDoc() { return in.maxDoc(); }
102
103 public Document document(int n) throws IOException { return in.document(n); }
104
105 public boolean isDeleted(int n) { return in.isDeleted(n); }
106 public boolean hasDeletions() { return in.hasDeletions(); }
107 protected void doUndeleteAll() throws IOException { in.undeleteAll(); }
108
109 public byte[] norms(String f) throws IOException { return in.norms(f); }
110 public void norms(String f, byte[] bytes, int offset) throws IOException {
111 in.norms(f, bytes, offset);
112 }
113 protected void doSetNorm(int d, String f, byte b) throws IOException {
114 in.setNorm(d, f, b);
115 }
116
117 public TermEnum terms() throws IOException { return in.terms(); }
118 public TermEnum terms(Term t) throws IOException { return in.terms(t); }
119
120 public int docFreq(Term t) throws IOException { return in.docFreq(t); }
121
122 public TermDocs termDocs() throws IOException { return in.termDocs(); }
123
124 public TermPositions termPositions() throws IOException {
125 return in.termPositions();
126 }
127
128 protected void doDelete(int n) throws IOException { in.delete(n); }
129 protected void doCommit() throws IOException { in.commit(); }
130 protected void doClose() throws IOException { in.close(); }
131
132 public Collection getFieldNames() throws IOException {
133 return in.getFieldNames();
134 }
135
136 public Collection getFieldNames(boolean indexed) throws IOException {
137 return in.getFieldNames(indexed);
138 }
139
140 /**
141 *
142 * @param storedTermVector if true, returns only Indexed fields that have term vector info,
143 * else only indexed fields without term vector info
144 * @return Collection of Strings indicating the names of the fields
145 */
146 public Collection getIndexedFieldNames(boolean storedTermVector) {
147 return in.getIndexedFieldNames(storedTermVector);
148 }
149 }
|