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
DocFieldProcessor.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 using System.Collections;
20 using System.Collections.Generic;
21 using Lucene.Net.Support;
22 
23 namespace Lucene.Net.Index
24 {
25 
26  /// <summary> This is a DocConsumer that gathers all fields under the
27  /// same name, and calls per-field consumers to process field
28  /// by field. This class doesn't doesn't do any "real" work
29  /// of its own: it just forwards the fields to a
30  /// DocFieldConsumer.
31  /// </summary>
32 
34  {
35 
36  internal DocumentsWriter docWriter;
37  internal FieldInfos fieldInfos = new FieldInfos();
38  internal DocFieldConsumer consumer;
39  internal StoredFieldsWriter fieldsWriter;
40 
42  {
43  this.docWriter = docWriter;
44  this.consumer = consumer;
45  consumer.SetFieldInfos(fieldInfos);
46  fieldsWriter = new StoredFieldsWriter(docWriter, fieldInfos);
47  }
48 
49  public override void CloseDocStore(SegmentWriteState state)
50  {
51  consumer.CloseDocStore(state);
52  fieldsWriter.CloseDocStore(state);
53  }
54 
55  public override void Flush(ICollection<DocConsumerPerThread> threads, SegmentWriteState state)
56  {
57  var childThreadsAndFields = new HashMap<DocFieldConsumerPerThread, ICollection<DocFieldConsumerPerField>>();
58  foreach(DocConsumerPerThread thread in threads)
59  {
61  childThreadsAndFields[perThread.consumer] = perThread.Fields();
62  perThread.TrimFields(state);
63  }
64  fieldsWriter.Flush(state);
65  consumer.Flush(childThreadsAndFields, state);
66 
67  // Important to save after asking consumer to flush so
68  // consumer can alter the FieldInfo* if necessary. EG,
69  // FreqProxTermsWriter does this with
70  // FieldInfo.storePayload.
71  System.String fileName = state.SegmentFileName(IndexFileNames.FIELD_INFOS_EXTENSION);
72  fieldInfos.Write(state.directory, fileName);
73  state.flushedFiles.Add(fileName);
74  }
75 
76  public override void Abort()
77  {
78  fieldsWriter.Abort();
79  consumer.Abort();
80  }
81 
82  public override bool FreeRAM()
83  {
84  return consumer.FreeRAM();
85  }
86 
87  public override DocConsumerPerThread AddThread(DocumentsWriterThreadState threadState)
88  {
89  return new DocFieldProcessorPerThread(threadState, this);
90  }
91  }
92 }