lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject svn commit: r1367344 - /incubator/lucene.net/trunk/src/core/Index/
Date Mon, 30 Jul 2012 22:30:43 GMT
Author: synhershko
Date: Mon Jul 30 22:30:43 2012
New Revision: 1367344

URL: http://svn.apache.org/viewvc?rev=1367344&view=rev
Log:
Cleanup work

Modified:
    incubator/lucene.net/trunk/src/core/Index/DefaultSkipListReader.cs
    incubator/lucene.net/trunk/src/core/Index/DirectoryReader.cs
    incubator/lucene.net/trunk/src/core/Index/DocInverter.cs
    incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs
    incubator/lucene.net/trunk/src/core/Index/FieldSortedTermVectorMapper.cs
    incubator/lucene.net/trunk/src/core/Index/FormatPostingsPositionsConsumer.cs
    incubator/lucene.net/trunk/src/core/Index/KeepOnlyLastCommitDeletionPolicy.cs
    incubator/lucene.net/trunk/src/core/Index/MultiLevelSkipListReader.cs
    incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs
    incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs
    incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs
    incubator/lucene.net/trunk/src/core/Index/TermVectorsWriter.cs

Modified: incubator/lucene.net/trunk/src/core/Index/DefaultSkipListReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/DefaultSkipListReader.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/DefaultSkipListReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/DefaultSkipListReader.cs Mon Jul 30 22:30:43
2012
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-using System;
 using Lucene.Net.Support;
 using IndexInput = Lucene.Net.Store.IndexInput;
 
@@ -29,9 +28,9 @@ namespace Lucene.Net.Index
 	class DefaultSkipListReader:MultiLevelSkipListReader
 	{
 		private bool currentFieldStoresPayloads;
-		private long[] freqPointer;
-		private long[] proxPointer;
-		private int[] payloadLength;
+		private readonly long[] freqPointer;
+		private readonly long[] proxPointer;
+		private readonly int[] payloadLength;
 		
 		private long lastFreqPointer;
 		private long lastProxPointer;

Modified: incubator/lucene.net/trunk/src/core/Index/DirectoryReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/DirectoryReader.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/DirectoryReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/DirectoryReader.cs Mon Jul 30 22:30:43 2012
@@ -17,10 +17,10 @@
 
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using Lucene.Net.Support;
 using Document = Lucene.Net.Documents.Document;
 using FieldSelector = Lucene.Net.Documents.FieldSelector;
-using AlreadyClosedException = Lucene.Net.Store.AlreadyClosedException;
 using Directory = Lucene.Net.Store.Directory;
 using Lock = Lucene.Net.Store.Lock;
 using LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException;
@@ -30,18 +30,18 @@ namespace Lucene.Net.Index
 {
     
     /// <summary> An IndexReader which reads indexes with multiple segments.</summary>
-    public class DirectoryReader:IndexReader, System.ICloneable
+    public class DirectoryReader:IndexReader
     {
         /*new*/ private class AnonymousClassFindSegmentsFile:SegmentInfos.FindSegmentsFile
         {
-            private void  InitBlock(bool readOnly, Lucene.Net.Index.IndexDeletionPolicy deletionPolicy,
int termInfosIndexDivisor)
+            private void  InitBlock(bool readOnly, IndexDeletionPolicy deletionPolicy, int
termInfosIndexDivisor)
             {
                 this.readOnly = readOnly;
                 this.deletionPolicy = deletionPolicy;
                 this.termInfosIndexDivisor = termInfosIndexDivisor;
             }
             private bool readOnly;
-            private Lucene.Net.Index.IndexDeletionPolicy deletionPolicy;
+            private IndexDeletionPolicy deletionPolicy;
             private int termInfosIndexDivisor;
             internal AnonymousClassFindSegmentsFile(bool readOnly, Lucene.Net.Index.IndexDeletionPolicy
deletionPolicy, int termInfosIndexDivisor, Lucene.Net.Store.Directory Param1):base(Param1)
             {
@@ -49,7 +49,7 @@ namespace Lucene.Net.Index
             }
             public /*protected internal*/ override System.Object DoBody(System.String segmentFileName)
             {
-                SegmentInfos infos = new SegmentInfos();
+                var infos = new SegmentInfos();
                 infos.Read(directory, segmentFileName);
                 if (readOnly)
                     return new ReadOnlyDirectoryReader(directory, infos, deletionPolicy,
termInfosIndexDivisor);
@@ -80,7 +80,7 @@ namespace Lucene.Net.Index
             }
             public /*protected internal*/ override System.Object DoBody(System.String segmentFileName)
             {
-                SegmentInfos infos = new SegmentInfos();
+                var infos = new SegmentInfos();
                 infos.Read(directory, segmentFileName);
                 return Enclosing_Instance.DoReopen(infos, false, openReadOnly);
             }
@@ -91,12 +91,12 @@ namespace Lucene.Net.Index
         internal IndexWriter writer;
         
         private IndexDeletionPolicy deletionPolicy;
-        private System.Collections.Generic.HashSet<string> synced = new System.Collections.Generic.HashSet<string>();
+        private readonly HashSet<string> synced = new HashSet<string>();
         private Lock writeLock;
-        private SegmentInfos segmentInfos;
-        private SegmentInfos segmentInfosStart;
+        private readonly SegmentInfos segmentInfos;
+        private readonly SegmentInfos segmentInfosStart;
         private bool stale;
-        private int termInfosIndexDivisor;
+        private readonly int termInfosIndexDivisor;
         
         private bool rollbackHasChanges;
                 
@@ -120,7 +120,7 @@ namespace Lucene.Net.Index
         /// <summary>Construct reading the named set of readers. </summary>
         internal DirectoryReader(Directory directory, SegmentInfos sis, IndexDeletionPolicy
deletionPolicy, bool readOnly, int termInfosIndexDivisor)
         {
-            this.internalDirectory = directory;
+            internalDirectory = directory;
             this.readOnly = readOnly;
             this.segmentInfos = sis;
             this.deletionPolicy = deletionPolicy;
@@ -138,7 +138,7 @@ namespace Lucene.Net.Index
             // reverse because IndexWriter merges & deletes
             // the newest segments first.
             
-            SegmentReader[] readers = new SegmentReader[sis.Count];
+            var readers = new SegmentReader[sis.Count];
             for (int i = sis.Count - 1; i >= 0; i--)
             {
                 bool success = false;
@@ -189,7 +189,7 @@ namespace Lucene.Net.Index
             // us, which ensures infos will not change; so there's
             // no need to process segments in reverse order
             int numSegments = infos.Count;
-            SegmentReader[] readers = new SegmentReader[numSegments];
+            var readers = new SegmentReader[numSegments];
             Directory dir = writer.Directory;
             int upto = 0;
             
@@ -230,7 +230,7 @@ namespace Lucene.Net.Index
             if (upto < readers.Length)
             {
                 // This means some segments were in a foreign Directory
-                SegmentReader[] newReaders = new SegmentReader[upto];
+                var newReaders = new SegmentReader[upto];
                 Array.Copy(readers, 0, newReaders, 0, upto);
                 readers = newReaders;
             }
@@ -240,7 +240,7 @@ namespace Lucene.Net.Index
         
         /// <summary>This constructor is only used for <see cref="Reopen()" />
</summary>
         internal DirectoryReader(Directory directory, SegmentInfos infos, SegmentReader[]
oldReaders, int[] oldStarts,
-                                 System.Collections.Generic.IDictionary<string,byte[]>
oldNormsCache, bool readOnly, bool doClone, int termInfosIndexDivisor)
+                                 IEnumerable<KeyValuePair<string, byte[]>> oldNormsCache,
bool readOnly, bool doClone, int termInfosIndexDivisor)
         {
             this.internalDirectory = directory;
             this.readOnly = readOnly;
@@ -255,7 +255,7 @@ namespace Lucene.Net.Index
             
             // we put the old SegmentReaders in a map, that allows us
             // to lookup a reader using its segment name
-            System.Collections.Generic.IDictionary<string, int> segmentReaders = new
HashMap<string, int>();
+            IDictionary<string, int> segmentReaders = new HashMap<string, int>();
             
             if (oldReaders != null)
             {
@@ -266,11 +266,11 @@ namespace Lucene.Net.Index
                 }
             }
             
-            SegmentReader[] newReaders = new SegmentReader[infos.Count];
+            var newReaders = new SegmentReader[infos.Count];
             
             // remember which readers are shared between the old and the re-opened
             // DirectoryReader - we have to incRef those readers
-            bool[] readerShared = new bool[infos.Count];
+            var readerShared = new bool[infos.Count];
             
             for (int i = infos.Count - 1; i >= 0; i--)
             {
@@ -358,7 +358,7 @@ namespace Lucene.Net.Index
             {
                 foreach(var entry in oldNormsCache)
                 {
-                    System.String field = entry.Key;
+                    String field = entry.Key;
                     if (!HasNorms(field))
                     {
                         continue;
@@ -366,7 +366,7 @@ namespace Lucene.Net.Index
                     
                     byte[] oldBytes = entry.Value;
                     
-                    byte[] bytes = new byte[MaxDoc];
+                    var bytes = new byte[MaxDoc];
                     
                     for (int i = 0; i < subReaders.Length; i++)
                     {
@@ -413,7 +413,7 @@ namespace Lucene.Net.Index
             }
         }
         
-        public override System.Object Clone()
+        public override Object Clone()
         {
             lock (this)
             {
@@ -421,9 +421,9 @@ namespace Lucene.Net.Index
                 {
                     return Clone(readOnly); // Preserve current readOnly
                 }
-                catch (System.Exception ex)
+                catch (Exception ex)
                 {
-                    throw new System.SystemException(ex.Message, ex);
+                    throw new SystemException(ex.Message, ex); // TODO: why rethrow this
way?
                 }
             }
         }
@@ -572,9 +572,9 @@ namespace Lucene.Net.Index
 
         class AnonymousFindSegmentsFile : SegmentInfos.FindSegmentsFile
         {
-            DirectoryReader enclosingInstance;
-            bool openReadOnly;
-            Directory dir;
+        	readonly DirectoryReader enclosingInstance;
+        	readonly bool openReadOnly;
+        	readonly Directory dir;
             public AnonymousFindSegmentsFile(Directory directory, bool openReadOnly, DirectoryReader
dirReader) : base(directory)
             {
                 this.dir = directory;
@@ -584,8 +584,8 @@ namespace Lucene.Net.Index
 
             public override object DoBody(string segmentFileName)
             {
-                SegmentInfos infos = new SegmentInfos();
-                infos.Read(this.dir, segmentFileName);
+                var infos = new SegmentInfos();
+                infos.Read(dir, segmentFileName);
                 return enclosingInstance.DoReopen(infos, false, openReadOnly);
             }
         }
@@ -663,10 +663,8 @@ namespace Lucene.Net.Index
             if (numDocs == - 1)
             {
                 // check cache
-                int n = 0; // cache miss--recompute
-                for (int i = 0; i < subReaders.Length; i++)
-                    n += subReaders[i].NumDocs(); // sum from readers
-                numDocs = n;
+                int n = subReaders.Sum(t => t.NumDocs()); // cache miss--recompute
+            	numDocs = n;
             }
             return numDocs;
         }
@@ -714,10 +712,10 @@ namespace Lucene.Net.Index
         
         protected internal override void  DoUndeleteAll()
         {
-            for (int i = 0; i < subReaders.Length; i++)
-                subReaders[i].UndeleteAll();
-            
-            hasDeletions = false;
+            foreach (SegmentReader t in subReaders)
+            	t.UndeleteAll();
+
+        	hasDeletions = false;
             numDocs = - 1; // invalidate cache
         }
         
@@ -757,12 +755,7 @@ namespace Lucene.Net.Index
         public override bool HasNorms(System.String field)
         {
             EnsureOpen();
-            for (int i = 0; i < subReaders.Length; i++)
-            {
-                if (subReaders[i].HasNorms(field))
-                    return true;
-            }
-            return false;
+        	return subReaders.Any(t => t.HasNorms(field));
         }
         
         public override byte[] Norms(System.String field)
@@ -914,14 +907,14 @@ namespace Lucene.Net.Index
         /// 
         /// </summary>
         /// <throws>  IOException if there is a low-level IO error </throws>
-        protected internal override void DoCommit(System.Collections.Generic.IDictionary<string,
string> commitUserData)
+        protected internal override void DoCommit(IDictionary<string, string> commitUserData)
         {
             if (hasChanges)
             {
                 segmentInfos.UserData = commitUserData;
                 // Default deleter (for backwards compatibility) is
                 // KeepOnlyLastCommitDeleter:
-                IndexFileDeleter deleter = new IndexFileDeleter(internalDirectory, deletionPolicy
== null?new KeepOnlyLastCommitDeletionPolicy():deletionPolicy, segmentInfos, null, null, synced);
+                var deleter = new IndexFileDeleter(internalDirectory, deletionPolicy ?? new
KeepOnlyLastCommitDeletionPolicy(), segmentInfos, null, null, synced);
 
                 segmentInfos.UpdateGeneration(deleter.LastSegmentInfos);
 
@@ -932,10 +925,10 @@ namespace Lucene.Net.Index
                 bool success = false;
                 try
                 {
-                    for (int i = 0; i < subReaders.Length; i++)
-                        subReaders[i].Commit();
+                    foreach (SegmentReader t in subReaders)
+                    	t.Commit();
 
-                    // Sync all files we just wrote
+                	// Sync all files we just wrote
                     foreach(string fileName in segmentInfos.Files(internalDirectory, false))
                     {
                         if(!synced.Contains(fileName))
@@ -987,23 +980,23 @@ namespace Lucene.Net.Index
         
         internal virtual void  StartCommit()
         {
-            rollbackHasChanges = hasChanges;
-            for (int i = 0; i < subReaders.Length; i++)
-            {
-                subReaders[i].StartCommit();
-            }
-        }
-        
-        internal virtual void  RollbackCommit()
-        {
-            hasChanges = rollbackHasChanges;
-            for (int i = 0; i < subReaders.Length; i++)
-            {
-                subReaders[i].RollbackCommit();
-            }
-        }
+        	rollbackHasChanges = hasChanges;
+        	foreach (SegmentReader t in subReaders)
+        	{
+        		t.StartCommit();
+        	}
+        }
+
+    	internal virtual void  RollbackCommit()
+    	{
+    		hasChanges = rollbackHasChanges;
+    		foreach (SegmentReader t in subReaders)
+    		{
+    			t.RollbackCommit();
+    		}
+    	}
 
-        public override IDictionary<string, string> CommitUserData
+    	public override IDictionary<string, string> CommitUserData
         {
             get
             {
@@ -1032,24 +1025,24 @@ namespace Lucene.Net.Index
             {
                 System.IO.IOException ioe = null;
                 normsCache = null;
-                for (int i = 0; i < subReaders.Length; i++)
+                foreach (SegmentReader t in subReaders)
                 {
-                    // try to close each reader, even if an exception is thrown
-                    try
-                    {
-                        subReaders[i].DecRef();
-                    }
-                    catch (System.IO.IOException e)
-                    {
-                        if (ioe == null)
-                            ioe = e;
-                    }
+					// try to close each reader, even if an exception is thrown
+                	try
+                	{
+                		t.DecRef();
+                	}
+                	catch (System.IO.IOException e)
+                	{
+                		if (ioe == null)
+                			ioe = e;
+                	}
                 }
 
-                // NOTE: only needed in case someone had asked for
+            	// NOTE: only needed in case someone had asked for
                 // FieldCache for top-level reader (which is generally
                 // not a good idea):
-                Lucene.Net.Search.FieldCache_Fields.DEFAULT.Purge(this);
+                Search.FieldCache_Fields.DEFAULT.Purge(this);
 
                 // throw the first exception
                 if (ioe != null)
@@ -1057,16 +1050,16 @@ namespace Lucene.Net.Index
             }
         }
 
-        public override System.Collections.Generic.ICollection<string> GetFieldNames(IndexReader.FieldOption
fieldNames)
+        public override ICollection<string> GetFieldNames(IndexReader.FieldOption fieldNames)
         {
             EnsureOpen();
             return GetFieldNames(fieldNames, this.subReaders);
         }
 
-        internal static System.Collections.Generic.ICollection<string> GetFieldNames(IndexReader.FieldOption
fieldNames, IndexReader[] subReaders)
+        internal static ICollection<string> GetFieldNames(IndexReader.FieldOption fieldNames,
IndexReader[] subReaders)
         {
             // maintain a unique set of field names
-            System.Collections.Generic.ISet<string> fieldSet = Lucene.Net.Support.Compatibility.SetFactory.GetSet<string>();
+            ISet<string> fieldSet = Support.Compatibility.SetFactory.GetSet<string>();
             foreach (IndexReader reader in subReaders)
             {
                 fieldSet.UnionWith(reader.GetFieldNames(fieldNames));
@@ -1104,48 +1097,45 @@ namespace Lucene.Net.Index
 
         /// <seealso cref="Lucene.Net.Index.IndexReader.ListCommits">
         /// </seealso>
-        public static new System.Collections.Generic.ICollection<IndexCommit> ListCommits(Directory
dir)
+        public static new ICollection<IndexCommit> ListCommits(Directory dir)
         {
-            System.String[] files = dir.ListAll();
+            String[] files = dir.ListAll();
 
-            System.Collections.Generic.ICollection<IndexCommit> commits = new  System.Collections.Generic.List<IndexCommit>();
+            ICollection<IndexCommit> commits = new  List<IndexCommit>();
             
-            SegmentInfos latest = new SegmentInfos();
+            var latest = new SegmentInfos();
             latest.Read(dir);
             long currentGen = latest.Generation;
             
             commits.Add(new ReaderCommit(latest, dir));
             
-            for (int i = 0; i < files.Length; i++)
+            foreach (string fileName in files)
             {
-                
-                System.String fileName = files[i];
-                
-                if (fileName.StartsWith(IndexFileNames.SEGMENTS) && !fileName.Equals(IndexFileNames.SEGMENTS_GEN)
&& SegmentInfos.GenerationFromSegmentsFileName(fileName) < currentGen)
-                {
+            	if (fileName.StartsWith(IndexFileNames.SEGMENTS) && !fileName.Equals(IndexFileNames.SEGMENTS_GEN)
&& SegmentInfos.GenerationFromSegmentsFileName(fileName) < currentGen)
+            	{
                     
-                    SegmentInfos sis = new SegmentInfos();
-                    try
-                    {
-                        // IOException allowed to throw there, in case
-                        // segments_N is corrupt
-                        sis.Read(dir, fileName);
-                    }
-                    catch (System.IO.FileNotFoundException)
-                    {
-                        // LUCENE-948: on NFS (and maybe others), if
-                        // you have writers switching back and forth
-                        // between machines, it's very likely that the
-                        // dir listing will be stale and will claim a
-                        // file segments_X exists when in fact it
-                        // doesn't.  So, we catch this and handle it
-                        // as if the file does not exist
-                        sis = null;
-                    }
+            		var sis = new SegmentInfos();
+            		try
+            		{
+            			// IOException allowed to throw there, in case
+            			// segments_N is corrupt
+            			sis.Read(dir, fileName);
+            		}
+            		catch (System.IO.FileNotFoundException)
+            		{
+            			// LUCENE-948: on NFS (and maybe others), if
+            			// you have writers switching back and forth
+            			// between machines, it's very likely that the
+            			// dir listing will be stale and will claim a
+            			// file segments_X exists when in fact it
+            			// doesn't.  So, we catch this and handle it
+            			// as if the file does not exist
+            			sis = null;
+            		}
                     
-                    if (sis != null)
-                        commits.Add(new ReaderCommit(sis, dir));
-                }
+            		if (sis != null)
+            			commits.Add(new ReaderCommit(sis, dir));
+            	}
             }
             
             return commits;
@@ -1153,13 +1143,13 @@ namespace Lucene.Net.Index
         
         private sealed class ReaderCommit:IndexCommit
         {
-            private System.String segmentsFileName;
-            internal System.Collections.Generic.ICollection<string> files;
-            internal Directory dir;
-            internal long generation;
-            internal long version;
-            internal bool isOptimized;
-            internal System.Collections.Generic.IDictionary<string, string> userData;
+            private readonly String segmentsFileName;
+        	private readonly ICollection<string> files;
+        	private readonly Directory dir;
+        	private readonly long generation;
+        	private readonly long version;
+        	private readonly bool isOptimized;
+        	private readonly IDictionary<string, string> userData;
             
             internal ReaderCommit(SegmentInfos infos, Directory dir)
             {
@@ -1225,7 +1215,7 @@ namespace Lucene.Net.Index
         internal class MultiTermEnum:TermEnum
         {
             internal IndexReader topReader; // used for matching TermEnum to TermDocs
-            private SegmentMergeQueue queue;
+            private readonly SegmentMergeQueue queue;
             
             private Term term;
             private int docFreq;
@@ -1239,18 +1229,11 @@ namespace Lucene.Net.Index
                 for (int i = 0; i < readers.Length; i++)
                 {
                     IndexReader reader = readers[i];
-                    TermEnum termEnum;
-                    
-                    if (t != null)
-                    {
-                        termEnum = reader.Terms(t);
-                    }
-                    else
-                        termEnum = reader.Terms();
-                    
-                    SegmentMergeInfo smi = new SegmentMergeInfo(starts[i], termEnum, reader);
-                    smi.ord = i;
-                    if (t == null?smi.Next():termEnum.Term != null)
+
+                	TermEnum termEnum = t != null ? reader.Terms(t) : reader.Terms();
+
+                	var smi = new SegmentMergeInfo(starts[i], termEnum, reader) {ord = i};
+                	if (t == null?smi.Next():termEnum.Term != null)
                         queue.Add(smi);
                     // initialize queue
                     else
@@ -1265,15 +1248,14 @@ namespace Lucene.Net.Index
             
             public override bool Next()
             {
-                for (int i = 0; i < matchingSegments.Length; i++)
+                foreach (SegmentMergeInfo smi in matchingSegments)
                 {
-                    SegmentMergeInfo smi = matchingSegments[i];
-                    if (smi == null)
-                        break;
-                    if (smi.Next())
-                        queue.Add(smi);
-                    else
-                        smi.Dispose(); // done with segment
+                	if (smi == null)
+                		break;
+                	if (smi.Next())
+                		queue.Add(smi);
+                	else
+                		smi.Dispose(); // done with segment
                 }
                 
                 int numMatchingSegments = 0;
@@ -1331,7 +1313,7 @@ namespace Lucene.Net.Index
             protected internal int base_Renamed = 0;
             protected internal int pointer = 0;
             
-            private TermDocs[] readerTermDocs;
+            private readonly TermDocs[] readerTermDocs;
             protected internal TermDocs current; // == readerTermDocs[pointer]
             
             private MultiTermEnum tenum; // the term enum used for seeking... can be null
@@ -1371,12 +1353,13 @@ namespace Lucene.Net.Index
             public virtual void  Seek(TermEnum termEnum)
             {
                 Seek(termEnum.Term);
-                if (termEnum is MultiTermEnum)
-                {
-                    tenum = (MultiTermEnum) termEnum;
-                    if (topReader != tenum.topReader)
-                        tenum = null;
-                }
+            	var multiTermEnum = termEnum as MultiTermEnum;
+            	if (multiTermEnum != null)
+            	{
+            		tenum = multiTermEnum;
+            		if (topReader != tenum.topReader)
+            			tenum = null;
+            	}
             }
             
             public virtual bool Next()
@@ -1485,10 +1468,8 @@ namespace Lucene.Net.Index
             
             private TermDocs TermDocs(int i)
             {
-                TermDocs result = readerTermDocs[i];
-                if (result == null)
-                    result = readerTermDocs[i] = TermDocs(readers[i]);
-                if (smi != null)
+                TermDocs result = readerTermDocs[i] ?? (readerTermDocs[i] = TermDocs(readers[i]));
+            	if (smi != null)
                 {
                     System.Diagnostics.Debug.Assert((smi.ord == i));
                     System.Diagnostics.Debug.Assert((smi.termEnum.Term.Equals(term)));
@@ -1520,10 +1501,10 @@ namespace Lucene.Net.Index
             {
                 if (disposing)
                 {
-                    for (int i = 0; i < readerTermDocs.Length; i++)
+                    foreach (TermDocs t in readerTermDocs)
                     {
-                        if (readerTermDocs[i] != null)
-                            readerTermDocs[i].Close();
+                    	if (t != null)
+                    		t.Close();
                     }
                 }
             }

Modified: incubator/lucene.net/trunk/src/core/Index/DocInverter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/DocInverter.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/DocInverter.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/DocInverter.cs Mon Jul 30 22:30:43 2012
@@ -15,10 +15,8 @@
  * limitations under the License.
  */
 
-using System;
 using System.Collections.Generic;
 using Lucene.Net.Support;
-using AttributeSource = Lucene.Net.Util.AttributeSource;
 
 namespace Lucene.Net.Index
 {
@@ -55,13 +53,13 @@ namespace Lucene.Net.Index
 
             foreach (var entry in threadsAndFields)
 			{
-				DocInverterPerThread perThread = (DocInverterPerThread) entry.Key;
+				var perThread = (DocInverterPerThread) entry.Key;
 
 				ICollection<InvertedDocConsumerPerField> childFields = new HashSet<InvertedDocConsumerPerField>();
 				ICollection<InvertedDocEndConsumerPerField> endChildFields = new HashSet<InvertedDocEndConsumerPerField>();
 				foreach(DocFieldConsumerPerField field in entry.Value)
 				{
-                    DocInverterPerField perField = (DocInverterPerField)field;
+                    var perField = (DocInverterPerField)field;
 					childFields.Add(perField.consumer);
 					endChildFields.Add(perField.endConsumer);
 				}

Modified: incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/FieldInfos.cs Mon Jul 30 22:30:43 2012
@@ -33,7 +33,7 @@ namespace Lucene.Net.Index
 	/// be adding documents at a time, with no other reader or writer threads
 	/// accessing this object.
 	/// </summary>
-	public sealed class FieldInfos : System.ICloneable
+	public sealed class FieldInfos : ICloneable
 	{
 		
 		// Used internally (ie not written to *.fnm files) for pre-2.9 files
@@ -52,8 +52,8 @@ namespace Lucene.Net.Index
 		internal const byte STORE_PAYLOADS = (0x20);
 		internal const byte OMIT_TERM_FREQ_AND_POSITIONS = (0x40);
 
-        private System.Collections.Generic.List<FieldInfo> byNumber = new System.Collections.Generic.List<FieldInfo>();
-        private HashMap<string, FieldInfo> byName = new HashMap<string, FieldInfo>();
+        private readonly System.Collections.Generic.List<FieldInfo> byNumber = new
System.Collections.Generic.List<FieldInfo>();
+        private readonly HashMap<string, FieldInfo> byName = new HashMap<string,
FieldInfo>();
 		private int format;
 		
 		public /*internal*/ FieldInfos()
@@ -68,7 +68,7 @@ namespace Lucene.Net.Index
 		/// <param name="name">The name of the file to open the IndexInput from in the Directory
 		/// </param>
 		/// <throws>  IOException </throws>
-		public /*internal*/ FieldInfos(Directory d, System.String name)
+		public /*internal*/ FieldInfos(Directory d, String name)
 		{
 			IndexInput input = d.OpenInput(name);
 			try
@@ -94,7 +94,7 @@ namespace Lucene.Net.Index
 						{
 							Read(input, name);
 						}
-						catch (System.Exception)
+						catch (Exception)
                         {
                             // Ignore any new exception & set to throw original IOE
 						    rethrow = true;
@@ -120,15 +120,15 @@ namespace Lucene.Net.Index
 		}
 		
 		/// <summary> Returns a deep clone of this FieldInfos instance.</summary>
-		public System.Object Clone()
+		public Object Clone()
 		{
             lock (this)
             {
-                FieldInfos fis = new FieldInfos();
+                var fis = new FieldInfos();
                 int numField = byNumber.Count;
                 for (int i = 0; i < numField; i++)
                 {
-                    FieldInfo fi = (FieldInfo)byNumber[i].Clone();
+                    var fi = (FieldInfo)byNumber[i].Clone();
                     fis.byNumber.Add(fi);
                     fis.byName[fi.name] = fi;
                 }
@@ -218,7 +218,7 @@ namespace Lucene.Net.Index
 		/// </param>
         /// <seealso cref="Add(String, bool, bool, bool, bool)">
 		/// </seealso>
-		public void  Add(System.String name, bool isIndexed)
+		public void  Add(String name, bool isIndexed)
 		{
 			lock (this)
 			{
@@ -333,10 +333,10 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		private FieldInfo AddInternal(System.String name, bool isIndexed, bool storeTermVector,
bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads,
bool omitTermFreqAndPositions)
+		private FieldInfo AddInternal(String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector,
bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
 		{
 			name = StringHelper.Intern(name);
-			FieldInfo fi = new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector,
storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+			var fi = new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector,
storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
 			byNumber.Add(fi);
 			byName[name] = fi;
 			return fi;
@@ -417,7 +417,7 @@ namespace Lucene.Net.Index
 			for (int i = 0; i < Size(); i++)
 			{
 				FieldInfo fi = FieldInfo(i);
-				byte bits = (byte) (0x0);
+				var bits = (byte) (0x0);
 				if (fi.isIndexed)
 					bits |= IS_INDEXED;
 				if (fi.storeTermVector)
@@ -438,7 +438,7 @@ namespace Lucene.Net.Index
 			}
 		}
 		
-		private void  Read(IndexInput input, System.String fileName)
+		private void  Read(IndexInput input, String fileName)
 		{
 			int firstInt = input.ReadVInt();
 			
@@ -469,7 +469,7 @@ namespace Lucene.Net.Index
 			
 			for (int i = 0; i < size; i++)
 			{
-				System.String name = StringHelper.Intern(input.ReadString());
+				String name = StringHelper.Intern(input.ReadString());
 				byte bits = input.ReadByte();
 				bool isIndexed = (bits & IS_INDEXED) != 0;
 				bool storeTermVector = (bits & STORE_TERMVECTOR) != 0;

Modified: incubator/lucene.net/trunk/src/core/Index/FieldSortedTermVectorMapper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/FieldSortedTermVectorMapper.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/FieldSortedTermVectorMapper.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/FieldSortedTermVectorMapper.cs Mon Jul 30 22:30:43
2012
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-using System;
 using System.Collections.Generic;
 using Lucene.Net.Support;
 
@@ -28,10 +27,10 @@ namespace Lucene.Net.Index
 	/// </summary>
 	public class FieldSortedTermVectorMapper:TermVectorMapper
 	{
-        private IDictionary<string, SortedSet<TermVectorEntry>> fieldToTerms
= new HashMap<string, SortedSet<TermVectorEntry>>();
+        private readonly IDictionary<string, SortedSet<TermVectorEntry>> fieldToTerms
= new HashMap<string, SortedSet<TermVectorEntry>>();
 		private SortedSet<TermVectorEntry> currentSet;
 		private System.String currentField;
-        private IComparer<TermVectorEntry> comparator;
+        private readonly IComparer<TermVectorEntry> comparator;
 		
 		/// <summary> </summary>
 		/// <param name="comparator">A Comparator for sorting <see cref="TermVectorEntry"
/>s
@@ -50,13 +49,13 @@ namespace Lucene.Net.Index
 		
 		public override void  Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets,
int[] positions)
 		{
-			TermVectorEntry entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
+			var entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
 			currentSet.Add(entry);
 		}
 		
 		public override void  SetExpectations(System.String field, int numTerms, bool storeOffsets,
bool storePositions)
 		{
-			currentSet = new System.Collections.Generic.SortedSet<TermVectorEntry>(comparator);
+			currentSet = new SortedSet<TermVectorEntry>(comparator);
 			currentField = field;
 			fieldToTerms[field] = currentSet;
 		}

Modified: incubator/lucene.net/trunk/src/core/Index/FormatPostingsPositionsConsumer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/FormatPostingsPositionsConsumer.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/FormatPostingsPositionsConsumer.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/FormatPostingsPositionsConsumer.cs Mon Jul 30
22:30:43 2012
@@ -15,10 +15,6 @@
  * limitations under the License.
  */
 
-using System;
-
-using IndexInput = Lucene.Net.Store.IndexInput;
-
 namespace Lucene.Net.Index
 {
 	

Modified: incubator/lucene.net/trunk/src/core/Index/KeepOnlyLastCommitDeletionPolicy.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/KeepOnlyLastCommitDeletionPolicy.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/KeepOnlyLastCommitDeletionPolicy.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/KeepOnlyLastCommitDeletionPolicy.cs Mon Jul
30 22:30:43 2012
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-using System;
 using System.Collections.Generic;
 
 namespace Lucene.Net.Index

Modified: incubator/lucene.net/trunk/src/core/Index/MultiLevelSkipListReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/MultiLevelSkipListReader.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/MultiLevelSkipListReader.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/MultiLevelSkipListReader.cs Mon Jul 30 22:30:43
2012
@@ -34,7 +34,7 @@ namespace Lucene.Net.Index
 	abstract class MultiLevelSkipListReader : IDisposable
 	{
 		// the maximum number of skip levels possible for this index
-		private int maxNumberOfSkipLevels;
+		private readonly int maxNumberOfSkipLevels;
 		
 		// number of levels in this skip list
 		private int numberOfSkipLevels;
@@ -46,26 +46,26 @@ namespace Lucene.Net.Index
 		// the skipInterval. The top level can not contain more than
 		// skipLevel entries, the second top level can not contain more
 		// than skipLevel^2 entries and so forth.
-		private int numberOfLevelsToBuffer = 1;
-		
+		private const int numberOfLevelsToBuffer = 1;
+
 		private int docCount;
 		private bool haveSkipped;
 
 	    private bool isDisposed;
 		
-		private IndexInput[] skipStream; // skipStream for each level
-		private long[] skipPointer; // the start pointer of each skip level
-		private int[] skipInterval; // skipInterval of each level
-		private int[] numSkipped; // number of docs skipped per level
+		private readonly IndexInput[] skipStream; // skipStream for each level
+		private readonly long[] skipPointer; // the start pointer of each skip level
+		private readonly int[] skipInterval; // skipInterval of each level
+		private readonly int[] numSkipped; // number of docs skipped per level
 		
-		private int[] skipDoc; // doc id of current skip entry per level 
+		private readonly int[] skipDoc; // doc id of current skip entry per level 
 		private int lastDoc; // doc id of last read skip entry with docId <= target
-		private long[] childPointer; // child pointer of current skip entry per level
+		private readonly long[] childPointer; // child pointer of current skip entry per level
 		private long lastChildPointer; // childPointer of last read skip entry with docId <=
target
 		
-		private bool inputIsBuffered;
-		
-		public MultiLevelSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval)
+		private readonly bool inputIsBuffered;
+
+		protected MultiLevelSkipListReader(IndexInput skipStream, int maxSkipLevels, int skipInterval)
 		{
 			this.skipStream = new IndexInput[maxSkipLevels];
 			this.skipPointer = new long[maxSkipLevels];
@@ -282,7 +282,7 @@ namespace Lucene.Net.Index
 		private sealed class SkipBuffer : IndexInput
 		{
 			private byte[] data;
-			private long pointer;
+			private readonly long pointer;
 			private int pos;
 
 		    private bool isDisposed;

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentInfos.cs Mon Jul 30 22:30:43 2012
@@ -269,7 +269,7 @@ namespace Lucene.Net.Index
 			// Clear any previous segments:
 			Clear();
 			
-			ChecksumIndexInput input = new ChecksumIndexInput(directory.OpenInput(segmentFileName));
+			var input = new ChecksumIndexInput(directory.OpenInput(segmentFileName));
 			
 			generation = GenerationFromSegmentsFileName(segmentFileName);
 			
@@ -318,8 +318,7 @@ namespace Lucene.Net.Index
 					else if (0 != input.ReadByte())
 					{
                         // TODO: Should be read-only map
-                        userData = new HashMap<string,string>();
-						userData.Add("userData", input.ReadString());
+                        userData = new HashMap<string,string> {{"userData", input.ReadString()}};
 					}
 					else
 					{
@@ -386,7 +385,7 @@ namespace Lucene.Net.Index
 				generation++;
 			}
 			
-			ChecksumIndexOutput segnOutput = new ChecksumIndexOutput(directory.CreateOutput(segmentFileName));
+			var segnOutput = new ChecksumIndexOutput(directory.CreateOutput(segmentFileName));
 			
 			bool success = false;
 			
@@ -480,7 +479,7 @@ namespace Lucene.Net.Index
             // IndexWriter.prepareCommit has been called (but not
             // yet commit), then the reader will still see itself as
             // current:
-            SegmentInfos sis = new SegmentInfos();
+            var sis = new SegmentInfos();
             sis.Read(directory);
             return sis.version;
 			//return (long) ((System.Int64) new AnonymousClassFindSegmentsFile1(directory).Run());
@@ -492,7 +491,7 @@ namespace Lucene.Net.Index
 		/// <throws>  IOException if there is a low-level IO error </throws>
         public static System.Collections.Generic.IDictionary<string, string> ReadCurrentUserData(Directory
directory)
 		{
-			SegmentInfos sis = new SegmentInfos();
+			var sis = new SegmentInfos();
 			sis.Read(directory);
 			return sis.UserData;
 		}
@@ -684,7 +683,7 @@ namespace Lucene.Net.Index
 								}
 							}
 							
-                            System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64)
10000 * Lucene.Net.Index.SegmentInfos.defaultGenFileRetryPauseMsec));
+                            System.Threading.Thread.Sleep(new TimeSpan((System.Int64) 10000
* Lucene.Net.Index.SegmentInfos.defaultGenFileRetryPauseMsec));
 							
 							
 						}
@@ -985,7 +984,7 @@ namespace Lucene.Net.Index
 		{
 			lock (this)
 			{
-				System.Text.StringBuilder buffer = new System.Text.StringBuilder();
+				var buffer = new System.Text.StringBuilder();
 				int count = Count;
 				for (int i = 0; i < count; i++)
 				{
@@ -1042,7 +1041,7 @@ namespace Lucene.Net.Index
         {
             if (obj == null) return false;
 
-            SegmentInfos objToCompare = obj as SegmentInfos;
+            var objToCompare = obj as SegmentInfos;
             if (objToCompare == null) return false;
 
             if (this.Count != objToCompare.Count) return false;

Modified: incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SegmentTermDocs.cs Mon Jul 30 22:30:43 2012
@@ -33,8 +33,8 @@ namespace Lucene.Net.Index
 		internal int doc = 0;
 		internal int freq;
 		
-		private int skipInterval;
-		private int maxSkipLevels;
+		private readonly int skipInterval;
+		private readonly int maxSkipLevels;
 		private DefaultSkipListReader skipListReader;
 		
 		private long freqBasePointer;
@@ -75,7 +75,7 @@ namespace Lucene.Net.Index
 			if (termEnum is SegmentTermEnum && ((SegmentTermEnum) termEnum).fieldInfos ==
parent.core.fieldInfos)
 			{
 				// optimized case
-				SegmentTermEnum segmentTermEnum = ((SegmentTermEnum) termEnum);
+				var segmentTermEnum = ((SegmentTermEnum) termEnum);
 				term = segmentTermEnum.Term;
 				ti = segmentTermEnum.TermInfo();
 			}

Modified: incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/SerialMergeScheduler.cs Mon Jul 30 22:30:43
2012
@@ -15,8 +15,6 @@
  * limitations under the License.
  */
 
-using System;
-
 namespace Lucene.Net.Index
 {
 	

Modified: incubator/lucene.net/trunk/src/core/Index/TermVectorsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/core/Index/TermVectorsWriter.cs?rev=1367344&r1=1367343&r2=1367344&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/core/Index/TermVectorsWriter.cs (original)
+++ incubator/lucene.net/trunk/src/core/Index/TermVectorsWriter.cs Mon Jul 30 22:30:43 2012
@@ -27,9 +27,11 @@ namespace Lucene.Net.Index
 	sealed class TermVectorsWriter : IDisposable
 	{
 		
-		private IndexOutput tvx = null, tvd = null, tvf = null;
-		private FieldInfos fieldInfos;
-		internal UnicodeUtil.UTF8Result[] utf8Results = new UnicodeUtil.UTF8Result[]{new UnicodeUtil.UTF8Result(),
new UnicodeUtil.UTF8Result()};
+		private readonly IndexOutput tvx = null;
+		private readonly IndexOutput tvd = null;
+		private readonly IndexOutput tvf = null;
+		private readonly FieldInfos fieldInfos;
+		internal UnicodeUtil.UTF8Result[] utf8Results = new[]{new UnicodeUtil.UTF8Result(), new
UnicodeUtil.UTF8Result()};
 		
 		public TermVectorsWriter(Directory directory, System.String segment, FieldInfos fieldInfos)
 		{
@@ -62,7 +64,7 @@ namespace Lucene.Net.Index
 				int numFields = vectors.Length;
 				tvd.WriteVInt(numFields);
 				
-				long[] fieldPointers = new long[numFields];
+				var fieldPointers = new long[numFields];
 				
 				for (int i = 0; i < numFields; i++)
 				{
@@ -131,9 +133,8 @@ namespace Lucene.Net.Index
 							
 							// use delta encoding for positions
 							int lastPosition = 0;
-							for (int k = 0; k < positions.Length; k++)
+							foreach (int position in positions)
 							{
-								int position = positions[k];
 								tvf.WriteVInt(position - lastPosition);
 								lastPosition = position;
 							}
@@ -148,10 +149,10 @@ namespace Lucene.Net.Index
 							
 							// use delta encoding for offsets
 							int lastEndOffset = 0;
-							for (int k = 0; k < offsets.Length; k++)
+							foreach (TermVectorOffsetInfo t in offsets)
 							{
-								int startOffset = offsets[k].StartOffset;
-								int endOffset = offsets[k].EndOffset;
+								int startOffset = t.StartOffset;
+								int endOffset = t.EndOffset;
 								tvf.WriteVInt(startOffset - lastEndOffset);
 								tvf.WriteVInt(endOffset - startOffset);
 								lastEndOffset = endOffset;
@@ -214,8 +215,7 @@ namespace Lucene.Net.Index
 				}
 				catch (System.IO.IOException e)
 				{
-					if (keep == null)
-						keep = e;
+					keep = e;
 				}
 			if (tvd != null)
 				try



Mime
View raw message