19 using System.Collections.Generic;
20 using Lucene.Net.Support;
24 namespace Lucene.Net.Index
37 private static readonly byte defaultNorm;
44 public override void Abort()
49 internal void Files(ICollection<string> files)
53 internal override void SetFieldInfos(FieldInfos fieldInfos)
55 this.fieldInfos = fieldInfos;
64 IDictionary<FieldInfo, IList<NormsWriterPerField>> byField =
new HashMap<FieldInfo, IList<NormsWriterPerField>>();
70 foreach(var entry
in threadsAndFields)
72 ICollection<InvertedDocEndConsumerPerField> fields = entry.Value;
73 IEnumerator<InvertedDocEndConsumerPerField> fieldsIt = fields.GetEnumerator();
74 var fieldsToRemove =
new HashSet<NormsWriterPerField>();
75 while (fieldsIt.MoveNext())
79 if (perField.upto > 0)
82 IList<NormsWriterPerField> l = byField[perField.fieldInfo];
85 l =
new List<NormsWriterPerField>();
86 byField[perField.fieldInfo] = l;
94 fieldsToRemove.Add(perField);
97 foreach (var field
in fieldsToRemove)
104 state.flushedFiles.Add(normsFileName);
105 IndexOutput normsOut = state.directory.CreateOutput(normsFileName);
111 int numField = fieldInfos.Size();
115 for (
int fieldNumber = 0; fieldNumber < numField; fieldNumber++)
118 FieldInfo fieldInfo = fieldInfos.FieldInfo(fieldNumber);
120 IList<NormsWriterPerField> toMerge = byField[fieldInfo];
125 int numFields = toMerge.Count;
130 int[] uptos =
new int[numFields];
132 for (
int j = 0; j < numFields; j++)
133 fields[j] = toMerge[j];
135 int numLeft = numFields;
140 System.Diagnostics.Debug.Assert(uptos [0] < fields [0].docIDs.Length,
" uptos[0]=" + uptos [0] +
" len=" +(fields [0].docIDs.Length));
143 int minDocID = fields[0].docIDs[uptos[0]];
145 for (
int j = 1; j < numLeft; j++)
147 int docID = fields[j].docIDs[uptos[j]];
148 if (docID < minDocID)
155 System.Diagnostics.Debug.Assert(minDocID < state.numDocs);
158 for (; upto < minDocID; upto++)
159 normsOut.WriteByte(defaultNorm);
161 normsOut.WriteByte(fields[minLoc].norms[uptos[minLoc]]);
165 if (uptos[minLoc] == fields[minLoc].upto)
167 fields[minLoc].
Reset();
168 if (minLoc != numLeft - 1)
170 fields[minLoc] = fields[numLeft - 1];
171 uptos[minLoc] = uptos[numLeft - 1];
178 for (; upto < state.numDocs; upto++)
179 normsOut.WriteByte(defaultNorm);
181 else if (fieldInfo.isIndexed && !fieldInfo.omitNorms)
185 for (; upto < state.numDocs; upto++)
186 normsOut.WriteByte(defaultNorm);
189 System.Diagnostics.Debug.Assert(4 + normCount * state.numDocs == normsOut.FilePointer,
".nrm file size mismatch: expected=" +(4 + normCount * state.numDocs) +
" actual=" + normsOut.FilePointer);