You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/04/04 17:19:16 UTC
[10/62] [abbrv] [partial] lucenenet git commit: Renamed
Lucene.Net.Core folder Lucene.Net because the dotnet.exe pack command doesn't
allow creating a NuGet package with a different name than its folder. Working
around it with the script was much more co
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiDocValues.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiDocValues.cs b/src/Lucene.Net.Core/Index/MultiDocValues.cs
deleted file mode 100644
index f97a672..0000000
--- a/src/Lucene.Net.Core/Index/MultiDocValues.cs
+++ /dev/null
@@ -1,739 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Lucene.Net.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.
- */
-
- using AppendingPackedInt64Buffer = Lucene.Net.Util.Packed.AppendingPackedInt64Buffer;
- using IBits = Lucene.Net.Util.IBits;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using MonotonicAppendingInt64Buffer = Lucene.Net.Util.Packed.MonotonicAppendingInt64Buffer;
- using PackedInt32s = Lucene.Net.Util.Packed.PackedInt32s;
- using TermsEnumIndex = Lucene.Net.Index.MultiTermsEnum.TermsEnumIndex;
- using TermsEnumWithSlice = Lucene.Net.Index.MultiTermsEnum.TermsEnumWithSlice;
-
- /// <summary>
- /// A wrapper for CompositeIndexReader providing access to DocValues.
- ///
- /// <p><b>NOTE</b>: for multi readers, you'll get better
- /// performance by gathering the sub readers using
- /// <seealso cref="IndexReader#getContext()"/> to get the
- /// atomic leaves and then operate per-AtomicReader,
- /// instead of using this class.
- ///
- /// <p><b>NOTE</b>: this is very costly.
- ///
- /// @lucene.experimental
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class MultiDocValues
- {
- /// <summary>
- /// No instantiation </summary>
- private MultiDocValues()
- {
- }
-
- /// <summary>
- /// Returns a NumericDocValues for a reader's norms (potentially merging on-the-fly).
- /// <p>
- /// this is a slow way to access normalization values. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getNormValues(String)"/>
- /// </p>
- /// </summary>
- public static NumericDocValues GetNormValues(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.GetNormValues(field);
- }
- FieldInfo fi = MultiFields.GetMergedFieldInfos(r).FieldInfo(field);
- if (fi == null || fi.HasNorms == false)
- {
- return null;
- }
-
- 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.GetNormValues(field);
- if (v == null)
- {
- v = DocValues.EMPTY_NUMERIC;
- }
- else
- {
- anyReal = true;
- }
- values[i] = v;
- starts[i] = context.DocBase;
- }
- starts[size] = r.MaxDoc;
-
- Debug.Assert(anyReal);
-
- return new NumericDocValuesAnonymousInnerClassHelper(values, starts);
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
- {
- private NumericDocValues[] values;
- private int[] starts;
-
- public NumericDocValuesAnonymousInnerClassHelper(NumericDocValues[] values, int[] starts)
- {
- this.values = values;
- this.starts = starts;
- }
-
- public override long Get(int docID)
- {
- int subIndex = ReaderUtil.SubIndex(docID, starts);
- return values[subIndex].Get(docID - starts[subIndex]);
- }
- }
-
- /// <summary>
- /// Returns a NumericDocValues for a reader's docvalues (potentially merging on-the-fly)
- /// <p>
- /// this is a slow way to access numeric values. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getNumericDocValues(String)"/>
- /// </p>
- ///
- /// </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 NumericDocValuesAnonymousInnerClassHelper2(values, starts);
- }
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class NumericDocValuesAnonymousInnerClassHelper2 : NumericDocValues
- {
- private NumericDocValues[] values;
- private int[] starts;
-
- public NumericDocValuesAnonymousInnerClassHelper2(NumericDocValues[] values, int[] starts)
- {
- this.values = values;
- this.starts = starts;
- }
-
- public override long Get(int docID)
- {
- int subIndex = ReaderUtil.SubIndex(docID, starts);
- return values[subIndex].Get(docID - starts[subIndex]);
- }
- }
-
- /// <summary>
- /// Returns a Bits for a reader's docsWithField (potentially merging on-the-fly)
- /// <p>
- /// this is a slow way to access this bitset. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getDocsWithField(String)"/>
- /// </p>
- ///
- /// </summary>
- public static IBits GetDocsWithField(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.GetDocsWithField(field);
- }
-
- bool anyReal = false;
- bool anyMissing = false;
- IBits[] values = new IBits[size];
- int[] starts = new int[size + 1];
- for (int i = 0; i < size; i++)
- {
- AtomicReaderContext context = leaves[i];
- IBits v = context.AtomicReader.GetDocsWithField(field);
- if (v == null)
- {
- v = new Lucene.Net.Util.Bits.MatchNoBits(context.Reader.MaxDoc);
- anyMissing = true;
- }
- else
- {
- anyReal = true;
- if (v is Lucene.Net.Util.Bits.MatchAllBits == false)
- {
- anyMissing = true;
- }
- }
- values[i] = v;
- starts[i] = context.DocBase;
- }
- starts[size] = r.MaxDoc;
-
- if (!anyReal)
- {
- return null;
- }
- else if (!anyMissing)
- {
- return new Lucene.Net.Util.Bits.MatchAllBits(r.MaxDoc);
- }
- else
- {
- return new MultiBits(values, starts, false);
- }
- }
-
- /// <summary>
- /// Returns a BinaryDocValues for a reader's docvalues (potentially merging on-the-fly)
- /// <p>
- /// this is a slow way to access binary values. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getBinaryDocValues(String)"/>
- /// </p>
- /// </summary>
- public static BinaryDocValues GetBinaryValues(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.GetBinaryDocValues(field);
- }
-
- bool anyReal = false;
- BinaryDocValues[] values = new BinaryDocValues[size];
- int[] starts = new int[size + 1];
- for (int i = 0; i < size; i++)
- {
- AtomicReaderContext context = leaves[i];
- BinaryDocValues v = context.AtomicReader.GetBinaryDocValues(field);
- if (v == null)
- {
- v = DocValues.EMPTY_BINARY;
- }
- else
- {
- anyReal = true;
- }
- values[i] = v;
- starts[i] = context.DocBase;
- }
- starts[size] = r.MaxDoc;
-
- if (!anyReal)
- {
- return null;
- }
- else
- {
- return new BinaryDocValuesAnonymousInnerClassHelper(values, starts);
- }
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class BinaryDocValuesAnonymousInnerClassHelper : BinaryDocValues
- {
- private BinaryDocValues[] values;
- private int[] starts;
-
- public BinaryDocValuesAnonymousInnerClassHelper(BinaryDocValues[] values, int[] starts)
- {
- this.values = values;
- this.starts = starts;
- }
-
- public override void Get(int docID, BytesRef result)
- {
- int subIndex = ReaderUtil.SubIndex(docID, starts);
- values[subIndex].Get(docID - starts[subIndex], result);
- }
- }
-
- /// <summary>
- /// Returns a SortedDocValues for a reader's docvalues (potentially doing extremely slow things).
- /// <p>
- /// this is an extremely slow way to access sorted values. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getSortedDocValues(String)"/>
- /// </p>
- /// </summary>
- public static SortedDocValues GetSortedValues(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.GetSortedDocValues(field);
- }
-
- bool anyReal = false;
- var values = new SortedDocValues[size];
- int[] starts = new int[size + 1];
- for (int i = 0; i < size; i++)
- {
- AtomicReaderContext context = leaves[i];
- SortedDocValues v = context.AtomicReader.GetSortedDocValues(field);
- if (v == null)
- {
- v = DocValues.EMPTY_SORTED;
- }
- else
- {
- anyReal = true;
- }
- values[i] = v;
- starts[i] = context.DocBase;
- }
- starts[size] = r.MaxDoc;
-
- if (!anyReal)
- {
- return null;
- }
- else
- {
- TermsEnum[] enums = new TermsEnum[values.Length];
- for (int i = 0; i < values.Length; i++)
- {
- enums[i] = values[i].GetTermsEnum();
- }
- OrdinalMap mapping = new OrdinalMap(r.CoreCacheKey, enums);
- return new MultiSortedDocValues(values, starts, mapping);
- }
- }
-
- /// <summary>
- /// Returns a SortedSetDocValues for a reader's docvalues (potentially doing extremely slow things).
- /// <p>
- /// this is an extremely slow way to access sorted values. Instead, access them per-segment
- /// with <seealso cref="AtomicReader#getSortedSetDocValues(String)"/>
- /// </p>
- /// </summary>
- public static SortedSetDocValues GetSortedSetValues(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.GetSortedSetDocValues(field);
- }
-
- bool anyReal = false;
- SortedSetDocValues[] values = new SortedSetDocValues[size];
- int[] starts = new int[size + 1];
- for (int i = 0; i < size; i++)
- {
- AtomicReaderContext context = leaves[i];
- SortedSetDocValues v = context.AtomicReader.GetSortedSetDocValues(field);
- if (v == null)
- {
- v = DocValues.EMPTY_SORTED_SET;
- }
- else
- {
- anyReal = true;
- }
- values[i] = v;
- starts[i] = context.DocBase;
- }
- starts[size] = r.MaxDoc;
-
- if (!anyReal)
- {
- return null;
- }
- else
- {
- TermsEnum[] enums = new TermsEnum[values.Length];
- for (int i = 0; i < values.Length; i++)
- {
- enums[i] = values[i].GetTermsEnum();
- }
- OrdinalMap mapping = new OrdinalMap(r.CoreCacheKey, enums);
- return new MultiSortedSetDocValues(values, starts, mapping);
- }
- }
-
- /// <summary>
- /// maps per-segment ordinals to/from global ordinal space </summary>
- // TODO: use more efficient packed ints structures?
- // TODO: pull this out? its pretty generic (maps between N ord()-enabled TermsEnums)
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class OrdinalMap
- {
- // cache key of whoever asked for this awful thing
- internal readonly object owner;
-
- // globalOrd -> (globalOrd - segmentOrd) where segmentOrd is the the ordinal in the first segment that contains this term
- internal readonly MonotonicAppendingInt64Buffer globalOrdDeltas;
-
- // globalOrd -> first segment container
- internal readonly AppendingPackedInt64Buffer firstSegments;
-
- // for every segment, segmentOrd -> (globalOrd - segmentOrd)
- internal readonly MonotonicAppendingInt64Buffer[] ordDeltas;
-
- /// <summary>
- /// Creates an ordinal map that allows mapping ords to/from a merged
- /// space from <code>subs</code>. </summary>
- /// <param name="owner"> a cache key </param>
- /// <param name="subs"> TermsEnums that support <seealso cref="TermsEnum#ord()"/>. They need
- /// not be dense (e.g. can be FilteredTermsEnums}. </param>
- /// <exception cref="IOException"> if an I/O error occurred. </exception>
- public OrdinalMap(object owner, TermsEnum[] subs)
- {
- // create the ordinal mappings by pulling a termsenum over each sub's
- // unique terms, and walking a multitermsenum over those
- this.owner = owner;
- globalOrdDeltas = new MonotonicAppendingInt64Buffer(PackedInt32s.COMPACT);
- firstSegments = new AppendingPackedInt64Buffer(PackedInt32s.COMPACT);
- ordDeltas = new MonotonicAppendingInt64Buffer[subs.Length];
- for (int i = 0; i < ordDeltas.Length; i++)
- {
- ordDeltas[i] = new MonotonicAppendingInt64Buffer();
- }
- long[] segmentOrds = new long[subs.Length];
- ReaderSlice[] slices = new ReaderSlice[subs.Length];
- TermsEnumIndex[] indexes = new TermsEnumIndex[slices.Length];
- for (int i = 0; i < slices.Length; i++)
- {
- slices[i] = new ReaderSlice(0, 0, i);
- indexes[i] = new TermsEnumIndex(subs[i], i);
- }
- MultiTermsEnum mte = new MultiTermsEnum(slices);
- mte.Reset(indexes);
- long globalOrd = 0;
- while (mte.Next() != null)
- {
- TermsEnumWithSlice[] matches = mte.MatchArray;
- for (int i = 0; i < mte.MatchCount; i++)
- {
- int segmentIndex = matches[i].Index;
- long segmentOrd = matches[i].Terms.Ord;
- long delta = globalOrd - segmentOrd;
- // for each unique term, just mark the first segment index/delta where it occurs
- if (i == 0)
- {
- firstSegments.Add(segmentIndex);
- globalOrdDeltas.Add(delta);
- }
- // for each per-segment ord, map it back to the global term.
- while (segmentOrds[segmentIndex] <= segmentOrd)
- {
- ordDeltas[segmentIndex].Add(delta);
- segmentOrds[segmentIndex]++;
- }
- }
- globalOrd++;
- }
- firstSegments.Freeze();
- globalOrdDeltas.Freeze();
- for (int i = 0; i < ordDeltas.Length; ++i)
- {
- ordDeltas[i].Freeze();
- }
- }
-
- /// <summary>
- /// Given a segment number and segment ordinal, returns
- /// the corresponding global ordinal.
- /// </summary>
- public virtual long GetGlobalOrd(int segmentIndex, long segmentOrd)
- {
- return segmentOrd + ordDeltas[segmentIndex].Get(segmentOrd);
- }
-
- /// <summary>
- /// Given global ordinal, returns the ordinal of the first segment which contains
- /// this ordinal (the corresponding to the segment return <seealso cref="#getFirstSegmentNumber"/>).
- /// </summary>
- public virtual long GetFirstSegmentOrd(long globalOrd)
- {
- return globalOrd - globalOrdDeltas.Get(globalOrd);
- }
-
- /// <summary>
- /// Given a global ordinal, returns the index of the first
- /// segment that contains this term.
- /// </summary>
- public virtual int GetFirstSegmentNumber(long globalOrd)
- {
- return (int)firstSegments.Get(globalOrd);
- }
-
- /// <summary>
- /// Returns the total number of unique terms in global ord space.
- /// </summary>
- public virtual long ValueCount
- {
- get
- {
- return globalOrdDeltas.Count;
- }
- }
-
- /// <summary>
- /// Returns total byte size used by this ordinal map.
- /// </summary>
- public virtual long RamBytesUsed()
- {
- long size = globalOrdDeltas.RamBytesUsed() + firstSegments.RamBytesUsed();
- for (int i = 0; i < ordDeltas.Length; i++)
- {
- size += ordDeltas[i].RamBytesUsed();
- }
- return size;
- }
- }
-
- /// <summary>
- /// Implements SortedDocValues over n subs, using an OrdinalMap
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class MultiSortedDocValues : SortedDocValues
- {
- /// <summary>
- /// docbase for each leaf: parallel with <seealso cref="#values"/> </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public int[] DocStarts
- {
- get { return docStarts; }
- }
- private readonly int[] docStarts;
-
- /// <summary>
- /// leaf values </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public SortedDocValues[] Values
- {
- get { return values; }
- }
- private readonly SortedDocValues[] values;
-
- /// <summary>
- /// ordinal map mapping ords from <code>values</code> to global ord space </summary>
- public OrdinalMap Mapping
- {
- get { return mapping; }
- }
- private readonly OrdinalMap mapping;
-
- /// <summary>
- /// Creates a new MultiSortedDocValues over <code>values</code> </summary>
- internal MultiSortedDocValues(SortedDocValues[] values, int[] docStarts, OrdinalMap mapping)
- {
- Debug.Assert(values.Length == mapping.ordDeltas.Length);
- Debug.Assert(docStarts.Length == values.Length + 1);
- this.values = values;
- this.docStarts = docStarts;
- this.mapping = mapping;
- }
-
- public override int GetOrd(int docID)
- {
- int subIndex = ReaderUtil.SubIndex(docID, docStarts);
- int segmentOrd = values[subIndex].GetOrd(docID - docStarts[subIndex]);
- return segmentOrd == -1 ? segmentOrd : (int)mapping.GetGlobalOrd(subIndex, segmentOrd);
- }
-
- public override void LookupOrd(int ord, BytesRef result)
- {
- int subIndex = mapping.GetFirstSegmentNumber(ord);
- int segmentOrd = (int)mapping.GetFirstSegmentOrd(ord);
- values[subIndex].LookupOrd(segmentOrd, result);
- }
-
- public override int ValueCount
- {
- get
- {
- return (int)mapping.ValueCount;
- }
- }
- }
-
- /// <summary>
- /// Implements MultiSortedSetDocValues over n subs, using an OrdinalMap
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class MultiSortedSetDocValues : SortedSetDocValues
- {
- /// <summary>
- /// docbase for each leaf: parallel with <seealso cref="#values"/> </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public int[] DocStarts
- {
- get { return docStarts; }
- }
- private readonly int[] docStarts;
-
- /// <summary>
- /// leaf values </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public SortedSetDocValues[] Values
- {
- get { return values; }
- }
- private readonly SortedSetDocValues[] values;
-
- /// <summary>
- /// ordinal map mapping ords from <code>values</code> to global ord space </summary>
- public OrdinalMap Mapping
- {
- get { return mapping; }
- }
- private readonly OrdinalMap mapping;
-
- internal int currentSubIndex;
-
- /// <summary>
- /// Creates a new MultiSortedSetDocValues over <code>values</code> </summary>
- internal MultiSortedSetDocValues(SortedSetDocValues[] values, int[] docStarts, OrdinalMap mapping)
- {
- Debug.Assert(values.Length == mapping.ordDeltas.Length);
- Debug.Assert(docStarts.Length == values.Length + 1);
- this.values = values;
- this.docStarts = docStarts;
- this.mapping = mapping;
- }
-
- public override long NextOrd()
- {
- long segmentOrd = values[currentSubIndex].NextOrd();
- if (segmentOrd == NO_MORE_ORDS)
- {
- return segmentOrd;
- }
- else
- {
- return mapping.GetGlobalOrd(currentSubIndex, segmentOrd);
- }
- }
-
- public override void SetDocument(int docID)
- {
- currentSubIndex = ReaderUtil.SubIndex(docID, docStarts);
- values[currentSubIndex].SetDocument(docID - docStarts[currentSubIndex]);
- }
-
- public override void LookupOrd(long ord, BytesRef result)
- {
- int subIndex = mapping.GetFirstSegmentNumber(ord);
- long segmentOrd = mapping.GetFirstSegmentOrd(ord);
- values[subIndex].LookupOrd(segmentOrd, result);
- }
-
- public override long ValueCount
- {
- get
- {
- return mapping.ValueCount;
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiDocsAndPositionsEnum.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiDocsAndPositionsEnum.cs b/src/Lucene.Net.Core/Index/MultiDocsAndPositionsEnum.cs
deleted file mode 100644
index bfab6d7..0000000
--- a/src/Lucene.Net.Core/Index/MultiDocsAndPositionsEnum.cs
+++ /dev/null
@@ -1,249 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Lucene.Net.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.
- */
-
- using BytesRef = Lucene.Net.Util.BytesRef;
-
- /// <summary>
- /// Exposes flex API, merged from flex API of sub-segments.
- ///
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class MultiDocsAndPositionsEnum : DocsAndPositionsEnum
- {
- private readonly MultiTermsEnum parent;
- internal readonly DocsAndPositionsEnum[] subDocsAndPositionsEnum;
- private EnumWithSlice[] subs;
- internal int numSubs;
- internal int upto;
- internal DocsAndPositionsEnum current;
- internal int currentBase;
- internal int doc = -1;
-
- /// <summary>
- /// Sole constructor. </summary>
- public MultiDocsAndPositionsEnum(MultiTermsEnum parent, int subReaderCount)
- {
- this.parent = parent;
- subDocsAndPositionsEnum = new DocsAndPositionsEnum[subReaderCount];
- }
-
- /// <summary>
- /// Returns {@code true} if this instance can be reused by
- /// the provided <seealso cref="MultiTermsEnum"/>.
- /// </summary>
- public bool CanReuse(MultiTermsEnum parent)
- {
- return this.parent == parent;
- }
-
- /// <summary>
- /// Rre-use and reset this instance on the provided slices. </summary>
- public MultiDocsAndPositionsEnum Reset(EnumWithSlice[] subs, int numSubs)
- {
- this.numSubs = numSubs;
- this.subs = new EnumWithSlice[subs.Length];
- for (int i = 0; i < subs.Length; i++)
- {
- this.subs[i] = new EnumWithSlice();
- this.subs[i].DocsAndPositionsEnum = subs[i].DocsAndPositionsEnum;
- this.subs[i].Slice = subs[i].Slice;
- }
- upto = -1;
- doc = -1;
- current = null;
- return this;
- }
-
- /// <summary>
- /// How many sub-readers we are merging. </summary>
- /// <seealso cref= #getSubs </seealso>
- public int NumSubs
- {
- get
- {
- return numSubs;
- }
- }
-
- /// <summary>
- /// Returns sub-readers we are merging. </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public EnumWithSlice[] Subs
- {
- get { return subs; }
- }
-
- public override int Freq
- {
- get
- {
- Debug.Assert(current != null);
- return current.Freq;
- }
- }
-
- public override int DocID
- {
- get { return doc; }
- }
-
- public override int Advance(int target)
- {
- Debug.Assert(target > doc);
- while (true)
- {
- if (current != null)
- {
- int doc;
- if (target < currentBase)
- {
- // target was in the previous slice but there was no matching doc after it
- doc = current.NextDoc();
- }
- else
- {
- doc = current.Advance(target - currentBase);
- }
- if (doc == NO_MORE_DOCS)
- {
- current = null;
- }
- else
- {
- return this.doc = doc + currentBase;
- }
- }
- else if (upto == numSubs - 1)
- {
- return this.doc = NO_MORE_DOCS;
- }
- else
- {
- upto++;
- current = subs[upto].DocsAndPositionsEnum;
- currentBase = subs[upto].Slice.Start;
- }
- }
- }
-
- public override int NextDoc()
- {
- while (true)
- {
- if (current == null)
- {
- if (upto == numSubs - 1)
- {
- return this.doc = NO_MORE_DOCS;
- }
- else
- {
- upto++;
- current = subs[upto].DocsAndPositionsEnum;
- currentBase = subs[upto].Slice.Start;
- }
- }
-
- int doc = current.NextDoc();
- if (doc != NO_MORE_DOCS)
- {
- return this.doc = currentBase + doc;
- }
- else
- {
- current = null;
- }
- }
- }
-
- public override int NextPosition()
- {
- return current.NextPosition();
- }
-
- public override int StartOffset
- {
- get { return current.StartOffset; }
- }
-
- public override int EndOffset
- {
- get { return current.EndOffset; }
- }
-
- public override BytesRef GetPayload()
- {
- return current.GetPayload();
- }
-
- // TODO: implement bulk read more efficiently than super
- /// <summary>
- /// Holds a <seealso cref="DocsAndPositionsEnum"/> along with the
- /// corresponding <seealso cref="ReaderSlice"/>.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class EnumWithSlice
- {
- internal EnumWithSlice()
- {
- }
-
- /// <summary>
- /// <seealso cref="DocsAndPositionsEnum"/> for this sub-reader. </summary>
- public DocsAndPositionsEnum DocsAndPositionsEnum { get; internal set; } // LUCENENET NOTE: Made setter internal because ctor is internal
-
- /// <summary>
- /// <seealso cref="ReaderSlice"/> describing how this sub-reader
- /// fits into the composite reader.
- /// </summary>
- public ReaderSlice Slice { get; internal set; } // LUCENENET NOTE: Made setter internal because ctor is internal
-
- public override string ToString()
- {
- return Slice.ToString() + ":" + DocsAndPositionsEnum;
- }
- }
-
- public override long GetCost()
- {
- long cost = 0;
- for (int i = 0; i < numSubs; i++)
- {
- cost += subs[i].DocsAndPositionsEnum.GetCost();
- }
- return cost;
- }
-
- public override string ToString()
- {
- return "MultiDocsAndPositionsEnum(" + Arrays.ToString(Subs) + ")";
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiDocsEnum.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiDocsEnum.cs b/src/Lucene.Net.Core/Index/MultiDocsEnum.cs
deleted file mode 100644
index 0e34a7c..0000000
--- a/src/Lucene.Net.Core/Index/MultiDocsEnum.cs
+++ /dev/null
@@ -1,225 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-
-namespace Lucene.Net.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.
- */
-
- /// <summary>
- /// Exposes <seealso cref="DocsEnum"/>, merged from <seealso cref="DocsEnum"/>
- /// API of sub-segments.
- ///
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class MultiDocsEnum : DocsEnum
- {
- private readonly MultiTermsEnum parent;
- internal readonly DocsEnum[] subDocsEnum;
- private EnumWithSlice[] subs;
- internal int numSubs;
- internal int upto;
- internal DocsEnum current;
- internal int currentBase;
- internal int doc = -1;
-
- /// <summary>
- /// Sole constructor </summary>
- /// <param name="parent"> The <seealso cref="MultiTermsEnum"/> that created us. </param>
- /// <param name="subReaderCount"> How many sub-readers are being merged. </param>
- public MultiDocsEnum(MultiTermsEnum parent, int subReaderCount)
- {
- this.parent = parent;
- subDocsEnum = new DocsEnum[subReaderCount];
- }
-
- internal MultiDocsEnum Reset(EnumWithSlice[] subs, int numSubs)
- {
- this.numSubs = numSubs;
-
- this.subs = new EnumWithSlice[subs.Length];
- for (int i = 0; i < subs.Length; i++)
- {
- this.subs[i] = new EnumWithSlice();
- this.subs[i].DocsEnum = subs[i].DocsEnum;
- this.subs[i].Slice = subs[i].Slice;
- }
- upto = -1;
- doc = -1;
- current = null;
- return this;
- }
-
- /// <summary>
- /// Returns {@code true} if this instance can be reused by
- /// the provided <seealso cref="MultiTermsEnum"/>.
- /// </summary>
- public bool CanReuse(MultiTermsEnum parent)
- {
- return this.parent == parent;
- }
-
- /// <summary>
- /// How many sub-readers we are merging. </summary>
- /// <seealso cref= #getSubs </seealso>
- public int NumSubs
- {
- get
- {
- return numSubs;
- }
- }
-
- /// <summary>
- /// Returns sub-readers we are merging. </summary>
- [WritableArray]
- [SuppressMessage("Microsoft.Performance", "CA1819", Justification = "Lucene's design requires some writable array properties")]
- public EnumWithSlice[] Subs
- {
- get { return subs; }
- }
-
- public override int Freq
- {
- get { return current.Freq; }
- }
-
- public override int DocID
- {
- get { return doc; }
- }
-
- public override int Advance(int target)
- {
- Debug.Assert(target > doc);
- while (true)
- {
- if (current != null)
- {
- int doc;
- if (target < currentBase)
- {
- // target was in the previous slice but there was no matching doc after it
- doc = current.NextDoc();
- }
- else
- {
- doc = current.Advance(target - currentBase);
- }
- if (doc == NO_MORE_DOCS)
- {
- current = null;
- }
- else
- {
- return this.doc = doc + currentBase;
- }
- }
- else if (upto == numSubs - 1)
- {
- return this.doc = NO_MORE_DOCS;
- }
- else
- {
- upto++;
- current = subs[upto].DocsEnum;
- currentBase = subs[upto].Slice.Start;
- }
- }
- }
-
- public override int NextDoc()
- {
- while (true)
- {
- if (current == null)
- {
- if (upto == numSubs - 1)
- {
- return this.doc = NO_MORE_DOCS;
- }
- else
- {
- upto++;
- current = subs[upto].DocsEnum;
- currentBase = subs[upto].Slice.Start;
- }
- }
-
- int doc = current.NextDoc();
- if (doc != NO_MORE_DOCS)
- {
- return this.doc = currentBase + doc;
- }
- else
- {
- current = null;
- }
- }
- }
-
- public override long GetCost()
- {
- long cost = 0;
- for (int i = 0; i < numSubs; i++)
- {
- cost += subs[i].DocsEnum.GetCost();
- }
- return cost;
- }
-
- // TODO: implement bulk read more efficiently than super
- /// <summary>
- /// Holds a <seealso cref="DocsEnum"/> along with the
- /// corresponding <seealso cref="ReaderSlice"/>.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class EnumWithSlice
- {
- internal EnumWithSlice()
- {
- }
-
- /// <summary>
- /// <seealso cref="DocsEnum"/> of this sub-reader. </summary>
- public DocsEnum DocsEnum { get; internal set; } // LUCENENET NOTE: Made setter internal because ctor is internal
-
- /// <summary>
- /// <seealso cref="ReaderSlice"/> describing how this sub-reader
- /// fits into the composite reader.
- /// </summary>
- public ReaderSlice Slice { get; internal set; } // LUCENENET NOTE: Made setter internal because ctor is internal
-
- public override string ToString()
- {
- return Slice.ToString() + ":" + DocsEnum;
- }
- }
-
- public override string ToString()
- {
- return "MultiDocsEnum(" + Arrays.ToString(Subs) + ")";
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiFields.cs b/src/Lucene.Net.Core/Index/MultiFields.cs
deleted file mode 100644
index 045200b..0000000
--- a/src/Lucene.Net.Core/Index/MultiFields.cs
+++ /dev/null
@@ -1,334 +0,0 @@
-using Lucene.Net.Util;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-
-namespace Lucene.Net.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.
- */
-
- using IBits = Lucene.Net.Util.IBits;
- using BytesRef = Lucene.Net.Util.BytesRef;
-
- /// <summary>
- /// Exposes flex API, merged from flex API of sub-segments.
- /// this is useful when you're interacting with an {@link
- /// IndexReader} implementation that consists of sequential
- /// sub-readers (eg <seealso cref="DirectoryReader"/> or {@link
- /// MultiReader}).
- ///
- /// <p><b>NOTE</b>: for composite readers, you'll get better
- /// performance by gathering the sub readers using
- /// <seealso cref="IndexReader#getContext()"/> to get the
- /// atomic leaves and then operate per-AtomicReader,
- /// instead of using this class.
- ///
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class MultiFields : Fields
- {
- private readonly Fields[] subs;
- private readonly ReaderSlice[] subSlices;
- private readonly IDictionary<string, Terms> terms = new ConcurrentDictionary<string, Terms>();
-
- /// <summary>
- /// Returns a single <seealso cref="Fields"/> instance for this
- /// reader, merging fields/terms/docs/positions on the
- /// fly. this method will return null if the reader
- /// has no postings.
- ///
- /// <p><b>NOTE</b>: this is a slow way to access postings.
- /// It's better to get the sub-readers and iterate through them
- /// yourself.
- /// </summary>
- public static Fields GetFields(IndexReader reader)
- {
- var leaves = reader.Leaves;
- switch (leaves.Count)
- {
- case 0:
- // no fields
- return null;
-
- case 1:
- // already an atomic reader / reader with one leave
- return leaves[0].AtomicReader.Fields;
-
- default:
- IList<Fields> fields = new List<Fields>();
- IList<ReaderSlice> slices = new List<ReaderSlice>();
- foreach (AtomicReaderContext ctx in leaves)
- {
- AtomicReader r = ctx.AtomicReader;
- Fields f = r.Fields;
- if (f != null)
- {
- fields.Add(f);
- slices.Add(new ReaderSlice(ctx.DocBase, r.MaxDoc, fields.Count - 1));
- }
- }
- if (fields.Count == 0)
- {
- return null;
- }
- else if (fields.Count == 1)
- {
- return fields[0];
- }
- else
- {
- return new MultiFields(fields.ToArray(/*Fields.EMPTY_ARRAY*/), slices.ToArray(/*ReaderSlice.EMPTY_ARRAY*/));
- }
- }
- }
-
- /// <summary>
- /// Returns a single <seealso cref="IBits"/> instance for this
- /// reader, merging live Documents on the
- /// fly. this method will return null if the reader
- /// has no deletions.
- ///
- /// <p><b>NOTE</b>: this is a very slow way to access live docs.
- /// For example, each Bits access will require a binary search.
- /// It's better to get the sub-readers and iterate through them
- /// yourself.
- /// </summary>
- public static IBits GetLiveDocs(IndexReader reader)
- {
- if (reader.HasDeletions)
- {
- IList<AtomicReaderContext> leaves = reader.Leaves;
- int size = leaves.Count;
- Debug.Assert(size > 0, "A reader with deletions must have at least one leave");
- if (size == 1)
- {
- return leaves[0].AtomicReader.LiveDocs;
- }
- var liveDocs = new IBits[size];
- int[] starts = new int[size + 1];
- for (int i = 0; i < size; i++)
- {
- // record all liveDocs, even if they are null
- AtomicReaderContext ctx = leaves[i];
- liveDocs[i] = ctx.AtomicReader.LiveDocs;
- starts[i] = ctx.DocBase;
- }
- starts[size] = reader.MaxDoc;
- return new MultiBits(liveDocs, starts, true);
- }
- else
- {
- return null;
- }
- }
-
- /// <summary>
- /// this method may return null if the field does not exist. </summary>
- public static Terms GetTerms(IndexReader r, string field)
- {
- Fields fields = GetFields(r);
- if (fields == null)
- {
- return null;
- }
- else
- {
- return fields.GetTerms(field);
- }
- }
-
- /// <summary>
- /// Returns <seealso cref="DocsEnum"/> for the specified field &
- /// term. this will return null if the field or term does
- /// not exist.
- /// </summary>
- public static DocsEnum GetTermDocsEnum(IndexReader r, IBits liveDocs, string field, BytesRef term)
- {
- return GetTermDocsEnum(r, liveDocs, field, term, DocsFlags.FREQS);
- }
-
- /// <summary>
- /// Returns <seealso cref="DocsEnum"/> for the specified field &
- /// term, with control over whether freqs are required.
- /// Some codecs may be able to optimize their
- /// implementation when freqs are not required. this will
- /// return null if the field or term does not exist. See {@link
- /// TermsEnum#docs(Bits,DocsEnum,int)}.
- /// </summary>
- public static DocsEnum GetTermDocsEnum(IndexReader r, IBits liveDocs, string field, BytesRef term, DocsFlags flags)
- {
- Debug.Assert(field != null);
- Debug.Assert(term != null);
- Terms terms = GetTerms(r, field);
- if (terms != null)
- {
- TermsEnum termsEnum = terms.GetIterator(null);
- if (termsEnum.SeekExact(term))
- {
- return termsEnum.Docs(liveDocs, null, flags);
- }
- }
- return null;
- }
-
- /// <summary>
- /// Returns <seealso cref="DocsAndPositionsEnum"/> for the specified
- /// field & term. this will return null if the field or
- /// term does not exist or positions were not indexed. </summary>
- /// <seealso cref= #getTermPositionsEnum(IndexReader, Bits, String, BytesRef, int) </seealso>
- public static DocsAndPositionsEnum GetTermPositionsEnum(IndexReader r, IBits liveDocs, string field, BytesRef term)
- {
- return GetTermPositionsEnum(r, liveDocs, field, term, DocsAndPositionsFlags.OFFSETS | DocsAndPositionsFlags.PAYLOADS);
- }
-
- /// <summary>
- /// Returns <seealso cref="DocsAndPositionsEnum"/> for the specified
- /// field & term, with control over whether offsets and payloads are
- /// required. Some codecs may be able to optimize
- /// their implementation when offsets and/or payloads are not
- /// required. this will return null if the field or term does not
- /// exist or positions were not indexed. See {@link
- /// TermsEnum#docsAndPositions(Bits,DocsAndPositionsEnum,int)}.
- /// </summary>
- public static DocsAndPositionsEnum GetTermPositionsEnum(IndexReader r, IBits liveDocs, string field, BytesRef term, DocsAndPositionsFlags flags)
- {
- Debug.Assert(field != null);
- Debug.Assert(term != null);
- Terms terms = GetTerms(r, field);
- if (terms != null)
- {
- TermsEnum termsEnum = terms.GetIterator(null);
- if (termsEnum.SeekExact(term))
- {
- return termsEnum.DocsAndPositions(liveDocs, null, flags);
- }
- }
- return null;
- }
-
- /// <summary>
- /// Expert: construct a new MultiFields instance directly.
- /// @lucene.internal
- /// </summary>
- // TODO: why is this public?
- public MultiFields(Fields[] subs, ReaderSlice[] subSlices)
- {
- this.subs = subs;
- this.subSlices = subSlices;
- }
-
- public override IEnumerator<string> GetEnumerator()
- {
- IEnumerator<string>[] subIterators = new IEnumerator<string>[subs.Length];
- for (int i = 0; i < subs.Length; i++)
- {
- subIterators[i] = subs[i].GetEnumerator();
- }
- return new MergedIterator<string>(subIterators);
- }
-
- public override Terms GetTerms(string field)
- {
- Terms result;
- if (terms.TryGetValue(field, out result) && result != null)
- {
- return result;
- }
-
- // Lazy init: first time this field is requested, we
- // create & add to terms:
- IList<Terms> subs2 = new List<Terms>();
- IList<ReaderSlice> slices2 = new List<ReaderSlice>();
-
- // Gather all sub-readers that share this field
- for (int i = 0; i < subs.Length; i++)
- {
- Terms terms = subs[i].GetTerms(field);
- if (terms != null)
- {
- subs2.Add(terms);
- slices2.Add(subSlices[i]);
- }
- }
- if (subs2.Count == 0)
- {
- result = null;
- // don't cache this case with an unbounded cache, since the number of fields that don't exist
- // is unbounded.
- }
- else
- {
- result = new MultiTerms(subs2.ToArray(/*Terms.EMPTY_ARRAY*/), slices2.ToArray(/*ReaderSlice.EMPTY_ARRAY*/));
- terms[field] = result;
- }
-
- return result;
- }
-
- public override int Count
- {
- get { return -1; }
- }
-
- /// <summary>
- /// Call this to get the (merged) FieldInfos for a
- /// composite reader.
- /// <p>
- /// NOTE: the returned field numbers will likely not
- /// correspond to the actual field numbers in the underlying
- /// readers, and codec metadata (<seealso cref="FieldInfo#getAttribute(String)"/>
- /// will be unavailable.
- /// </summary>
- public static FieldInfos GetMergedFieldInfos(IndexReader reader)
- {
- var builder = new FieldInfos.Builder();
- foreach (AtomicReaderContext ctx in reader.Leaves)
- {
- builder.Add(ctx.AtomicReader.FieldInfos);
- }
- return builder.Finish();
- }
-
- /// <summary>
- /// Call this to get the (merged) FieldInfos representing the
- /// set of indexed fields <b>only</b> for a composite reader.
- /// <p>
- /// NOTE: the returned field numbers will likely not
- /// correspond to the actual field numbers in the underlying
- /// readers, and codec metadata (<seealso cref="FieldInfo#getAttribute(String)"/>
- /// will be unavailable.
- /// </summary>
- public static ICollection<string> GetIndexedFields(IndexReader reader)
- {
- ICollection<string> fields = new HashSet<string>();
- foreach (FieldInfo fieldInfo in GetMergedFieldInfos(reader))
- {
- if (fieldInfo.IsIndexed)
- {
- fields.Add(fieldInfo.Name);
- }
- }
- return fields;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiReader.cs b/src/Lucene.Net.Core/Index/MultiReader.cs
deleted file mode 100644
index 2be292a..0000000
--- a/src/Lucene.Net.Core/Index/MultiReader.cs
+++ /dev/null
@@ -1,110 +0,0 @@
-using System;
-using System.IO;
-
-namespace Lucene.Net.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.
- */
-
- /// <summary>
- /// A <seealso cref="CompositeReader"/> which reads multiple indexes, appending
- /// their content. It can be used to create a view on several
- /// sub-readers (like <seealso cref="DirectoryReader"/>) and execute searches on it.
- ///
- /// <p> For efficiency, in this API documents are often referred to via
- /// <i>document numbers</i>, non-negative integers which each name a unique
- /// document in the index. These document numbers are ephemeral -- they may change
- /// as documents are added to and deleted from an index. Clients should thus not
- /// rely on a given document having the same number between sessions.
- ///
- /// <p><a name="thread-safety"></a><p><b>NOTE</b>: {@link
- /// IndexReader} instances are completely thread
- /// safe, meaning multiple threads can call any of its methods,
- /// concurrently. If your application requires external
- /// synchronization, you should <b>not</b> synchronize on the
- /// <code>IndexReader</code> instance; use your own
- /// (non-Lucene) objects instead.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class MultiReader : BaseCompositeReader<IndexReader>
- {
- private readonly bool closeSubReaders;
-
- /// <summary>
- /// <p>Construct a MultiReader aggregating the named set of (sub)readers.
- /// <p>Note that all subreaders are closed if this Multireader is closed.</p> </summary>
- /// <param name="subReaders"> set of (sub)readers </param>
- public MultiReader(params IndexReader[] subReaders)
- : this(subReaders, true)
- {
- }
-
- /// <summary>
- /// <p>Construct a MultiReader aggregating the named set of (sub)readers. </summary>
- /// <param name="subReaders"> set of (sub)readers; this array will be cloned. </param>
- /// <param name="closeSubReaders"> indicates whether the subreaders should be closed
- /// when this MultiReader is closed </param>
- public MultiReader(IndexReader[] subReaders, bool closeSubReaders)
- : base((IndexReader[])subReaders.Clone())
- {
- this.closeSubReaders = closeSubReaders;
- if (!closeSubReaders)
- {
- for (int i = 0; i < subReaders.Length; i++)
- {
- subReaders[i].IncRef();
- }
- }
- }
-
- protected internal override void DoClose()
- {
- lock (this)
- {
- IOException ioe = null;
- foreach (IndexReader r in GetSequentialSubReaders())
- {
- try
- {
- if (closeSubReaders)
- {
- r.Dispose();
- }
- else
- {
- r.DecRef();
- }
- }
- catch (IOException e)
- {
- if (ioe == null)
- {
- ioe = e;
- }
- }
- }
- // throw the first exception
- if (ioe != null)
- {
- throw ioe;
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/MultiTerms.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/MultiTerms.cs b/src/Lucene.Net.Core/Index/MultiTerms.cs
deleted file mode 100644
index 6854182..0000000
--- a/src/Lucene.Net.Core/Index/MultiTerms.cs
+++ /dev/null
@@ -1,224 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-
-namespace Lucene.Net.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.
- */
-
- using BytesRef = Lucene.Net.Util.BytesRef;
- using CompiledAutomaton = Lucene.Net.Util.Automaton.CompiledAutomaton;
-
- /// <summary>
- /// Exposes flex API, merged from flex API of
- /// sub-segments.
- ///
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class MultiTerms : Terms
- {
- private readonly Terms[] subs;
- private readonly ReaderSlice[] subSlices;
- private readonly IComparer<BytesRef> termComp;
- private readonly bool hasFreqs;
- private readonly bool hasOffsets;
- private readonly bool hasPositions;
- private readonly bool hasPayloads;
-
- /// <summary>
- /// Sole constructor.
- /// </summary>
- /// <param name="subs"> The <seealso cref="Terms"/> instances of all sub-readers. </param>
- /// <param name="subSlices"> A parallel array (matching {@code
- /// subs}) describing the sub-reader slices. </param>
- public MultiTerms(Terms[] subs, ReaderSlice[] subSlices)
- {
- this.subs = subs;
- this.subSlices = subSlices;
-
- IComparer<BytesRef> _termComp = null;
- Debug.Assert(subs.Length > 0, "inefficient: don't use MultiTerms over one sub");
- bool _hasFreqs = true;
- bool _hasOffsets = true;
- bool _hasPositions = true;
- bool _hasPayloads = false;
- for (int i = 0; i < subs.Length; i++)
- {
- if (_termComp == null)
- {
- _termComp = subs[i].Comparer;
- }
- else
- {
- // We cannot merge sub-readers that have
- // different TermComps
- IComparer<BytesRef> subTermComp = subs[i].Comparer;
- if (subTermComp != null && !subTermComp.Equals(_termComp))
- {
- throw new InvalidOperationException("sub-readers have different BytesRef.Comparers; cannot merge");
- }
- }
- _hasFreqs &= subs[i].HasFreqs;
- _hasOffsets &= subs[i].HasOffsets;
- _hasPositions &= subs[i].HasPositions;
- _hasPayloads |= subs[i].HasPayloads;
- }
-
- termComp = _termComp;
- hasFreqs = _hasFreqs;
- hasOffsets = _hasOffsets;
- hasPositions = _hasPositions;
- hasPayloads = hasPositions && _hasPayloads; // if all subs have pos, and at least one has payloads.
- }
-
- public override TermsEnum Intersect(CompiledAutomaton compiled, BytesRef startTerm)
- {
- IList<MultiTermsEnum.TermsEnumIndex> termsEnums = new List<MultiTermsEnum.TermsEnumIndex>();
- for (int i = 0; i < subs.Length; i++)
- {
- TermsEnum termsEnum = subs[i].Intersect(compiled, startTerm);
- if (termsEnum != null)
- {
- termsEnums.Add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i));
- }
- }
-
- if (termsEnums.Count > 0)
- {
- return (new MultiTermsEnum(subSlices)).Reset(termsEnums.ToArray(/*MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY*/));
- }
- else
- {
- return TermsEnum.EMPTY;
- }
- }
-
- public override TermsEnum GetIterator(TermsEnum reuse)
- {
- IList<MultiTermsEnum.TermsEnumIndex> termsEnums = new List<MultiTermsEnum.TermsEnumIndex>();
- for (int i = 0; i < subs.Length; i++)
- {
- TermsEnum termsEnum = subs[i].GetIterator(null);
- if (termsEnum != null)
- {
- termsEnums.Add(new MultiTermsEnum.TermsEnumIndex(termsEnum, i));
- }
- }
-
- if (termsEnums.Count > 0)
- {
- return (new MultiTermsEnum(subSlices)).Reset(termsEnums.ToArray(/*MultiTermsEnum.TermsEnumIndex.EMPTY_ARRAY*/));
- }
- else
- {
- return TermsEnum.EMPTY;
- }
- }
-
- public override long Count
- {
- get { return -1; }
- }
-
- public override long SumTotalTermFreq
- {
- get
- {
- long sum = 0;
- foreach (Terms terms in subs)
- {
- long v = terms.SumTotalTermFreq;
- if (v == -1)
- {
- return -1;
- }
- sum += v;
- }
- return sum;
- }
- }
-
- public override long SumDocFreq
- {
- get
- {
- long sum = 0;
- foreach (Terms terms in subs)
- {
- long v = terms.SumDocFreq;
- if (v == -1)
- {
- return -1;
- }
- sum += v;
- }
- return sum;
- }
- }
-
- public override int DocCount
- {
- get
- {
- int sum = 0;
- foreach (Terms terms in subs)
- {
- int v = terms.DocCount;
- if (v == -1)
- {
- return -1;
- }
- sum += v;
- }
- return sum;
- }
- }
-
- public override IComparer<BytesRef> Comparer
- {
- get
- {
- return termComp;
- }
- }
-
- public override bool HasFreqs
- {
- get { return hasFreqs; }
- }
-
- public override bool HasOffsets
- {
- get { return hasOffsets; }
- }
-
- public override bool HasPositions
- {
- get { return hasPositions; }
- }
-
- public override bool HasPayloads
- {
- get { return hasPayloads; }
- }
- }
-}
\ No newline at end of file