2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using Document
= Lucene
.Net
.Documents
.Document
;
18 using Field
= Lucene
.Net
.Documents
.Field
;
19 using Directory
= Lucene
.Net
.Store
.Directory
;
20 using InputStream
= Lucene
.Net
.Store
.InputStream
;
21 namespace Lucene
.Net
.Index
24 /// <summary> Class responsible for access to stored document fields.
26 /// It uses <segment>.fdt and <segment>.fdx; files.
29 /// <version> $Id: FieldsReader.cs,v 1.2 2005/01/17 19:54:29 joeshaw Exp $
31 sealed public class FieldsReader
33 private FieldInfos fieldInfos
;
34 private InputStream fieldsStream
;
35 private InputStream indexStream
;
38 public /*internal*/ FieldsReader(Directory d
, System
.String segment
, FieldInfos fn
)
42 fieldsStream
= d
.OpenFile(segment
+ ".fdt");
43 indexStream
= d
.OpenFile(segment
+ ".fdx");
45 size
= (int) (indexStream
.Length() / 8);
48 public /*internal*/ void Close()
54 public /*internal*/ int Size()
59 public /*internal*/ Document
Doc(int n
)
61 indexStream
.Seek(n
* 8L);
62 long position
= indexStream
.ReadLong();
63 fieldsStream
.Seek(position
);
65 Document doc
= new Document();
66 int numFields
= fieldsStream
.ReadVInt();
67 for (int i
= 0; i
< numFields
; i
++)
69 int fieldNumber
= fieldsStream
.ReadVInt();
70 FieldInfo fi
= fieldInfos
.FieldInfo(fieldNumber
);
72 byte bits
= fieldsStream
.ReadByte();
74 doc
.Add(new Field(fi
.name
, fieldsStream
.ReadString(), true, fi
.isIndexed
, (bits
& 1) != 0, fi
.storeTermVector
)); // vector