Lucene.Net  3.0.3
Lucene.Net is a port of the Lucene search engine library, written in C# and targeted at .NET runtime users.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Pages
FilterIndexReader.cs
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 using System;
19 
20 using Document = Lucene.Net.Documents.Document;
21 using FieldSelector = Lucene.Net.Documents.FieldSelector;
22 using Directory = Lucene.Net.Store.Directory;
23 
24 namespace Lucene.Net.Index
25 {
26 
27  /// <summary>A <c>FilterIndexReader</c> contains another IndexReader, which it
28  /// uses as its basic source of data, possibly transforming the data along the
29  /// way or providing additional functionality. The class
30  /// <c>FilterIndexReader</c> itself simply implements all abstract methods
31  /// of <c>IndexReader</c> with versions that pass all requests to the
32  /// contained index reader. Subclasses of <c>FilterIndexReader</c> may
33  /// further override some of these methods and may also provide additional
34  /// methods and fields.
35  /// </summary>
37  {
38 
39  /// <summary>Base class for filtering <see cref="Lucene.Net.Index.TermDocs" /> implementations. </summary>
40  public class FilterTermDocs : TermDocs
41  {
42  protected internal TermDocs in_Renamed;
43 
44  public FilterTermDocs(TermDocs in_Renamed)
45  {
46  this.in_Renamed = in_Renamed;
47  }
48 
49  public virtual void Seek(Term term)
50  {
51  in_Renamed.Seek(term);
52  }
53  public virtual void Seek(TermEnum termEnum)
54  {
55  in_Renamed.Seek(termEnum);
56  }
57 
58  public virtual int Doc
59  {
60  get { return in_Renamed.Doc; }
61  }
62 
63  public virtual int Freq
64  {
65  get { return in_Renamed.Freq; }
66  }
67 
68  public virtual bool Next()
69  {
70  return in_Renamed.Next();
71  }
72  public virtual int Read(int[] docs, int[] freqs)
73  {
74  return in_Renamed.Read(docs, freqs);
75  }
76  public virtual bool SkipTo(int i)
77  {
78  return in_Renamed.SkipTo(i);
79  }
80 
81  public void Close()
82  {
83  Dispose();
84  }
85 
86  public void Dispose()
87  {
88  Dispose(true);
89  }
90 
91  protected virtual void Dispose(bool disposing)
92  {
93  if (disposing)
94  {
95  in_Renamed.Close();
96  }
97  }
98  }
99 
100  /// <summary>Base class for filtering <see cref="TermPositions" /> implementations. </summary>
102  {
103 
104  public FilterTermPositions(TermPositions in_Renamed):base(in_Renamed)
105  {
106  }
107 
108  public virtual int NextPosition()
109  {
110  return ((TermPositions) this.in_Renamed).NextPosition();
111  }
112 
113  public virtual int PayloadLength
114  {
115  get { return ((TermPositions) this.in_Renamed).PayloadLength; }
116  }
117 
118  public virtual byte[] GetPayload(byte[] data, int offset)
119  {
120  return ((TermPositions) this.in_Renamed).GetPayload(data, offset);
121  }
122 
123 
124  // TODO: Remove warning after API has been finalized
125 
126  public virtual bool IsPayloadAvailable
127  {
128  get { return ((TermPositions) this.in_Renamed).IsPayloadAvailable; }
129  }
130  }
131 
132  /// <summary>Base class for filtering <see cref="TermEnum" /> implementations. </summary>
134  {
135  protected internal TermEnum in_Renamed;
136 
137  public FilterTermEnum(TermEnum in_Renamed)
138  {
139  this.in_Renamed = in_Renamed;
140  }
141 
142  public override bool Next()
143  {
144  return in_Renamed.Next();
145  }
146 
147  public override Term Term
148  {
149  get { return in_Renamed.Term; }
150  }
151 
152  public override int DocFreq()
153  {
154  return in_Renamed.DocFreq();
155  }
156 
157  protected override void Dispose(bool disposing)
158  {
159  if (disposing)
160  {
161  in_Renamed.Close();
162  }
163  }
164  }
165 
166  protected internal IndexReader in_Renamed;
167 
168  /// <summary> <p/>Construct a FilterIndexReader based on the specified base reader.
169  /// Directory locking for delete, undeleteAll, and setNorm operations is
170  /// left to the base reader.<p/>
171  /// <p/>Note that base reader is closed if this FilterIndexReader is closed.<p/>
172  /// </summary>
173  /// <param name="in_Renamed">specified base reader.
174  /// </param>
175  public FilterIndexReader(IndexReader in_Renamed):base()
176  {
177  this.in_Renamed = in_Renamed;
178  }
179 
180  public override Directory Directory()
181  {
182  return in_Renamed.Directory();
183  }
184 
185  public override ITermFreqVector[] GetTermFreqVectors(int docNumber)
186  {
187  EnsureOpen();
188  return in_Renamed.GetTermFreqVectors(docNumber);
189  }
190 
191  public override ITermFreqVector GetTermFreqVector(int docNumber, System.String field)
192  {
193  EnsureOpen();
194  return in_Renamed.GetTermFreqVector(docNumber, field);
195  }
196 
197 
198  public override void GetTermFreqVector(int docNumber, System.String field, TermVectorMapper mapper)
199  {
200  EnsureOpen();
201  in_Renamed.GetTermFreqVector(docNumber, field, mapper);
202  }
203 
204  public override void GetTermFreqVector(int docNumber, TermVectorMapper mapper)
205  {
206  EnsureOpen();
207  in_Renamed.GetTermFreqVector(docNumber, mapper);
208  }
209 
210  public override int NumDocs()
211  {
212  // Don't call ensureOpen() here (it could affect performance)
213  return in_Renamed.NumDocs();
214  }
215 
216  public override int MaxDoc
217  {
218  get
219  {
220  // Don't call ensureOpen() here (it could affect performance)
221  return in_Renamed.MaxDoc;
222  }
223  }
224 
225  public override Document Document(int n, FieldSelector fieldSelector)
226  {
227  EnsureOpen();
228  return in_Renamed.Document(n, fieldSelector);
229  }
230 
231  public override bool IsDeleted(int n)
232  {
233  // Don't call ensureOpen() here (it could affect performance)
234  return in_Renamed.IsDeleted(n);
235  }
236 
237  public override bool HasDeletions
238  {
239  get
240  {
241  // Don't call ensureOpen() here (it could affect performance)
242  return in_Renamed.HasDeletions;
243  }
244  }
245 
246  protected internal override void DoUndeleteAll()
247  {
248  in_Renamed.UndeleteAll();
249  }
250 
251  public override bool HasNorms(System.String field)
252  {
253  EnsureOpen();
254  return in_Renamed.HasNorms(field);
255  }
256 
257  public override byte[] Norms(System.String f)
258  {
259  EnsureOpen();
260  return in_Renamed.Norms(f);
261  }
262 
263  public override void Norms(System.String f, byte[] bytes, int offset)
264  {
265  EnsureOpen();
266  in_Renamed.Norms(f, bytes, offset);
267  }
268 
269  protected internal override void DoSetNorm(int d, System.String f, byte b)
270  {
271  in_Renamed.SetNorm(d, f, b);
272  }
273 
274  public override TermEnum Terms()
275  {
276  EnsureOpen();
277  return in_Renamed.Terms();
278  }
279 
280  public override TermEnum Terms(Term t)
281  {
282  EnsureOpen();
283  return in_Renamed.Terms(t);
284  }
285 
286  public override int DocFreq(Term t)
287  {
288  EnsureOpen();
289  return in_Renamed.DocFreq(t);
290  }
291 
292  public override TermDocs TermDocs()
293  {
294  EnsureOpen();
295  return in_Renamed.TermDocs();
296  }
297 
298  public override TermDocs TermDocs(Term term)
299  {
300  EnsureOpen();
301  return in_Renamed.TermDocs(term);
302  }
303 
304  public override TermPositions TermPositions()
305  {
306  EnsureOpen();
307  return in_Renamed.TermPositions();
308  }
309 
310  protected internal override void DoDelete(int n)
311  {
312  in_Renamed.DeleteDocument(n);
313  }
314 
315  protected internal override void DoCommit(System.Collections.Generic.IDictionary<string, string> commitUserData)
316  {
317  in_Renamed.Commit(commitUserData);
318  }
319 
320  protected internal override void DoClose()
321  {
322  in_Renamed.Close();
323  // NOTE: only needed in case someone had asked for
324  // FieldCache for top-level reader (which is generally
325  // not a good idea):
326  Lucene.Net.Search.FieldCache_Fields.DEFAULT.Purge(this);
327  }
328 
329 
330  public override System.Collections.Generic.ICollection<string> GetFieldNames(IndexReader.FieldOption fieldNames)
331  {
332  EnsureOpen();
333  return in_Renamed.GetFieldNames(fieldNames);
334  }
335 
336  public override long Version
337  {
338  get
339  {
340  EnsureOpen();
341  return in_Renamed.Version;
342  }
343  }
344 
345  public override bool IsCurrent()
346  {
347  EnsureOpen();
348  return in_Renamed.IsCurrent();
349  }
350 
351  public override bool IsOptimized()
352  {
353  EnsureOpen();
354  return in_Renamed.IsOptimized();
355  }
356 
357  public override IndexReader[] GetSequentialSubReaders()
358  {
359  return in_Renamed.GetSequentialSubReaders();
360  }
361 
362  override public System.Object Clone()
363  {
364  System.Diagnostics.Debug.Fail("Port issue:", "Lets see if we need this FilterIndexReader.Clone()"); // {{Aroush-2.9}}
365  return null;
366  }
367 
368  /// <summary>
369  /// If the subclass of FilteredIndexReader modifies the
370  /// contents of the FieldCache, you must override this
371  /// method to provide a different key */
372  ///</summary>
373  public override object FieldCacheKey
374  {
375  get { return in_Renamed.FieldCacheKey; }
376  }
377 
378  /// <summary>
379  /// If the subclass of FilteredIndexReader modifies the
380  /// deleted docs, you must override this method to provide
381  /// a different key */
382  /// </summary>
383  public override object DeletesCacheKey
384  {
385  get { return in_Renamed.DeletesCacheKey; }
386  }
387  }
388 }