1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
21 import java.util.Collection;
23 import java.util.HashMap;
27 * This is a DocConsumer that gathers all fields under the
28 * same name, and calls per-field consumers to process field
29 * by field. This class doesn't doesn't do any "real" work
30 * of its own: it just forwards the fields to a
34 final class DocFieldProcessor extends DocConsumer {
36 final DocumentsWriter docWriter;
37 final FieldInfos fieldInfos;
38 final DocFieldConsumer consumer;
39 final StoredFieldsWriter fieldsWriter;
41 public DocFieldProcessor(DocumentsWriter docWriter, DocFieldConsumer consumer) {
42 this.docWriter = docWriter;
43 this.consumer = consumer;
44 fieldInfos = docWriter.getFieldInfos();
45 consumer.setFieldInfos(fieldInfos);
46 fieldsWriter = new StoredFieldsWriter(docWriter, fieldInfos);
50 public void flush(Collection<DocConsumerPerThread> threads, SegmentWriteState state) throws IOException {
52 Map<DocFieldConsumerPerThread, Collection<DocFieldConsumerPerField>> childThreadsAndFields = new HashMap<DocFieldConsumerPerThread, Collection<DocFieldConsumerPerField>>();
53 for ( DocConsumerPerThread thread : threads) {
54 DocFieldProcessorPerThread perThread = (DocFieldProcessorPerThread) thread;
55 childThreadsAndFields.put(perThread.consumer, perThread.fields());
56 perThread.trimFields(state);
59 fieldsWriter.flush(state);
60 consumer.flush(childThreadsAndFields, state);
62 // Important to save after asking consumer to flush so
63 // consumer can alter the FieldInfo* if necessary. EG,
64 // FreqProxTermsWriter does this with
65 // FieldInfo.storePayload.
66 final String fileName = IndexFileNames.segmentFileName(state.segmentName, IndexFileNames.FIELD_INFOS_EXTENSION);
67 fieldInfos.write(state.directory, fileName);
80 public boolean freeRAM() {
81 return consumer.freeRAM();
85 public DocConsumerPerThread addThread(DocumentsWriterThreadState threadState) throws IOException {
86 return new DocFieldProcessorPerThread(threadState, this);