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:14 UTC
[08/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/ParallelCompositeReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ParallelCompositeReader.cs b/src/Lucene.Net.Core/Index/ParallelCompositeReader.cs
deleted file mode 100644
index c35642a..0000000
--- a/src/Lucene.Net.Core/Index/ParallelCompositeReader.cs
+++ /dev/null
@@ -1,262 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-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>
- /// An <seealso cref="CompositeReader"/> which reads multiple, parallel indexes. Each index added
- /// must have the same number of documents, and exactly the same hierarchical subreader structure,
- /// but typically each contains different fields. Deletions are taken from the first reader.
- /// Each document contains the union of the fields of all
- /// documents with the same document number. When searching, matches for a
- /// query term are from the first index added that has the field.
- ///
- /// <p>this is useful, e.g., with collections that have large fields which
- /// change rarely and small fields that change more frequently. The smaller
- /// fields may be re-indexed in a new index and both indexes may be searched
- /// together.
- ///
- /// <p><strong>Warning:</strong> It is up to you to make sure all indexes
- /// are created and modified the same way. For example, if you add
- /// documents to one index, you need to add the same documents in the
- /// same order to the other indexes. <em>Failure to do so will result in
- /// undefined behavior</em>.
- /// A good strategy to create suitable indexes with <seealso cref="IndexWriter"/> is to use
- /// <seealso cref="LogDocMergePolicy"/>, as this one does not reorder documents
- /// during merging (like {@code TieredMergePolicy}) and triggers merges
- /// by number of documents per segment. If you use different <seealso cref="MergePolicy"/>s
- /// it might happen that the segment structure of your index is no longer predictable.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class ParallelCompositeReader : BaseCompositeReader<IndexReader>
- {
- private readonly bool closeSubReaders;
- private readonly ISet<IndexReader> completeReaderSet = new IdentityHashSet<IndexReader>();
-
- /// <summary>
- /// Create a ParallelCompositeReader based on the provided
- /// readers; auto-closes the given readers on <seealso cref="#close()"/>.
- /// </summary>
- public ParallelCompositeReader(params CompositeReader[] readers)
- : this(true, readers)
- {
- }
-
- /// <summary>
- /// Create a ParallelCompositeReader based on the provided
- /// readers.
- /// </summary>
- public ParallelCompositeReader(bool closeSubReaders, params CompositeReader[] readers)
- : this(closeSubReaders, readers, readers)
- {
- }
-
- /// <summary>
- /// Expert: create a ParallelCompositeReader based on the provided
- /// readers and storedFieldReaders; when a document is
- /// loaded, only storedFieldsReaders will be used.
- /// </summary>
- public ParallelCompositeReader(bool closeSubReaders, CompositeReader[] readers, CompositeReader[] storedFieldReaders)
- : base(PrepareSubReaders(readers, storedFieldReaders))
- {
- this.closeSubReaders = closeSubReaders;
- Collections.AddAll(completeReaderSet, readers);
- Collections.AddAll(completeReaderSet, storedFieldReaders);
- // update ref-counts (like MultiReader):
- if (!closeSubReaders)
- {
- foreach (IndexReader reader in completeReaderSet)
- {
- reader.IncRef();
- }
- }
- // finally add our own synthetic readers, so we close or decRef them, too (it does not matter what we do)
- Collections.AddAll(completeReaderSet, GetSequentialSubReaders());
- }
-
- private static IndexReader[] PrepareSubReaders(CompositeReader[] readers, CompositeReader[] storedFieldsReaders)
- {
- if (readers.Length == 0)
- {
- if (storedFieldsReaders.Length > 0)
- {
- throw new System.ArgumentException("There must be at least one main reader if storedFieldsReaders are used.");
- }
- return new IndexReader[0];
- }
- else
- {
- IList<IndexReader> firstSubReaders = readers[0].GetSequentialSubReaders();
-
- // check compatibility:
- int maxDoc = readers[0].MaxDoc, noSubs = firstSubReaders.Count;
- int[] childMaxDoc = new int[noSubs];
- bool[] childAtomic = new bool[noSubs];
- for (int i = 0; i < noSubs; i++)
- {
- IndexReader r = firstSubReaders[i];
- childMaxDoc[i] = r.MaxDoc;
- childAtomic[i] = r is AtomicReader;
- }
- Validate(readers, maxDoc, childMaxDoc, childAtomic);
- Validate(storedFieldsReaders, maxDoc, childMaxDoc, childAtomic);
-
- // hierarchically build the same subreader structure as the first CompositeReader with Parallel*Readers:
- IndexReader[] subReaders = new IndexReader[noSubs];
- for (int i = 0; i < subReaders.Length; i++)
- {
- if (firstSubReaders[i] is AtomicReader)
- {
- AtomicReader[] atomicSubs = new AtomicReader[readers.Length];
- for (int j = 0; j < readers.Length; j++)
- {
- atomicSubs[j] = (AtomicReader)readers[j].GetSequentialSubReaders()[i];
- }
- AtomicReader[] storedSubs = new AtomicReader[storedFieldsReaders.Length];
- for (int j = 0; j < storedFieldsReaders.Length; j++)
- {
- storedSubs[j] = (AtomicReader)storedFieldsReaders[j].GetSequentialSubReaders()[i];
- }
- // We pass true for closeSubs and we prevent closing of subreaders in doClose():
- // By this the synthetic throw-away readers used here are completely invisible to ref-counting
- subReaders[i] = new ParallelAtomicReaderAnonymousInnerClassHelper(atomicSubs, storedSubs);
- }
- else
- {
- Debug.Assert(firstSubReaders[i] is CompositeReader);
- CompositeReader[] compositeSubs = new CompositeReader[readers.Length];
- for (int j = 0; j < readers.Length; j++)
- {
- compositeSubs[j] = (CompositeReader)readers[j].GetSequentialSubReaders()[i];
- }
- CompositeReader[] storedSubs = new CompositeReader[storedFieldsReaders.Length];
- for (int j = 0; j < storedFieldsReaders.Length; j++)
- {
- storedSubs[j] = (CompositeReader)storedFieldsReaders[j].GetSequentialSubReaders()[i];
- }
- // We pass true for closeSubs and we prevent closing of subreaders in doClose():
- // By this the synthetic throw-away readers used here are completely invisible to ref-counting
- subReaders[i] = new ParallelCompositeReaderAnonymousInnerClassHelper(compositeSubs, storedSubs);
- }
- }
- return subReaders;
- }
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class ParallelAtomicReaderAnonymousInnerClassHelper : ParallelAtomicReader
- {
- public ParallelAtomicReaderAnonymousInnerClassHelper(Lucene.Net.Index.AtomicReader[] atomicSubs, Lucene.Net.Index.AtomicReader[] storedSubs)
- : base(true, atomicSubs, storedSubs)
- {
- }
-
- protected internal override void DoClose()
- {
- }
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- private class ParallelCompositeReaderAnonymousInnerClassHelper : ParallelCompositeReader
- {
- public ParallelCompositeReaderAnonymousInnerClassHelper(Lucene.Net.Index.CompositeReader[] compositeSubs, Lucene.Net.Index.CompositeReader[] storedSubs)
- : base(true, compositeSubs, storedSubs)
- {
- }
-
- protected internal override void DoClose()
- {
- }
- }
-
- private static void Validate(CompositeReader[] readers, int maxDoc, int[] childMaxDoc, bool[] childAtomic)
- {
- for (int i = 0; i < readers.Length; i++)
- {
- CompositeReader reader = readers[i];
- IList<IndexReader> subs = reader.GetSequentialSubReaders();
- if (reader.MaxDoc != maxDoc)
- {
- throw new System.ArgumentException("All readers must have same MaxDoc: " + maxDoc + "!=" + reader.MaxDoc);
- }
- int noSubs = subs.Count;
- if (noSubs != childMaxDoc.Length)
- {
- throw new System.ArgumentException("All readers must have same number of subReaders");
- }
- for (int subIDX = 0; subIDX < noSubs; subIDX++)
- {
- IndexReader r = subs[subIDX];
- if (r.MaxDoc != childMaxDoc[subIDX])
- {
- throw new System.ArgumentException("All readers must have same corresponding subReader maxDoc");
- }
- if (!(childAtomic[subIDX] ? (r is AtomicReader) : (r is CompositeReader)))
- {
- throw new System.ArgumentException("All readers must have same corresponding subReader types (atomic or composite)");
- }
- }
- }
- }
-
- protected internal override void DoClose()
- {
- lock (this)
- {
- IOException ioe = null;
- foreach (IndexReader reader in completeReaderSet)
- {
- try
- {
- if (closeSubReaders)
- {
- reader.Dispose();
- }
- else
- {
- reader.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/ParallelPostingsArray.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ParallelPostingsArray.cs b/src/Lucene.Net.Core/Index/ParallelPostingsArray.cs
deleted file mode 100644
index 94ac850..0000000
--- a/src/Lucene.Net.Core/Index/ParallelPostingsArray.cs
+++ /dev/null
@@ -1,70 +0,0 @@
-using System;
-
-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 ArrayUtil = Lucene.Net.Util.ArrayUtil;
- using RamUsageEstimator = Lucene.Net.Util.RamUsageEstimator;
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class ParallelPostingsArray
- {
- internal static readonly int BYTES_PER_POSTING = 3 * RamUsageEstimator.NUM_BYTES_INT32;
-
- internal readonly int size;
- internal readonly int[] textStarts;
- internal readonly int[] intStarts;
- internal readonly int[] byteStarts;
-
- internal ParallelPostingsArray(int size)
- {
- this.size = size;
- textStarts = new int[size];
- intStarts = new int[size];
- byteStarts = new int[size];
- }
-
- internal virtual int BytesPerPosting()
- {
- return BYTES_PER_POSTING;
- }
-
- internal virtual ParallelPostingsArray NewInstance(int size)
- {
- return new ParallelPostingsArray(size);
- }
-
- internal ParallelPostingsArray Grow()
- {
- int newSize = ArrayUtil.Oversize(size + 1, BytesPerPosting());
- ParallelPostingsArray newArray = NewInstance(newSize);
- CopyTo(newArray, size);
- return newArray;
- }
-
- internal virtual void CopyTo(ParallelPostingsArray toArray, int numToCopy)
- {
- Array.Copy(textStarts, 0, toArray.textStarts, 0, numToCopy);
- Array.Copy(intStarts, 0, toArray.intStarts, 0, numToCopy);
- Array.Copy(byteStarts, 0, toArray.byteStarts, 0, numToCopy);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/PersistentSnapshotDeletionPolicy.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/PersistentSnapshotDeletionPolicy.cs b/src/Lucene.Net.Core/Index/PersistentSnapshotDeletionPolicy.cs
deleted file mode 100644
index b90405a..0000000
--- a/src/Lucene.Net.Core/Index/PersistentSnapshotDeletionPolicy.cs
+++ /dev/null
@@ -1,381 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Collections.Generic;
-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.
- */
-
- using CodecUtil = Lucene.Net.Codecs.CodecUtil;
- using Directory = Lucene.Net.Store.Directory;
- using IndexInput = Lucene.Net.Store.IndexInput;
- using IndexOutput = Lucene.Net.Store.IndexOutput;
- using IOContext = Lucene.Net.Store.IOContext;
- using IOUtils = Lucene.Net.Util.IOUtils;
-
- /// <summary>
- /// A <seealso cref="SnapshotDeletionPolicy"/> which adds a persistence layer so that
- /// snapshots can be maintained across the life of an application. The snapshots
- /// are persisted in a <seealso cref="Directory"/> and are committed as soon as
- /// <seealso cref="#snapshot()"/> or <seealso cref="#release(IndexCommit)"/> is called.
- /// <p>
- /// <b>NOTE:</b> Sharing <seealso cref="PersistentSnapshotDeletionPolicy"/>s that write to
- /// the same directory across <seealso cref="IndexWriter"/>s will corrupt snapshots. You
- /// should make sure every <seealso cref="IndexWriter"/> has its own
- /// <seealso cref="PersistentSnapshotDeletionPolicy"/> and that they all write to a
- /// different <seealso cref="Directory"/>. It is OK to use the same
- /// Directory that holds the index.
- ///
- /// <p> this class adds a <seealso cref="#release(long)"/> method to
- /// release commits from a previous snapshot's <seealso cref="IndexCommit#getGeneration"/>.
- ///
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class PersistentSnapshotDeletionPolicy : SnapshotDeletionPolicy
- {
- /// <summary>
- /// Prefix used for the save file. </summary>
- public static readonly string SNAPSHOTS_PREFIX = "snapshots_";
-
- private static readonly int VERSION_START = 0;
- private static readonly int VERSION_CURRENT = VERSION_START;
- private static readonly string CODEC_NAME = "snapshots";
-
- // The index writer which maintains the snapshots metadata
- private long nextWriteGen;
-
- private readonly Directory dir;
-
- /// <summary>
- /// <seealso cref="PersistentSnapshotDeletionPolicy"/> wraps another
- /// <seealso cref="IndexDeletionPolicy"/> to enable flexible
- /// snapshotting, passing <seealso cref="OpenMode#CREATE_OR_APPEND"/>
- /// by default.
- /// </summary>
- /// <param name="primary">
- /// the <seealso cref="IndexDeletionPolicy"/> that is used on non-snapshotted
- /// commits. Snapshotted commits, by definition, are not deleted until
- /// explicitly released via <seealso cref="#release"/>. </param>
- /// <param name="dir">
- /// the <seealso cref="Directory"/> which will be used to persist the snapshots
- /// information. </param>
- public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir)
- : this(primary, dir, OpenMode.CREATE_OR_APPEND)
- {
- }
-
- /// <summary>
- /// <seealso cref="PersistentSnapshotDeletionPolicy"/> wraps another
- /// <seealso cref="IndexDeletionPolicy"/> to enable flexible snapshotting.
- /// </summary>
- /// <param name="primary">
- /// the <seealso cref="IndexDeletionPolicy"/> that is used on non-snapshotted
- /// commits. Snapshotted commits, by definition, are not deleted until
- /// explicitly released via <seealso cref="#release"/>. </param>
- /// <param name="dir">
- /// the <seealso cref="Directory"/> which will be used to persist the snapshots
- /// information. </param>
- /// <param name="mode">
- /// specifies whether a new index should be created, deleting all
- /// existing snapshots information (immediately), or open an existing
- /// index, initializing the class with the snapshots information. </param>
- public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, OpenMode mode)
- : base(primary)
- {
- this.dir = dir;
-
- if (mode == OpenMode.CREATE)
- {
- ClearPriorSnapshots();
- }
-
- LoadPriorSnapshots();
-
- if (mode == OpenMode.APPEND && nextWriteGen == 0)
- {
- throw new InvalidOperationException("no snapshots stored in this directory");
- }
- }
-
- /// <summary>
- /// Snapshots the last commit. Once this method returns, the
- /// snapshot information is persisted in the directory.
- /// </summary>
- /// <seealso cref= SnapshotDeletionPolicy#snapshot </seealso>
- public override IndexCommit Snapshot()
- {
- lock (this)
- {
- IndexCommit ic = base.Snapshot();
- bool success = false;
- try
- {
- Persist();
- success = true;
- }
- finally
- {
- if (!success)
- {
- try
- {
- base.Release(ic);
- }
-#pragma warning disable 168
- catch (Exception e)
-#pragma warning restore 168
- {
- // Suppress so we keep throwing original exception
- }
- }
- }
- return ic;
- }
- }
-
- /// <summary>
- /// Deletes a snapshotted commit. Once this method returns, the snapshot
- /// information is persisted in the directory.
- /// </summary>
- /// <seealso cref= SnapshotDeletionPolicy#release </seealso>
- public override void Release(IndexCommit commit)
- {
- lock (this)
- {
- base.Release(commit);
- bool success = false;
- try
- {
- Persist();
- success = true;
- }
- finally
- {
- if (!success)
- {
- try
- {
- IncRef(commit);
- }
-#pragma warning disable 168
- catch (Exception e)
-#pragma warning restore 168
- {
- // Suppress so we keep throwing original exception
- }
- }
- }
- }
- }
-
- /// <summary>
- /// Deletes a snapshotted commit by generation. Once this method returns, the snapshot
- /// information is persisted in the directory.
- /// </summary>
- /// <seealso cref= IndexCommit#getGeneration </seealso>
- /// <seealso cref= SnapshotDeletionPolicy#release </seealso>
- public virtual void Release(long gen)
- {
- lock (this)
- {
- base.ReleaseGen(gen);
- Persist();
- }
- }
-
- internal void Persist()
- {
- lock (this)
- {
- string fileName = SNAPSHOTS_PREFIX + nextWriteGen;
- IndexOutput @out = dir.CreateOutput(fileName, IOContext.DEFAULT);
- bool success = false;
- try
- {
- CodecUtil.WriteHeader(@out, CODEC_NAME, VERSION_CURRENT);
- @out.WriteVInt32(m_refCounts.Count);
- foreach (KeyValuePair<long, int> ent in m_refCounts)
- {
- @out.WriteVInt64(ent.Key);
- @out.WriteVInt32(ent.Value);
- }
- success = true;
- }
- finally
- {
- if (!success)
- {
- IOUtils.CloseWhileHandlingException(@out);
- try
- {
- dir.DeleteFile(fileName);
- }
-#pragma warning disable 168
- catch (Exception e)
-#pragma warning restore 168
- {
- // Suppress so we keep throwing original exception
- }
- }
- else
- {
- IOUtils.Close(@out);
- }
- }
-
- dir.Sync(/*Collections.singletonList(*/new[] { fileName }/*)*/);
-
- if (nextWriteGen > 0)
- {
- string lastSaveFile = SNAPSHOTS_PREFIX + (nextWriteGen - 1);
- try
- {
- dir.DeleteFile(lastSaveFile);
- }
-#pragma warning disable 168
- catch (IOException ioe)
-#pragma warning restore 168
- {
- // OK: likely it didn't exist
- }
- }
-
- nextWriteGen++;
- }
- }
-
- private void ClearPriorSnapshots()
- {
- lock (this)
- {
- foreach (string file in dir.ListAll())
- {
- if (file.StartsWith(SNAPSHOTS_PREFIX, StringComparison.Ordinal))
- {
- dir.DeleteFile(file);
- }
- }
- }
- }
-
- /// <summary>
- /// Returns the file name the snapshots are currently
- /// saved to, or null if no snapshots have been saved.
- /// </summary>
- public virtual string LastSaveFile
- {
- get
- {
- if (nextWriteGen == 0)
- {
- return null;
- }
- else
- {
- return SNAPSHOTS_PREFIX + (nextWriteGen - 1);
- }
- }
- }
-
- /// <summary>
- /// Reads the snapshots information from the given <seealso cref="Directory"/>. this
- /// method can be used if the snapshots information is needed, however you
- /// cannot instantiate the deletion policy (because e.g., some other process
- /// keeps a lock on the snapshots directory).
- /// </summary>
- private void LoadPriorSnapshots()
- {
- lock (this)
- {
- long genLoaded = -1;
- IOException ioe = null;
- IList<string> snapshotFiles = new List<string>();
- foreach (string file in dir.ListAll())
- {
- if (file.StartsWith(SNAPSHOTS_PREFIX, StringComparison.Ordinal))
- {
- long gen = Convert.ToInt64(file.Substring(SNAPSHOTS_PREFIX.Length));
- if (genLoaded == -1 || gen > genLoaded)
- {
- snapshotFiles.Add(file);
- IDictionary<long, int> m = new Dictionary<long, int>();
- IndexInput @in = dir.OpenInput(file, IOContext.DEFAULT);
- try
- {
- CodecUtil.CheckHeader(@in, CODEC_NAME, VERSION_START, VERSION_START);
- int count = @in.ReadVInt32();
- for (int i = 0; i < count; i++)
- {
- long commitGen = @in.ReadVInt64();
- int refCount = @in.ReadVInt32();
- m[commitGen] = refCount;
- }
- }
- catch (IOException ioe2)
- {
- // Save first exception & throw in the end
- if (ioe == null)
- {
- ioe = ioe2;
- }
- }
- finally
- {
- @in.Dispose();
- }
-
- genLoaded = gen;
- m_refCounts.Clear();
- m_refCounts.PutAll(m);
- }
- }
- }
-
- if (genLoaded == -1)
- {
- // Nothing was loaded...
- if (ioe != null)
- {
- // ... not for lack of trying:
- throw ioe;
- }
- }
- else
- {
- if (snapshotFiles.Count > 1)
- {
- // Remove any broken / old snapshot files:
- string curFileName = SNAPSHOTS_PREFIX + genLoaded;
- foreach (string file in snapshotFiles)
- {
- if (!curFileName.Equals(file, StringComparison.Ordinal))
- {
- dir.DeleteFile(file);
- }
- }
- }
- nextWriteGen = 1 + genLoaded;
- }
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/PrefixCodedTerms.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/PrefixCodedTerms.cs b/src/Lucene.Net.Core/Index/PrefixCodedTerms.cs
deleted file mode 100644
index 7403384..0000000
--- a/src/Lucene.Net.Core/Index/PrefixCodedTerms.cs
+++ /dev/null
@@ -1,222 +0,0 @@
-using Lucene.Net.Support;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-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.
- */
-
- using BytesRef = Lucene.Net.Util.BytesRef;
- using IndexInput = Lucene.Net.Store.IndexInput;
- using RAMFile = Lucene.Net.Store.RAMFile;
- using RAMInputStream = Lucene.Net.Store.RAMInputStream;
- using RAMOutputStream = Lucene.Net.Store.RAMOutputStream;
-
- /// <summary>
- /// Prefix codes term instances (prefixes are shared)
- /// @lucene.experimental
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class PrefixCodedTerms : IEnumerable<Term>
- {
- internal readonly RAMFile buffer;
-
- private PrefixCodedTerms(RAMFile buffer)
- {
- this.buffer = buffer;
- }
-
- /// <returns> size in bytes </returns>
- public virtual long GetSizeInBytes()
- {
- return buffer.GetSizeInBytes();
- }
-
- /// <returns> iterator over the bytes </returns>
- public virtual IEnumerator<Term> GetEnumerator()
- {
- return new PrefixCodedTermsIterator(buffer);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
-
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- internal class PrefixCodedTermsIterator : IEnumerator<Term>
- {
- private readonly IndexInput input;
- private string field = "";
- private BytesRef bytes = new BytesRef();
- private Term term;
-
- internal PrefixCodedTermsIterator(RAMFile buffer)
- {
- term = new Term(field, bytes);
-
- try
- {
- input = new RAMInputStream("PrefixCodedTermsIterator", buffer);
- }
- catch (System.IO.IOException e)
- {
- throw new Exception(e.ToString(), e);
- }
- }
-
- public virtual Term Current
- {
- get { return term; }
- }
-
- public virtual void Dispose()
- {
- }
-
- object IEnumerator.Current
- {
- get { return Current; }
- }
-
- public virtual bool MoveNext()
- {
- if (input.GetFilePointer() < input.Length)
- {
- try
- {
- int code = input.ReadVInt32();
- if ((code & 1) != 0)
- {
- field = input.ReadString();
- }
- int prefix = Number.URShift(code, 1);
- int suffix = input.ReadVInt32();
- bytes.Grow(prefix + suffix);
- input.ReadBytes(bytes.Bytes, prefix, suffix);
- bytes.Length = prefix + suffix;
- term.Set(field, bytes);
- }
- catch (IOException e)
- {
- throw new Exception(e.ToString(), e);
- }
-
- return true;
- }
- return false;
- }
-
- public virtual void Reset()
- {
- throw new NotSupportedException();
- }
- }
-
- /// <summary>
- /// Builds a PrefixCodedTerms: call add repeatedly, then finish. </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public class Builder
- {
- public Builder()
- {
- InitializeInstanceFields();
- }
-
- internal virtual void InitializeInstanceFields()
- {
- output = new RAMOutputStream(buffer);
- }
-
- private RAMFile buffer = new RAMFile();
- private RAMOutputStream output;
- private Term lastTerm = new Term("");
-
- /// <summary>
- /// add a term </summary>
- public virtual void Add(Term term)
- {
- Debug.Assert(lastTerm.Equals(new Term("")) || term.CompareTo(lastTerm) > 0);
-
- try
- {
- int prefix = SharedPrefix(lastTerm.Bytes, term.Bytes);
- int suffix = term.Bytes.Length - prefix;
- if (term.Field.Equals(lastTerm.Field, StringComparison.Ordinal))
- {
- output.WriteVInt32(prefix << 1);
- }
- else
- {
- output.WriteVInt32(prefix << 1 | 1);
- output.WriteString(term.Field);
- }
- output.WriteVInt32(suffix);
- output.WriteBytes(term.Bytes.Bytes, term.Bytes.Offset + prefix, suffix);
- lastTerm.Bytes.CopyBytes(term.Bytes);
- lastTerm.Field = term.Field;
- }
- catch (IOException e)
- {
- throw new Exception(e.ToString(), e);
- }
- }
-
- /// <summary>
- /// return finalized form </summary>
- public virtual PrefixCodedTerms Finish()
- {
- try
- {
- output.Dispose();
- return new PrefixCodedTerms(buffer);
- }
- catch (IOException e)
- {
- throw new Exception(e.ToString(), e);
- }
- }
-
- private int SharedPrefix(BytesRef term1, BytesRef term2)
- {
- int pos1 = 0;
- int pos1End = pos1 + Math.Min(term1.Length, term2.Length);
- int pos2 = 0;
- while (pos1 < pos1End)
- {
- if (term1.Bytes[term1.Offset + pos1] != term2.Bytes[term2.Offset + pos2])
- {
- return pos1;
- }
- pos1++;
- pos2++;
- }
- return pos1;
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/RandomAccessOrds.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/RandomAccessOrds.cs b/src/Lucene.Net.Core/Index/RandomAccessOrds.cs
deleted file mode 100644
index 5d777d4..0000000
--- a/src/Lucene.Net.Core/Index/RandomAccessOrds.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-
-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>
- /// Extension of <seealso cref="SortedSetDocValues"/> that supports random access
- /// to the ordinals of a document.
- /// <p>
- /// Operations via this API are independent of the iterator api (<seealso cref="#nextOrd()"/>)
- /// and do not impact its state.
- /// <p>
- /// Codecs can optionally extend this API if they support constant-time access
- /// to ordinals for the document.
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public abstract class RandomAccessOrds : SortedSetDocValues
- {
- /// <summary>
- /// Sole constructor. (For invocation by subclass
- /// constructors, typically implicit.)
- /// </summary>
- protected RandomAccessOrds()
- {
- }
-
- /// <summary>
- /// Retrieve the ordinal for the current document (previously
- /// set by <seealso cref="#setDocument(int)"/> at the specified index.
- /// <p>
- /// An index ranges from {@code 0} to {@code cardinality()-1}.
- /// The first ordinal value is at index {@code 0}, the next at index {@code 1},
- /// and so on, as for array indexing. </summary>
- /// <param name="index"> index of the ordinal for the document. </param>
- /// <returns> ordinal for the document at the specified index. </returns>
- public abstract long OrdAt(int index);
-
- /// <summary>
- /// Returns the cardinality for the current document (previously
- /// set by <seealso cref="#setDocument(int)"/>.
- /// </summary>
- public abstract int Cardinality();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/ReaderManager.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ReaderManager.cs b/src/Lucene.Net.Core/Index/ReaderManager.cs
deleted file mode 100644
index 30ba2d5..0000000
--- a/src/Lucene.Net.Core/Index/ReaderManager.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using Lucene.Net.Search;
-
-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 Directory = Lucene.Net.Store.Directory;
- using IndexSearcher = Lucene.Net.Search.IndexSearcher;
-
- /// <summary>
- /// Utility class to safely share <seealso cref="DirectoryReader"/> instances across
- /// multiple threads, while periodically reopening. this class ensures each
- /// reader is closed only once all threads have finished using it.
- /// </summary>
- /// <seealso cref= SearcherManager
- ///
- /// @lucene.experimental </seealso>
- public sealed class ReaderManager : ReferenceManager<DirectoryReader>
- {
- /// <summary>
- /// Creates and returns a new ReaderManager from the given
- /// <seealso cref="IndexWriter"/>.
- /// </summary>
- /// <param name="writer">
- /// the IndexWriter to open the IndexReader from. </param>
- /// <param name="applyAllDeletes">
- /// If <code>true</code>, all buffered deletes will be applied (made
- /// visible) in the <seealso cref="IndexSearcher"/> / <seealso cref="DirectoryReader"/>.
- /// If <code>false</code>, the deletes may or may not be applied, but
- /// remain buffered (in IndexWriter) so that they will be applied in
- /// the future. Applying deletes can be costly, so if your app can
- /// tolerate deleted documents being returned you might gain some
- /// performance by passing <code>false</code>. See
- /// <seealso cref="DirectoryReader#openIfChanged(DirectoryReader, IndexWriter, boolean)"/>.
- /// </param>
- /// <exception cref="IOException"> If there is a low-level I/O error </exception>
- public ReaderManager(IndexWriter writer, bool applyAllDeletes)
- {
- Current = DirectoryReader.Open(writer, applyAllDeletes);
- }
-
- /// <summary>
- /// Creates and returns a new ReaderManager from the given <seealso cref="Directory"/>. </summary>
- /// <param name="dir"> the directory to open the DirectoryReader on.
- /// </param>
- /// <exception cref="IOException"> If there is a low-level I/O error </exception>
- public ReaderManager(Directory dir)
- {
- Current = DirectoryReader.Open(dir);
- }
-
- protected override void DecRef(DirectoryReader reference)
- {
- reference.DecRef();
- }
-
- protected override DirectoryReader RefreshIfNeeded(DirectoryReader referenceToRefresh)
- {
- return DirectoryReader.OpenIfChanged(referenceToRefresh);
- }
-
- protected override bool TryIncRef(DirectoryReader reference)
- {
- return reference.TryIncRef();
- }
-
- protected override int GetRefCount(DirectoryReader reference)
- {
- return reference.RefCount;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/ReaderSlice.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ReaderSlice.cs b/src/Lucene.Net.Core/Index/ReaderSlice.cs
deleted file mode 100644
index e12cb92..0000000
--- a/src/Lucene.Net.Core/Index/ReaderSlice.cs
+++ /dev/null
@@ -1,62 +0,0 @@
-using System;
-
-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>
- /// Subreader slice from a parent composite reader.
- ///
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class ReaderSlice
- {
- /// <summary>
- /// Zero-length {@code ReaderSlice} array. </summary>
- public static readonly ReaderSlice[] EMPTY_ARRAY = new ReaderSlice[0];
-
- /// <summary>
- /// Document ID this slice starts from. </summary>
- public int Start { get; private set; }
-
- /// <summary>
- /// Number of documents in this slice. </summary>
- public int Length { get; private set; }
-
- /// <summary>
- /// Sub-reader index for this slice. </summary>
- public int ReaderIndex { get; private set; }
-
- /// <summary>
- /// Sole constructor. </summary>
- public ReaderSlice(int start, int length, int readerIndex)
- {
- this.Start = start;
- this.Length = length;
- this.ReaderIndex = readerIndex;
- }
-
- public override string ToString()
- {
- return "slice start=" + Start + " length=" + Length + " readerIndex=" + ReaderIndex;
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Index/ReaderUtil.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Index/ReaderUtil.cs b/src/Lucene.Net.Core/Index/ReaderUtil.cs
deleted file mode 100644
index 065f60d..0000000
--- a/src/Lucene.Net.Core/Index/ReaderUtil.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-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>
- /// Common util methods for dealing with <seealso cref="IndexReader"/>s and <seealso cref="IndexReaderContext"/>s.
- ///
- /// @lucene.internal
- /// </summary>
-#if FEATURE_SERIALIZABLE
- [Serializable]
-#endif
- public sealed class ReaderUtil
- {
- private ReaderUtil() // no instance
- {
- }
-
- /// <summary>
- /// Walks up the reader tree and return the given context's top level reader
- /// context, or in other words the reader tree's root context.
- /// </summary>
- public static IndexReaderContext GetTopLevelContext(IndexReaderContext context)
- {
- while (context.Parent != null)
- {
- context = context.Parent;
- }
- return context;
- }
-
- /// <summary>
- /// Returns index of the searcher/reader for document <code>n</code> in the
- /// array used to construct this searcher/reader.
- /// </summary>
- public static int SubIndex(int n, int[] docStarts) // find
- {
- // searcher/reader for doc n:
- int size = docStarts.Length;
- int lo = 0; // search starts array
- int hi = size - 1; // for first element less than n, return its index
- while (hi >= lo)
- {
- int mid = (int)((uint)(lo + hi) >> 1);
- int midValue = docStarts[mid];
- if (n < midValue)
- {
- hi = mid - 1;
- }
- else if (n > midValue)
- {
- lo = mid + 1;
- }
- else // found a match
- {
- while (mid + 1 < size && docStarts[mid + 1] == midValue)
- {
- mid++; // scan to last match
- }
- return mid;
- }
- }
- return hi;
- }
-
- /// <summary>
- /// Returns index of the searcher/reader for document <code>n</code> in the
- /// array used to construct this searcher/reader.
- /// </summary>
- public static int SubIndex(int n, IList<AtomicReaderContext> leaves) // find
- {
- // searcher/reader for doc n:
- int size = leaves.Count;
- int lo = 0; // search starts array
- int hi = size - 1; // for first element less than n, return its index
- while (hi >= lo)
- {
- int mid = (int)((uint)(lo + hi) >> 1);
- int midValue = leaves[mid].DocBase;
- if (n < midValue)
- {
- hi = mid - 1;
- }
- else if (n > midValue)
- {
- lo = mid + 1;
- }
- else // found a match
- {
- while (mid + 1 < size && leaves[mid + 1].DocBase == midValue)
- {
- mid++; // scan to last match
- }
- return mid;
- }
- }
- return hi;
- }
- }
-}
\ No newline at end of file