Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Index / FieldsReader.cs
blobd3b338d2569a6a8f2624d0f39f4979547cdfa803
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
16 using System;
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.
25 ///
26 /// It uses &lt;segment&gt;.fdt and &lt;segment&gt;.fdx; files.
27 ///
28 /// </summary>
29 /// <version> $Id: FieldsReader.cs,v 1.2 2005/01/17 19:54:29 joeshaw Exp $
30 /// </version>
31 sealed public class FieldsReader
33 private FieldInfos fieldInfos;
34 private InputStream fieldsStream;
35 private InputStream indexStream;
36 private int size;
38 public /*internal*/ FieldsReader(Directory d, System.String segment, FieldInfos fn)
40 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()
50 fieldsStream.Close();
51 indexStream.Close();
54 public /*internal*/ int Size()
56 return 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
77 return doc;