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;
22 import java.util.HashMap;
23 import java.util.HashSet;
28 /** This is a DocFieldConsumer that inverts each field,
29 * separately, from a Document, and accepts a
30 * InvertedTermsConsumer to process those terms. */
32 final class DocInverter extends DocFieldConsumer {
34 final InvertedDocConsumer consumer;
35 final InvertedDocEndConsumer endConsumer;
37 public DocInverter(InvertedDocConsumer consumer, InvertedDocEndConsumer endConsumer) {
38 this.consumer = consumer;
39 this.endConsumer = endConsumer;
43 void setFieldInfos(FieldInfos fieldInfos) {
44 super.setFieldInfos(fieldInfos);
45 consumer.setFieldInfos(fieldInfos);
46 endConsumer.setFieldInfos(fieldInfos);
50 void flush(Map<DocFieldConsumerPerThread, Collection<DocFieldConsumerPerField>> threadsAndFields, SegmentWriteState state) throws IOException {
52 Map<InvertedDocConsumerPerThread,Collection<InvertedDocConsumerPerField>> childThreadsAndFields = new HashMap<InvertedDocConsumerPerThread,Collection<InvertedDocConsumerPerField>>();
53 Map<InvertedDocEndConsumerPerThread,Collection<InvertedDocEndConsumerPerField>> endChildThreadsAndFields = new HashMap<InvertedDocEndConsumerPerThread,Collection<InvertedDocEndConsumerPerField>>();
55 for (Map.Entry<DocFieldConsumerPerThread,Collection<DocFieldConsumerPerField>> entry : threadsAndFields.entrySet() ) {
56 DocInverterPerThread perThread = (DocInverterPerThread) entry.getKey();
58 Collection<InvertedDocConsumerPerField> childFields = new HashSet<InvertedDocConsumerPerField>();
59 Collection<InvertedDocEndConsumerPerField> endChildFields = new HashSet<InvertedDocEndConsumerPerField>();
60 for (final DocFieldConsumerPerField field: entry.getValue() ) {
61 DocInverterPerField perField = (DocInverterPerField) field;
62 childFields.add(perField.consumer);
63 endChildFields.add(perField.endConsumer);
66 childThreadsAndFields.put(perThread.consumer, childFields);
67 endChildThreadsAndFields.put(perThread.endConsumer, endChildFields);
70 consumer.flush(childThreadsAndFields, state);
71 endConsumer.flush(endChildThreadsAndFields, state);
84 public boolean freeRAM() {
85 return consumer.freeRAM();
89 public DocFieldConsumerPerThread addThread(DocFieldProcessorPerThread docFieldProcessorPerThread) {
90 return new DocInverterPerThread(docFieldProcessorPerThread, this);