/// <summary> /// Returns a <see cref="NumericDocValues"/> for a reader's docvalues (potentially merging on-the-fly) /// <para> /// This is a slow way to access numeric values. Instead, access them per-segment /// with <see cref="AtomicReader.GetNumericDocValues(string)"/> /// </para> /// </summary> public static NumericDocValues GetNumericValues(IndexReader r, string field) { IList <AtomicReaderContext> leaves = r.Leaves; int size = leaves.Count; if (size == 0) { return(null); } else if (size == 1) { return(leaves[0].AtomicReader.GetNumericDocValues(field)); } bool anyReal = false; NumericDocValues[] values = new NumericDocValues[size]; int[] starts = new int[size + 1]; for (int i = 0; i < size; i++) { AtomicReaderContext context = leaves[i]; NumericDocValues v = context.AtomicReader.GetNumericDocValues(field); if (v == null) { v = DocValues.EMPTY_NUMERIC; } else { anyReal = true; } values[i] = v; starts[i] = context.DocBase; } starts[size] = r.MaxDoc; if (!anyReal) { return(null); } else { return(new NumericDocValuesAnonymousClass2(values, starts)); } }
private void MergeNorms(SegmentWriteState segmentWriteState) { DocValuesConsumer consumer = codec.NormsFormat.NormsConsumer(segmentWriteState); bool success = false; try { foreach (FieldInfo field in mergeState.FieldInfos) { if (field.HasNorms) { IList <NumericDocValues> toMerge = new List <NumericDocValues>(); IList <IBits> docsWithField = new List <IBits>(); foreach (AtomicReader reader in mergeState.Readers) { NumericDocValues norms = reader.GetNormValues(field.Name); if (norms == null) { norms = DocValues.EMPTY_NUMERIC; } toMerge.Add(norms); docsWithField.Add(new Lucene.Net.Util.Bits.MatchAllBits(reader.MaxDoc)); } consumer.MergeNumericField(field, mergeState, toMerge, docsWithField); } } success = true; } finally { if (success) { IOUtils.Dispose(consumer); } else { IOUtils.DisposeWhileHandlingException(consumer); } } }
private void MergeDocValues(SegmentWriteState segmentWriteState) { DocValuesConsumer consumer = codec.DocValuesFormat.FieldsConsumer(segmentWriteState); bool success = false; try { foreach (FieldInfo field in mergeState.FieldInfos) { DocValuesType type = field.DocValuesType; if (type != DocValuesType.NONE) { if (type == DocValuesType.NUMERIC) { IList <NumericDocValues> toMerge = new List <NumericDocValues>(); IList <IBits> docsWithField = new List <IBits>(); foreach (AtomicReader reader in mergeState.Readers) { NumericDocValues values = reader.GetNumericDocValues(field.Name); IBits bits = reader.GetDocsWithField(field.Name); if (values == null) { values = DocValues.EMPTY_NUMERIC; bits = new Lucene.Net.Util.Bits.MatchNoBits(reader.MaxDoc); } toMerge.Add(values); docsWithField.Add(bits); } consumer.MergeNumericField(field, mergeState, toMerge, docsWithField); } else if (type == DocValuesType.BINARY) { IList <BinaryDocValues> toMerge = new List <BinaryDocValues>(); IList <IBits> docsWithField = new List <IBits>(); foreach (AtomicReader reader in mergeState.Readers) { BinaryDocValues values = reader.GetBinaryDocValues(field.Name); IBits bits = reader.GetDocsWithField(field.Name); if (values == null) { values = DocValues.EMPTY_BINARY; bits = new Lucene.Net.Util.Bits.MatchNoBits(reader.MaxDoc); } toMerge.Add(values); docsWithField.Add(bits); } consumer.MergeBinaryField(field, mergeState, toMerge, docsWithField); } else if (type == DocValuesType.SORTED) { IList <SortedDocValues> toMerge = new List <SortedDocValues>(); foreach (AtomicReader reader in mergeState.Readers) { SortedDocValues values = reader.GetSortedDocValues(field.Name); if (values == null) { values = DocValues.EMPTY_SORTED; } toMerge.Add(values); } consumer.MergeSortedField(field, mergeState, toMerge); } else if (type == DocValuesType.SORTED_SET) { IList <SortedSetDocValues> toMerge = new List <SortedSetDocValues>(); foreach (AtomicReader reader in mergeState.Readers) { SortedSetDocValues values = reader.GetSortedSetDocValues(field.Name); if (values == null) { values = DocValues.EMPTY_SORTED_SET; } toMerge.Add(values); } consumer.MergeSortedSetField(field, mergeState, toMerge); } else { throw new InvalidOperationException("type=" + type); } } } success = true; } finally { if (success) { IOUtils.Dispose(consumer); } else { IOUtils.DisposeWhileHandlingException(consumer); } } }