package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.lucene.util.UnicodeUtil; import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.ArrayList; import java.util.List; final class FreqProxTermsWriter extends TermsHashConsumer { @Override public TermsHashConsumerPerThread addThread(TermsHashPerThread perThread) { return new FreqProxTermsWriterPerThread(perThread); } @Override void createPostings(RawPostingList[] postings, int start, int count) { final int end = start + count; for(int i=start;i> threadsAndFields, final SegmentWriteState state) throws IOException { // Gather all FieldData's that have postings, across all // ThreadStates List allFields = new ArrayList(); for (Map.Entry> entry : threadsAndFields.entrySet()) { Collection fields = entry.getValue(); for (final TermsHashConsumerPerField i : fields) { final FreqProxTermsWriterPerField perField = (FreqProxTermsWriterPerField) i; if (perField.termsHashPerField.numPostings > 0) allFields.add(perField); } } // Sort by field name Collections.sort(allFields); final int numAllFields = allFields.size(); // TODO: allow Lucene user to customize this consumer: final FormatPostingsFieldsConsumer consumer = new FormatPostingsFieldsWriter(state, fieldInfos); /* Current writer chain: FormatPostingsFieldsConsumer -> IMPL: FormatPostingsFieldsWriter -> FormatPostingsTermsConsumer -> IMPL: FormatPostingsTermsWriter -> FormatPostingsDocConsumer -> IMPL: FormatPostingsDocWriter -> FormatPostingsPositionsConsumer -> IMPL: FormatPostingsPositionsWriter */ int start = 0; while(start < numAllFields) { final FieldInfo fieldInfo = allFields.get(start).fieldInfo; final String fieldName = fieldInfo.name; int end = start+1; while(end < numAllFields && allFields.get(end).fieldInfo.name.equals(fieldName)) end++; FreqProxTermsWriterPerField[] fields = new FreqProxTermsWriterPerField[end-start]; for(int i=start;i> entry : threadsAndFields.entrySet()) { FreqProxTermsWriterPerThread perThread = (FreqProxTermsWriterPerThread) entry.getKey(); perThread.termsHashPerThread.reset(true); } consumer.finish(); } private byte[] payloadBuffer; /* Walk through all unique text tokens (Posting * instances) found in this field and serialize them * into a single RAM segment. */ void appendPostings(FreqProxTermsWriterPerField[] fields, FormatPostingsFieldsConsumer consumer) throws CorruptIndexException, IOException { int numFields = fields.length; final FreqProxFieldMergeState[] mergeStates = new FreqProxFieldMergeState[numFields]; for(int i=0;i 0) { // Get the next term to merge termStates[0] = mergeStates[0]; int numToMerge = 1; for(int i=1;i 0) { FreqProxFieldMergeState minState = termStates[0]; for(int i=1;i> 1; final int payloadLength; if ((code & 1) != 0) { // This position has a payload payloadLength = prox.readVInt(); if (payloadBuffer == null || payloadBuffer.length < payloadLength) payloadBuffer = new byte[payloadLength]; prox.readBytes(payloadBuffer, 0, payloadLength); } else payloadLength = 0; posConsumer.addPosition(position, payloadBuffer, 0, payloadLength); } //End for posConsumer.finish(); } if (!minState.nextDoc()) { // Remove from termStates int upto = 0; for(int i=0;i