X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/index/NormsWriter.java?ds=sidebyside diff --git a/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/index/NormsWriter.java b/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/index/NormsWriter.java deleted file mode 100644 index fcdd8d8..0000000 --- a/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/index/NormsWriter.java +++ /dev/null @@ -1,178 +0,0 @@ -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 java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.HashMap; -import java.util.Map; -import java.util.List; -import java.util.ArrayList; - -import org.apache.lucene.store.IndexOutput; -import org.apache.lucene.search.Similarity; -import org.apache.lucene.util.IOUtils; - -// TODO FI: norms could actually be stored as doc store - -/** Writes norms. Each thread X field accumulates the norms - * for the doc/fields it saw, then the flush method below - * merges all of these together into a single _X.nrm file. - */ - -final class NormsWriter extends InvertedDocEndConsumer { - - private final byte defaultNorm = Similarity.getDefault().encodeNormValue(1.0f); - private FieldInfos fieldInfos; - @Override - public InvertedDocEndConsumerPerThread addThread(DocInverterPerThread docInverterPerThread) { - return new NormsWriterPerThread(docInverterPerThread, this); - } - - @Override - public void abort() {} - - // We only write the _X.nrm file at flush - void files(Collection files) {} - - @Override - void setFieldInfos(FieldInfos fieldInfos) { - this.fieldInfos = fieldInfos; - } - - /** Produce _X.nrm if any document had a field with norms - * not disabled */ - @Override - public void flush(Map> threadsAndFields, SegmentWriteState state) throws IOException { - - final Map> byField = new HashMap>(); - - // Typically, each thread will have encountered the same - // field. So first we collate by field, ie, all - // per-thread field instances that correspond to the - // same FieldInfo - for (final Map.Entry> entry : threadsAndFields.entrySet()) { - final Collection fields = entry.getValue(); - final Iterator fieldsIt = fields.iterator(); - - while (fieldsIt.hasNext()) { - final NormsWriterPerField perField = (NormsWriterPerField) fieldsIt.next(); - - if (perField.upto > 0) { - // It has some norms - List l = byField.get(perField.fieldInfo); - if (l == null) { - l = new ArrayList(); - byField.put(perField.fieldInfo, l); - } - l.add(perField); - } else - // Remove this field since we haven't seen it - // since the previous flush - fieldsIt.remove(); - } - } - - final String normsFileName = IndexFileNames.segmentFileName(state.segmentName, IndexFileNames.NORMS_EXTENSION); - IndexOutput normsOut = state.directory.createOutput(normsFileName); - boolean success = false; - try { - normsOut.writeBytes(SegmentNorms.NORMS_HEADER, 0, SegmentNorms.NORMS_HEADER.length); - - final int numField = fieldInfos.size(); - - int normCount = 0; - - for(int fieldNumber=0;fieldNumber toMerge = byField.get(fieldInfo); - int upto = 0; - if (toMerge != null) { - - final int numFields = toMerge.size(); - - normCount++; - - final NormsWriterPerField[] fields = new NormsWriterPerField[numFields]; - int[] uptos = new int[numFields]; - - for(int j=0;j 0) { - - assert uptos[0] < fields[0].docIDs.length : " uptos[0]=" + uptos[0] + " len=" + (fields[0].docIDs.length); - - int minLoc = 0; - int minDocID = fields[0].docIDs[uptos[0]]; - - for(int j=1;j