KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > index > FilterIndexReader


1 package org.apache.lucene.index;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.lucene.document.Document;
20 import org.apache.lucene.document.Field;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Collection JavaDoc;
24
25 /** A <code>FilterIndexReader</code> contains another IndexReader, which it
26  * uses as its basic source of data, possibly transforming the data along the
27  * way or providing additional functionality. The class
28  * <code>FilterIndexReader</code> itself simply implements all abstract methods
29  * of <code>IndexReader</code> with versions that pass all requests to the
30  * contained index reader. Subclasses of <code>FilterIndexReader</code> may
31  * further override some of these methods and may also provide additional
32  * methods and fields.
33  */

34 public class FilterIndexReader extends IndexReader {
35
36   /** Base class for filtering {@link TermDocs} implementations. */
37   public static class FilterTermDocs implements TermDocs {
38     protected TermDocs in;
39
40     public FilterTermDocs(TermDocs in) { this.in = in; }
41
42     public void seek(Term term) throws IOException JavaDoc { in.seek(term); }
43     public void seek(TermEnum termEnum) throws IOException JavaDoc { in.seek(termEnum); }
44     public int doc() { return in.doc(); }
45     public int freq() { return in.freq(); }
46     public boolean next() throws IOException JavaDoc { return in.next(); }
47     public int read(int[] docs, int[] freqs) throws IOException JavaDoc {
48       return in.read(docs, freqs);
49     }
50     public boolean skipTo(int i) throws IOException JavaDoc { return in.skipTo(i); }
51     public void close() throws IOException JavaDoc { in.close(); }
52   }
53
54   /** Base class for filtering {@link TermPositions} implementations. */
55   public static class FilterTermPositions
56           extends FilterTermDocs implements TermPositions {
57
58     public FilterTermPositions(TermPositions in) { super(in); }
59
60     public int nextPosition() throws IOException JavaDoc {
61       return ((TermPositions) this.in).nextPosition();
62     }
63   }
64
65   /** Base class for filtering {@link TermEnum} implementations. */
66   public static class FilterTermEnum extends TermEnum {
67     protected TermEnum in;
68
69     public FilterTermEnum(TermEnum in) { this.in = in; }
70
71     public boolean next() throws IOException JavaDoc { return in.next(); }
72     public Term term() { return in.term(); }
73     public int docFreq() { return in.docFreq(); }
74     public void close() throws IOException JavaDoc { in.close(); }
75   }
76
77   protected IndexReader in;
78
79   /**
80    * <p>Construct a FilterIndexReader based on the specified base reader.
81    * Directory locking for delete, undeleteAll, and setNorm operations is
82    * left to the base reader.</p>
83    * <p>Note that base reader is closed if this FilterIndexReader is closed.</p>
84    * @param in specified base reader.
85    */

86   public FilterIndexReader(IndexReader in) {
87     super(in.directory());
88     this.in = in;
89   }
90
91   public TermFreqVector[] getTermFreqVectors(int docNumber)
92           throws IOException JavaDoc {
93     return in.getTermFreqVectors(docNumber);
94   }
95
96   public TermFreqVector getTermFreqVector(int docNumber, String JavaDoc field)
97           throws IOException JavaDoc {
98     return in.getTermFreqVector(docNumber, field);
99   }
100
101   public int numDocs() { return in.numDocs(); }
102   public int maxDoc() { return in.maxDoc(); }
103
104   public Document document(int n) throws IOException JavaDoc { return in.document(n); }
105
106   public boolean isDeleted(int n) { return in.isDeleted(n); }
107   public boolean hasDeletions() { return in.hasDeletions(); }
108   protected void doUndeleteAll() throws IOException JavaDoc { in.undeleteAll(); }
109
110   public boolean hasNorms(String JavaDoc field) throws IOException JavaDoc {
111     return in.hasNorms(field);
112   }
113
114   public byte[] norms(String JavaDoc f) throws IOException JavaDoc { return in.norms(f); }
115   public void norms(String JavaDoc f, byte[] bytes, int offset) throws IOException JavaDoc {
116     in.norms(f, bytes, offset);
117   }
118   protected void doSetNorm(int d, String JavaDoc f, byte b) throws IOException JavaDoc {
119     in.setNorm(d, f, b);
120   }
121
122   public TermEnum terms() throws IOException JavaDoc { return in.terms(); }
123   public TermEnum terms(Term t) throws IOException JavaDoc { return in.terms(t); }
124
125   public int docFreq(Term t) throws IOException JavaDoc { return in.docFreq(t); }
126
127   public TermDocs termDocs() throws IOException JavaDoc { return in.termDocs(); }
128
129   public TermPositions termPositions() throws IOException JavaDoc {
130     return in.termPositions();
131   }
132
133   protected void doDelete(int n) throws IOException JavaDoc { in.delete(n); }
134   protected void doCommit() throws IOException JavaDoc { in.commit(); }
135   protected void doClose() throws IOException JavaDoc { in.close(); }
136
137   public Collection JavaDoc getFieldNames() throws IOException JavaDoc {
138     return in.getFieldNames();
139   }
140
141   public Collection JavaDoc getFieldNames(boolean indexed) throws IOException JavaDoc {
142     return in.getFieldNames(indexed);
143   }
144
145   public Collection JavaDoc getIndexedFieldNames (Field.TermVector tvSpec){
146     return in.getIndexedFieldNames(tvSpec);
147   }
148   
149   public Collection JavaDoc getFieldNames(IndexReader.FieldOption fieldNames) {
150     return in.getFieldNames(fieldNames);
151   }
152 }
153
Popular Tags