lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r432239 [2/8] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/DemoLib/HTML/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Analysis/Standard/ Lucene.Net/Docume...
Date Thu, 17 Aug 2006 13:49:32 GMT
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/MultiReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/MultiReader.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/MultiReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/MultiReader.cs Thu Aug 17 06:49:26 2006
@@ -131,7 +131,7 @@
 		{
 			numDocs = - 1; // invalidate cache
 			int i = ReaderIndex(n); // find segment num
-			subReaders[i].Delete(n - starts[i]); // dispatch to segment reader
+			subReaders[i].DeleteDocument(n - starts[i]); // dispatch to segment reader
 			hasDeletions = true;
 		}
 		
@@ -271,73 +271,6 @@
 				for (int i = 0; i < subReaders.Length; i++)
 					subReaders[i].Close();
 			}
-		}
-		
-		/// <seealso cref="IndexReader.GetFieldNames()">
-		/// </seealso>
-		public override System.Collections.ICollection GetFieldNames()
-		{
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < subReaders.Length; i++)
-			{
-				IndexReader reader = subReaders[i];
-				System.Collections.ICollection names = reader.GetFieldNames();
-                for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext(); )
-                {
-                    System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) iterator.Current;
-                    System.String s = fi.Key.ToString();
-                    if (fieldSet.ContainsKey(s) == false)
-                    {
-                        fieldSet.Add(s, s);
-                    }
-                }
-            }
-			return fieldSet;
-		}
-		
-		/// <seealso cref="IndexReader.GetFieldNames(boolean)">
-		/// </seealso>
-		public override System.Collections.ICollection GetFieldNames(bool indexed)
-		{
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < subReaders.Length; i++)
-			{
-				IndexReader reader = subReaders[i];
-				System.Collections.ICollection names = reader.GetFieldNames(indexed);
-                for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext(); )
-                {
-                    System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) iterator.Current;
-                    System.String s = fi.Key.ToString();
-                    if (fieldSet.ContainsKey(s) == false)
-                    {
-                        fieldSet.Add(s, s);
-                    }
-                }
-            }
-			return fieldSet;
-		}
-		
-		public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
-		{
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < subReaders.Length; i++)
-			{
-				IndexReader reader = subReaders[i];
-				System.Collections.ICollection names = reader.GetIndexedFieldNames(tvSpec);
-                for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext(); )
-                {
-                    System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) iterator.Current;
-                    System.String s = fi.Key.ToString();
-                    if (fieldSet.ContainsKey(s) == false)
-                    {
-                        fieldSet.Add(s, s);
-                    }
-                }
-            }
-			return fieldSet;
 		}
 		
 		/// <seealso cref="IndexReader.GetFieldNames(IndexReader.FieldOption)">

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ParallelReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/ParallelReader.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ParallelReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/ParallelReader.cs Thu Aug 17 06:49:26 2006
@@ -130,7 +130,7 @@
 		{
 			for (int i = 0; i < readers.Count; i++)
 			{
-				((IndexReader) readers[i]).DoDelete(n);
+				((IndexReader) readers[i]).DeleteDocument(n);
 			}
 			hasDeletions = true;
 		}
@@ -140,7 +140,7 @@
 		{
 			for (int i = 0; i < readers.Count; i++)
 			{
-				((IndexReader) readers[i]).DoUndeleteAll();
+				((IndexReader) readers[i]).UndeleteAll();
 			}
 			hasDeletions = false;
 		}
@@ -152,10 +152,9 @@
 			for (int i = 0; i < storedFieldReaders.Count; i++)
 			{
 				IndexReader reader = (IndexReader) storedFieldReaders[i];
-				System.Collections.IEnumerator fields = reader.Document(n).Fields();
-				while (fields.MoveNext())
+                foreach(Field field in reader.Document(n).Fields())
 				{
-					result.Add((Field) fields.Current);
+					result.Add(field);
 				}
 			}
 			return result;
@@ -169,9 +168,11 @@
 			while (i.MoveNext())
 			{
 				System.Collections.DictionaryEntry e = (System.Collections.DictionaryEntry) i.Current;
-				IndexReader reader = (IndexReader) e.Key;
-				System.String field = (System.String) e.Value;
-				TermFreqVector vector = reader.GetTermFreqVector(n, field);
+				//IndexReader reader = (IndexReader) e.Key;         // {{Aroush}} which is right, those two lines?
+				//System.String field = (System.String) e.Value;
+                System.String field = (System.String) e.Key;        // {{Aroush-2.0}} or those two lines?
+                IndexReader reader = (IndexReader) e.Value;
+                TermFreqVector vector = reader.GetTermFreqVector(n, field);
 				if (vector != null)
 					results.Add(vector);
 			}
@@ -180,28 +181,35 @@
 		
 		public override TermFreqVector GetTermFreqVector(int n, System.String field)
 		{
-			return ((IndexReader) fieldToReader[field]).GetTermFreqVector(n, field);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[field]);
+            return reader == null ? null : reader.GetTermFreqVector(n, field);
+        }
 		
 		public override bool HasNorms(System.String field)
 		{
-			return ((IndexReader) fieldToReader[field]).HasNorms(field);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[field]);
+            return reader == null ? false : reader.HasNorms(field);
+        }
 		
 		public override byte[] Norms(System.String field)
 		{
-			return ((IndexReader) fieldToReader[field]).Norms(field);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[field]);
+            return reader == null ? null : reader.Norms(field);
+        }
 		
 		public override void  Norms(System.String field, byte[] result, int offset)
 		{
-			((IndexReader) fieldToReader[field]).Norms(field, result, offset);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[field]);
+            if (reader != null)
+                reader.Norms(field, result, offset);
+        }
 		
 		protected internal override void  DoSetNorm(int n, System.String field, byte value_Renamed)
 		{
-			((IndexReader) fieldToReader[field]).DoSetNorm(n, field, value_Renamed);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[field]);
+            if (reader != null)
+                reader.DoSetNorm(n, field, value_Renamed);
+        }
 		
 		public override TermEnum Terms()
 		{
@@ -215,8 +223,9 @@
 		
 		public override int DocFreq(Term term)
 		{
-			return ((IndexReader) fieldToReader[term.Field()]).DocFreq(term);
-		}
+            IndexReader reader = ((IndexReader) fieldToReader[term.Field()]);
+            return reader == null ? 0 : reader.DocFreq(term);
+        }
 		
 		public override TermDocs TermDocs(Term term)
 		{
@@ -253,58 +262,8 @@
 			}
 		}
 		
-		public override System.Collections.ICollection GetFieldNames()
-		{
-            System.Collections.Hashtable result = new System.Collections.Hashtable(fieldToReader.Count);
-            System.Collections.ICollection items = fieldToReader.Keys;
-            foreach (object item in items)
-            {
-                result.Add(item, item);
-            }
-            return result;
-		}
-		
-		public override System.Collections.ICollection GetFieldNames(bool indexed)
-		{
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < readers.Count; i++)
-			{
-				IndexReader reader = ((IndexReader) readers[i]);
-				System.Collections.ICollection names = reader.GetFieldNames(indexed);
-                for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext(); )
-                {
-                    System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) iterator.Current;
-                    System.String s = fi.Key.ToString();
-                    if (fieldSet.ContainsKey(s) == false)
-                    {
-                        fieldSet.Add(s, s);
-                    }
-                }
-			}
-			return fieldSet;
-		}
 		
-		public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
-		{
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < readers.Count; i++)
-			{
-				IndexReader reader = ((IndexReader) readers[i]);
-				System.Collections.ICollection names = reader.GetIndexedFieldNames(tvSpec);
-                for (System.Collections.IEnumerator iterator = names.GetEnumerator(); iterator.MoveNext(); )
-                {
-                    System.Collections.DictionaryEntry fi = (System.Collections.DictionaryEntry) iterator.Current;
-                    System.String s = fi.Key.ToString();
-                    if (fieldSet.ContainsKey(s) == false)
-                    {
-                        fieldSet.Add(s, s);
-                    }
-                }
-            }
-			return fieldSet;
-		}
-		
-		public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldNames)
+        public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldNames)
 		{
             System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
             for (int i = 0; i < readers.Count; i++)
@@ -354,12 +313,14 @@
 			{
 				InitBlock(enclosingInstance);
 				field = term.Field();
-				termEnum = ((IndexReader) Enclosing_Instance.fieldToReader[field]).Terms(term);
-			}
+                IndexReader reader = ((IndexReader) Enclosing_Instance.fieldToReader[field]);
+                if (reader != null)
+                    termEnum = reader.Terms(term);
+            }
 			
 			public override bool Next()
 			{
-				if (field == null)
+				if (termEnum == null)
 					return false;
 				
 				bool next = termEnum.Next();
@@ -383,15 +344,22 @@
 			
 			public override Term Term()
 			{
-				return termEnum.Term();
+                if (termEnum == null)
+                    return null;
+				
+                return termEnum.Term();
 			}
 			public override int DocFreq()
 			{
-				return termEnum.DocFreq();
+                if (termEnum == null)
+                    return 0;
+				
+                return termEnum.DocFreq();
 			}
 			public override void  Close()
 			{
-				termEnum.Close();
+                if (termEnum != null)
+                    termEnum.Close();
 			}
 		}
 		
@@ -434,8 +402,9 @@
 			
 			public virtual void  Seek(Term term)
 			{
-				termDocs = ((IndexReader) Enclosing_Instance.fieldToReader[term.Field()]).TermDocs(term);
-			}
+                IndexReader reader = ((IndexReader) Enclosing_Instance.fieldToReader[term.Field()]);
+                termDocs = reader != null ? reader.TermDocs(term) : null;
+            }
 			
 			public virtual void  Seek(TermEnum termEnum)
 			{
@@ -444,22 +413,32 @@
 			
 			public virtual bool Next()
 			{
-				return termDocs.Next();
+                if (termDocs == null)
+                    return false;
+				
+                return termDocs.Next();
 			}
 			
 			public virtual int Read(int[] docs, int[] freqs)
 			{
-				return termDocs.Read(docs, freqs);
+                if (termDocs == null)
+                    return 0;
+				
+                return termDocs.Read(docs, freqs);
 			}
 			
 			public virtual bool SkipTo(int target)
 			{
-				return termDocs.SkipTo(target);
+                if (termDocs == null)
+                    return false;
+				
+                return termDocs.SkipTo(target);
 			}
 			
 			public virtual void  Close()
 			{
-				termDocs.Close();
+                if (termDocs != null)
+                    termDocs.Close();
 			}
 		}
 		
@@ -491,11 +470,13 @@
 			
 			public override void  Seek(Term term)
 			{
-				termDocs = ((IndexReader) Enclosing_Instance.fieldToReader[term.Field()]).TermPositions(term);
-			}
+                IndexReader reader = ((IndexReader) Enclosing_Instance.fieldToReader[term.Field()]);
+                termDocs = reader != null ? reader.TermPositions(term) : null;
+            }
 			
 			public virtual int NextPosition()
 			{
+				// It is an error to call this if there is no next position, e.g. if termDocs==null
 				return ((TermPositions) termDocs).NextPosition();
 			}
 		}

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentMerger.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentMerger.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentMerger.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentMerger.cs Thu Aug 17 06:49:26 2006
@@ -379,7 +379,7 @@
 					doc += base_Renamed; // convert to merged space
 					
 					if (doc < lastDoc)
-						throw new System.SystemException("docs out of order");
+						throw new System.SystemException("docs out of order (" + doc + " < " + lastDoc + " )");
 					
 					df++;
 					

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentReader.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs Thu Aug 17 06:49:26 2006
@@ -26,701 +26,610 @@
 namespace Lucene.Net.Index
 {
 	
-	/// <version>  $Id: SegmentReader.java 329523 2005-10-30 05:37:11Z yonik $
-	/// </version>
-	public class SegmentReader : IndexReader
-	{
-		private System.String segment;
-		
-		internal FieldInfos fieldInfos;
-		private FieldsReader fieldsReader;
-		
-		internal TermInfosReader tis;
-		internal TermVectorsReader termVectorsReaderOrig = null;
-		internal System.LocalDataStoreSlot termVectorsLocal = System.Threading.Thread.AllocateDataSlot();
-		
-		internal BitVector deletedDocs = null;
-		private bool deletedDocsDirty = false;
-		private bool normsDirty = false;
-		private bool undeleteAll = false;
+    /// <version>  $Id: SegmentReader.java 329523 2005-10-30 05:37:11Z yonik $
+    /// </version>
+    public class SegmentReader : IndexReader
+    {
+        private System.String segment;
+		
+        internal FieldInfos fieldInfos;
+        private FieldsReader fieldsReader;
+		
+        internal TermInfosReader tis;
+        internal TermVectorsReader termVectorsReaderOrig = null;
+        internal System.LocalDataStoreSlot termVectorsLocal = System.Threading.Thread.AllocateDataSlot();
+		
+        internal BitVector deletedDocs = null;
+        private bool deletedDocsDirty = false;
+        private bool normsDirty = false;
+        private bool undeleteAll = false;
 		
-		internal IndexInput freqStream;
-		internal IndexInput proxStream;
+        internal IndexInput freqStream;
+        internal IndexInput proxStream;
 		
-		// Compound File Reader when based on a compound file segment
-		internal CompoundFileReader cfsReader = null;
+        // Compound File Reader when based on a compound file segment
+        internal CompoundFileReader cfsReader = null;
 		
         public FieldInfos FieldInfos
         {
             get {   return fieldInfos;  }
         }
 
-		private class Norm
-		{
-			private void  InitBlock(SegmentReader enclosingInstance)
-			{
-				this.enclosingInstance = enclosingInstance;
-			}
-			private SegmentReader enclosingInstance;
-			public SegmentReader Enclosing_Instance
-			{
-				get
-				{
-					return enclosingInstance;
-				}
+        private class Norm
+        {
+            private void  InitBlock(SegmentReader enclosingInstance)
+            {
+                this.enclosingInstance = enclosingInstance;
+            }
+            private SegmentReader enclosingInstance;
+            public SegmentReader Enclosing_Instance
+            {
+                get
+                {
+                    return enclosingInstance;
+                }
 				
-			}
-			public Norm(SegmentReader enclosingInstance, IndexInput in_Renamed, int number)
-			{
-				InitBlock(enclosingInstance);
-				this.in_Renamed = in_Renamed;
-				this.number = number;
-			}
-			
-			public IndexInput in_Renamed;
-			public byte[] bytes;
-			public bool dirty;
-			public int number;
-			
-			public void  ReWrite()
-			{
-				// NOTE: norms are re-written in regular directory, not cfs
-				IndexOutput out_Renamed = Enclosing_Instance.Directory().CreateOutput(Enclosing_Instance.segment + ".tmp");
-				try
-				{
-					out_Renamed.WriteBytes(bytes, Enclosing_Instance.MaxDoc());
-				}
-				finally
-				{
-					out_Renamed.Close();
-				}
-				System.String fileName;
-				if (Enclosing_Instance.cfsReader == null)
-					fileName = Enclosing_Instance.segment + ".f" + number;
-				else
-				{
-					// use a different file name if we have compound format
-					fileName = Enclosing_Instance.segment + ".s" + number;
-				}
-				Enclosing_Instance.Directory().RenameFile(Enclosing_Instance.segment + ".tmp", fileName);
-				this.dirty = false;
-			}
-		}
-		
-		private System.Collections.Hashtable norms = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
-		
-		/// <summary>The class which implements SegmentReader. </summary>
-		private static System.Type IMPL;
-		
-		public SegmentReader() : base(null)
-		{
-		}
-		
-		public static SegmentReader Get(SegmentInfo si)
-		{
-			return Get(si.dir, si, null, false, false);
-		}
-		
-		public static SegmentReader Get(SegmentInfos sis, SegmentInfo si, bool closeDir)
-		{
-			return Get(si.dir, si, sis, closeDir, true);
-		}
-		
-		public static SegmentReader Get(Directory dir, SegmentInfo si, SegmentInfos sis, bool closeDir, bool ownDir)
-		{
-			SegmentReader instance;
-			try
-			{
-				instance = (SegmentReader) System.Activator.CreateInstance(IMPL);
-			}
-			catch (System.Exception e)
-			{
-				throw new System.SystemException("cannot load SegmentReader class: " + e);
-			}
-			instance.Init(dir, sis, closeDir, ownDir);
-			instance.Initialize(si);
-			return instance;
-		}
-		
-		private void  Initialize(SegmentInfo si)
-		{
-			segment = si.name;
-			
-			// Use compound file directory for some files, if it exists
-			Directory cfsDir = Directory();
-			if (Directory().FileExists(segment + ".cfs"))
-			{
-				cfsReader = new CompoundFileReader(Directory(), segment + ".cfs");
-				cfsDir = cfsReader;
-			}
-			
-			// No compound file exists - use the multi-file format
-			fieldInfos = new FieldInfos(cfsDir, segment + ".fnm");
-			fieldsReader = new FieldsReader(cfsDir, segment, fieldInfos);
-			
-			tis = new TermInfosReader(cfsDir, segment, fieldInfos);
-			
-			// NOTE: the bitvector is stored using the regular directory, not cfs
-			if (HasDeletions(si))
-				deletedDocs = new BitVector(Directory(), segment + ".del");
-			
-			// make sure that all index files have been read or are kept open
-			// so that if an index update removes them we'll still have them
-			freqStream = cfsDir.OpenInput(segment + ".frq");
-			proxStream = cfsDir.OpenInput(segment + ".prx");
-			OpenNorms(cfsDir);
-			
-			if (fieldInfos.HasVectors())
-			{
-				// open term vector files only as needed
-				termVectorsReaderOrig = new TermVectorsReader(cfsDir, segment, fieldInfos);
-			}
-		}
-		
-		~SegmentReader()
-		{
-			// patch for pre-1.4.2 JVMs, whose ThreadLocals leak
-			//System.Threading.Thread.SetData(termVectorsLocal, null);
-		}
-		
-		protected internal override void  DoCommit()
-		{
-			if (deletedDocsDirty)
-			{
-				// re-write deleted
-				deletedDocs.Write(Directory(), segment + ".tmp");
-				Directory().RenameFile(segment + ".tmp", segment + ".del");
-			}
-			if (undeleteAll && Directory().FileExists(segment + ".del"))
-			{
-				Directory().DeleteFile(segment + ".del");
-			}
-			if (normsDirty)
-			{
-				// re-write norms
-				System.Collections.IEnumerator values = norms.Values.GetEnumerator();
-				while (values.MoveNext())
-				{
-					Norm norm = (Norm) values.Current;
-					if (norm.dirty)
-					{
-						norm.ReWrite();
-					}
-				}
-			}
-			deletedDocsDirty = false;
-			normsDirty = false;
-			undeleteAll = false;
-		}
-		
-		protected internal override void  DoClose()
-		{
-			fieldsReader.Close();
-			tis.Close();
-			
-			if (freqStream != null)
-				freqStream.Close();
-			if (proxStream != null)
-				proxStream.Close();
-			
-			CloseNorms();
-			
-			if (termVectorsReaderOrig != null)
-				termVectorsReaderOrig.Close();
-			
-			if (cfsReader != null)
-				cfsReader.Close();
-		}
-		
-		internal static bool HasDeletions(SegmentInfo si)
-		{
-			return si.dir.FileExists(si.name + ".del");
-		}
-		
-		public override bool HasDeletions()
-		{
-			return deletedDocs != null;
-		}
-		
-		
-		internal static bool UsesCompoundFile(SegmentInfo si)
-		{
-			return si.dir.FileExists(si.name + ".cfs");
-		}
-		
-		internal static bool HasSeparateNorms(SegmentInfo si)
-		{
-			System.String[] result = si.dir.List();
-			System.String pattern = si.name + ".s";
-			int patternLength = pattern.Length;
-			for (int i = 0; i < result.Length; i++)
-			{
-				if (result[i].StartsWith(pattern) && System.Char.IsDigit(result[i][patternLength]))
-					return true;
-			}
-			return false;
-		}
-		
-		protected internal override void  DoDelete(int docNum)
-		{
-			if (deletedDocs == null)
-				deletedDocs = new BitVector(MaxDoc());
-			deletedDocsDirty = true;
-			undeleteAll = false;
-			deletedDocs.Set(docNum);
-		}
-		
-		protected internal override void  DoUndeleteAll()
-		{
-			deletedDocs = null;
-			deletedDocsDirty = false;
-			undeleteAll = true;
-		}
-		
-		internal virtual System.Collections.ArrayList Files()
-		{
-			System.Collections.ArrayList files = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(16));
-			
-			for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
-			{
-				System.String name = segment + "." + IndexFileNames.INDEX_EXTENSIONS[i];
-				if (Directory().FileExists(name))
-					files.Add(name);
-			}
-			
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fi.isIndexed && !fi.omitNorms)
-				{
-					System.String name;
-					if (cfsReader == null)
-						name = segment + ".f" + i;
-					else
-						name = segment + ".s" + i;
-					if (Directory().FileExists(name))
-						files.Add(name);
-				}
-			}
-			return files;
-		}
-		
-		public override TermEnum Terms()
-		{
-			return tis.Terms();
-		}
-		
-		public override TermEnum Terms(Term t)
-		{
-			return tis.Terms(t);
-		}
-		
-		public override Document Document(int n)
-		{
-			lock (this)
-			{
-				if (IsDeleted(n))
-					throw new System.ArgumentException("attempt to access a deleted document");
-				return fieldsReader.Doc(n);
-			}
-		}
-		
-		public override bool IsDeleted(int n)
-		{
-			lock (this)
-			{
-				return (deletedDocs != null && deletedDocs.Get(n));
-			}
-		}
-		
-		public override TermDocs TermDocs()
-		{
-			return new SegmentTermDocs(this);
-		}
-		
-		public override TermPositions TermPositions()
-		{
-			return new SegmentTermPositions(this);
-		}
-		
-		public override int DocFreq(Term t)
-		{
-			TermInfo ti = tis.Get(t);
-			if (ti != null)
-				return ti.docFreq;
-			else
-				return 0;
-		}
-		
-		public override int NumDocs()
-		{
-			int n = MaxDoc();
-			if (deletedDocs != null)
-				n -= deletedDocs.Count();
-			return n;
-		}
-		
-		public override int MaxDoc()
-		{
-			return fieldsReader.Size();
-		}
-		
-		/// <seealso cref="IndexReader.GetFieldNames()">
-		/// </seealso>
-		/// <deprecated>  Replaced by {@link #GetFieldNames (IndexReader.FieldOption fldOption)}
-		/// </deprecated>
-		public override System.Collections.ICollection GetFieldNames()
-		{
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				fieldSet.Add(fi.name, fi.name);
-			}
-			return fieldSet;
-		}
-		
-		/// <seealso cref="IndexReader.GetFieldNames(boolean)">
-		/// </seealso>
-		/// <deprecated>  Replaced by {@link #GetFieldNames (IndexReader.FieldOption fldOption)}
-		/// </deprecated>
-		public override System.Collections.ICollection GetFieldNames(bool indexed)
-		{
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fi.isIndexed == indexed)
-					fieldSet.Add(fi.name, fi.name);
-			}
-			return fieldSet;
-		}
-		
-		/// <seealso cref="IndexReader.GetIndexedFieldNames(Field.TermVector tvSpec)">
-		/// </seealso>
-		/// <deprecated>  Replaced by {@link #GetFieldNames (IndexReader.FieldOption fldOption)}
-		/// </deprecated>
-		public override System.Collections.ICollection GetIndexedFieldNames(Field.TermVector tvSpec)
-		{
-			bool storedTermVector;
-			bool storePositionWithTermVector;
-			bool storeOffsetWithTermVector;
-			
-			if (tvSpec == Field.TermVector.NO)
-			{
-				storedTermVector = false;
-				storePositionWithTermVector = false;
-				storeOffsetWithTermVector = false;
-			}
-			else if (tvSpec == Field.TermVector.YES)
-			{
-				storedTermVector = true;
-				storePositionWithTermVector = false;
-				storeOffsetWithTermVector = false;
-			}
-			else if (tvSpec == Field.TermVector.WITH_POSITIONS)
-			{
-				storedTermVector = true;
-				storePositionWithTermVector = true;
-				storeOffsetWithTermVector = false;
-			}
-			else if (tvSpec == Field.TermVector.WITH_OFFSETS)
-			{                                                                           
-				storedTermVector = true;
-				storePositionWithTermVector = false;
-				storeOffsetWithTermVector = true;
-			}
-			else if (tvSpec == Field.TermVector.WITH_POSITIONS_OFFSETS)
-			{
-				storedTermVector = true;
-				storePositionWithTermVector = true;
-				storeOffsetWithTermVector = true;
-			}
-			else
-			{
-				throw new System.ArgumentException("unknown termVector parameter " + tvSpec);
-			}
-			
-			// maintain a unique set of field names
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fi.isIndexed && fi.storeTermVector == storedTermVector && fi.storePositionWithTermVector == storePositionWithTermVector && fi.storeOffsetWithTermVector == storeOffsetWithTermVector)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-			}
-			return fieldSet;
-		}
-		
-		/// <seealso cref="IndexReader.GetFieldNames(IndexReader.FieldOption fldOption)">
-		/// </seealso>
-		public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldOption)
-		{
-			System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fieldOption == IndexReader.FieldOption.ALL)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.storeTermVector == true && fi.storePositionWithTermVector == false && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-				else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
-				{
-					fieldSet.Add(fi.name, fi.name);
-				}
-			}
-			return fieldSet;
-		}
-		
-		
-		public override bool HasNorms(System.String field)
-		{
-			lock (this)
-			{
-				return norms.ContainsKey(field);
-			}
-		}
+            }
+            public Norm(SegmentReader enclosingInstance, IndexInput in_Renamed, int number)
+            {
+                InitBlock(enclosingInstance);
+                this.in_Renamed = in_Renamed;
+                this.number = number;
+            }
+			
+            public IndexInput in_Renamed;
+            public byte[] bytes;
+            public bool dirty;
+            public int number;
+			
+            public void  ReWrite()
+            {
+                // NOTE: norms are re-written in regular directory, not cfs
+                IndexOutput out_Renamed = Enclosing_Instance.Directory().CreateOutput(Enclosing_Instance.segment + ".tmp");
+                try
+                {
+                    out_Renamed.WriteBytes(bytes, Enclosing_Instance.MaxDoc());
+                }
+                finally
+                {
+                    out_Renamed.Close();
+                }
+                System.String fileName;
+                if (Enclosing_Instance.cfsReader == null)
+                    fileName = Enclosing_Instance.segment + ".f" + number;
+                else
+                {
+                    // use a different file name if we have compound format
+                    fileName = Enclosing_Instance.segment + ".s" + number;
+                }
+                Enclosing_Instance.Directory().RenameFile(Enclosing_Instance.segment + ".tmp", fileName);
+                this.dirty = false;
+            }
+        }
+		
+        private System.Collections.Hashtable norms = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
+		
+        /// <summary>The class which implements SegmentReader. </summary>
+        private static System.Type IMPL;
+		
+        public SegmentReader() : base(null)
+        {
+        }
+		
+        public static SegmentReader Get(SegmentInfo si)
+        {
+            return Get(si.dir, si, null, false, false);
+        }
+		
+        public static SegmentReader Get(SegmentInfos sis, SegmentInfo si, bool closeDir)
+        {
+            return Get(si.dir, si, sis, closeDir, true);
+        }
+		
+        public static SegmentReader Get(Directory dir, SegmentInfo si, SegmentInfos sis, bool closeDir, bool ownDir)
+        {
+            SegmentReader instance;
+            try
+            {
+                instance = (SegmentReader) System.Activator.CreateInstance(IMPL);
+            }
+            catch (System.Exception e)
+            {
+                throw new System.Exception("cannot load SegmentReader class: " + e, e);
+            }
+            instance.Init(dir, sis, closeDir, ownDir);
+            instance.Initialize(si);
+            return instance;
+        }
+		
+        private void  Initialize(SegmentInfo si)
+        {
+            segment = si.name;
+			
+            // Use compound file directory for some files, if it exists
+            Directory cfsDir = Directory();
+            if (Directory().FileExists(segment + ".cfs"))
+            {
+                cfsReader = new CompoundFileReader(Directory(), segment + ".cfs");
+                cfsDir = cfsReader;
+            }
+			
+            // No compound file exists - use the multi-file format
+            fieldInfos = new FieldInfos(cfsDir, segment + ".fnm");
+            fieldsReader = new FieldsReader(cfsDir, segment, fieldInfos);
+			
+            tis = new TermInfosReader(cfsDir, segment, fieldInfos);
+			
+            // NOTE: the bitvector is stored using the regular directory, not cfs
+            if (HasDeletions(si))
+                deletedDocs = new BitVector(Directory(), segment + ".del");
+			
+            // make sure that all index files have been read or are kept open
+            // so that if an index update removes them we'll still have them
+            freqStream = cfsDir.OpenInput(segment + ".frq");
+            proxStream = cfsDir.OpenInput(segment + ".prx");
+            OpenNorms(cfsDir);
+			
+            if (fieldInfos.HasVectors())
+            {
+                // open term vector files only as needed
+                termVectorsReaderOrig = new TermVectorsReader(cfsDir, segment, fieldInfos);
+            }
+        }
+		
+        ~SegmentReader()
+        {
+            // patch for pre-1.4.2 JVMs, whose ThreadLocals leak
+            //System.Threading.Thread.SetData(termVectorsLocal, null);
+        }
+		
+        protected internal override void  DoCommit()
+        {
+            if (deletedDocsDirty)
+            {
+                // re-write deleted
+                deletedDocs.Write(Directory(), segment + ".tmp");
+                Directory().RenameFile(segment + ".tmp", segment + ".del");
+            }
+            if (undeleteAll && Directory().FileExists(segment + ".del"))
+            {
+                Directory().DeleteFile(segment + ".del");
+            }
+            if (normsDirty)
+            {
+                // re-write norms
+                System.Collections.IEnumerator values = norms.Values.GetEnumerator();
+                while (values.MoveNext())
+                {
+                    Norm norm = (Norm) values.Current;
+                    if (norm.dirty)
+                    {
+                        norm.ReWrite();
+                    }
+                }
+            }
+            deletedDocsDirty = false;
+            normsDirty = false;
+            undeleteAll = false;
+        }
+		
+        protected internal override void  DoClose()
+        {
+            fieldsReader.Close();
+            tis.Close();
+			
+            if (freqStream != null)
+                freqStream.Close();
+            if (proxStream != null)
+                proxStream.Close();
+			
+            CloseNorms();
+			
+            if (termVectorsReaderOrig != null)
+                termVectorsReaderOrig.Close();
+			
+            if (cfsReader != null)
+                cfsReader.Close();
+        }
+		
+        internal static bool HasDeletions(SegmentInfo si)
+        {
+            return si.dir.FileExists(si.name + ".del");
+        }
+		
+        public override bool HasDeletions()
+        {
+            return deletedDocs != null;
+        }
+		
+		
+        internal static bool UsesCompoundFile(SegmentInfo si)
+        {
+            return si.dir.FileExists(si.name + ".cfs");
+        }
+		
+        internal static bool HasSeparateNorms(SegmentInfo si)
+        {
+            System.String[] result = si.dir.List();
+            System.String pattern = si.name + ".s";
+            int patternLength = pattern.Length;
+            for (int i = 0; i < result.Length; i++)
+            {
+                if (result[i].StartsWith(pattern) && System.Char.IsDigit(result[i][patternLength]))
+                    return true;
+            }
+            return false;
+        }
+		
+        protected internal override void  DoDelete(int docNum)
+        {
+            if (deletedDocs == null)
+                deletedDocs = new BitVector(MaxDoc());
+            deletedDocsDirty = true;
+            undeleteAll = false;
+            deletedDocs.Set(docNum);
+        }
+		
+        protected internal override void  DoUndeleteAll()
+        {
+            deletedDocs = null;
+            deletedDocsDirty = false;
+            undeleteAll = true;
+        }
+		
+        internal virtual System.Collections.ArrayList Files()
+        {
+            System.Collections.ArrayList files = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(16));
+			
+            for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
+            {
+                System.String name = segment + "." + IndexFileNames.INDEX_EXTENSIONS[i];
+                if (Directory().FileExists(name))
+                    files.Add(name);
+            }
+			
+            for (int i = 0; i < fieldInfos.Size(); i++)
+            {
+                FieldInfo fi = fieldInfos.FieldInfo(i);
+                if (fi.isIndexed && !fi.omitNorms)
+                {
+                    System.String name;
+                    if (cfsReader == null)
+                        name = segment + ".f" + i;
+                    else
+                        name = segment + ".s" + i;
+                    if (Directory().FileExists(name))
+                        files.Add(name);
+                }
+            }
+            return files;
+        }
+		
+        public override TermEnum Terms()
+        {
+            return tis.Terms();
+        }
+		
+        public override TermEnum Terms(Term t)
+        {
+            return tis.Terms(t);
+        }
+		
+        public override Document Document(int n)
+        {
+            lock (this)
+            {
+                if (IsDeleted(n))
+                    throw new System.ArgumentException("attempt to access a deleted document");
+                return fieldsReader.Doc(n);
+            }
+        }
+		
+        public override bool IsDeleted(int n)
+        {
+            lock (this)
+            {
+                return (deletedDocs != null && deletedDocs.Get(n));
+            }
+        }
+		
+        public override TermDocs TermDocs()
+        {
+            return new SegmentTermDocs(this);
+        }
 		
-		internal static byte[] CreateFakeNorms(int size)
-		{
+        public override TermPositions TermPositions()
+        {
+            return new SegmentTermPositions(this);
+        }
+		
+        public override int DocFreq(Term t)
+        {
+            TermInfo ti = tis.Get(t);
+            if (ti != null)
+                return ti.docFreq;
+            else
+                return 0;
+        }
+		
+        public override int NumDocs()
+        {
+            int n = MaxDoc();
+            if (deletedDocs != null)
+                n -= deletedDocs.Count();
+            return n;
+        }
+		
+        public override int MaxDoc()
+        {
+            return fieldsReader.Size();
+        }
+		
+        /// <seealso cref="IndexReader.GetFieldNames(IndexReader.FieldOption fldOption)">
+        /// </seealso>
+        public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldOption)
+        {
+            System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
+            for (int i = 0; i < fieldInfos.Size(); i++)
+            {
+                FieldInfo fi = fieldInfos.FieldInfo(i);
+                if (fieldOption == IndexReader.FieldOption.ALL)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.storeTermVector == true && fi.storePositionWithTermVector == false && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+                else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
+                {
+                    fieldSet.Add(fi.name, fi.name);
+                }
+            }
+            return fieldSet;
+        }
+		
+		
+        public override bool HasNorms(System.String field)
+        {
+            lock (this)
+            {
+                return norms.ContainsKey(field);
+            }
+        }
+		
+        internal static byte[] CreateFakeNorms(int size)
+        {
             byte[] ones = new byte[size];
             byte val = DefaultSimilarity.EncodeNorm(1.0f);
             for (int index = 0; index < size; index++)
                 ones.SetValue(val, index);
 
             return ones;
-		}
+        }
+		
+        private byte[] ones;
+        private byte[] FakeNorms()
+        {
+            if (ones == null)
+                ones = CreateFakeNorms(MaxDoc());
+            return ones;
+        }
 		
-		private byte[] ones;
-		private byte[] FakeNorms()
-		{
-			if (ones == null)
-				ones = CreateFakeNorms(MaxDoc());
-			return ones;
-		}
-		
-		// can return null if norms aren't stored
-		protected internal virtual byte[] GetNorms(System.String field)
-		{
-			lock (this)
-			{
-				Norm norm = (Norm) norms[field];
-				if (norm == null)
-					return null; // not indexed, or norms not stored
+        // can return null if norms aren't stored
+        protected internal virtual byte[] GetNorms(System.String field)
+        {
+            lock (this)
+            {
+                Norm norm = (Norm) norms[field];
+                if (norm == null)
+                    return null; // not indexed, or norms not stored
 				
-				if (norm.bytes == null)
-				{
-					// value not yet read
-					byte[] bytes = new byte[MaxDoc()];
-					Norms(field, bytes, 0);
-					norm.bytes = bytes; // cache it
-				}
-				return norm.bytes;
-			}
-		}
-		
-		// returns fake norms if norms aren't available
-		public override byte[] Norms(System.String field)
-		{
-			lock (this)
-			{
-				byte[] bytes = GetNorms(field);
-				if (bytes == null)
-					bytes = FakeNorms();
-				return bytes;
-			}
-		}
-		
-		protected internal override void  DoSetNorm(int doc, System.String field, byte value_Renamed)
-		{
-			Norm norm = (Norm) norms[field];
-			if (norm == null)
-			// not an indexed field
-				return ;
-			norm.dirty = true; // mark it dirty
-			normsDirty = true;
-			
-			Norms(field)[doc] = value_Renamed; // set the value
-		}
-		
-		/// <summary>Read norms into a pre-allocated array. </summary>
-		public override void  Norms(System.String field, byte[] bytes, int offset)
-		{
-			lock (this)
-			{
+                if (norm.bytes == null)
+                {
+                    // value not yet read
+                    byte[] bytes = new byte[MaxDoc()];
+                    Norms(field, bytes, 0);
+                    norm.bytes = bytes; // cache it
+                }
+                return norm.bytes;
+            }
+        }
+		
+        // returns fake norms if norms aren't available
+        public override byte[] Norms(System.String field)
+        {
+            lock (this)
+            {
+                byte[] bytes = GetNorms(field);
+                if (bytes == null)
+                    bytes = FakeNorms();
+                return bytes;
+            }
+        }
+		
+        protected internal override void  DoSetNorm(int doc, System.String field, byte value_Renamed)
+        {
+            Norm norm = (Norm) norms[field];
+            if (norm == null)
+                // not an indexed field
+                return ;
+            norm.dirty = true; // mark it dirty
+            normsDirty = true;
+			
+            Norms(field)[doc] = value_Renamed; // set the value
+        }
+		
+        /// <summary>Read norms into a pre-allocated array. </summary>
+        public override void  Norms(System.String field, byte[] bytes, int offset)
+        {
+            lock (this)
+            {
 				
-				Norm norm = (Norm) norms[field];
-				if (norm == null)
-				{
-					Array.Copy(FakeNorms(), 0, bytes, offset, MaxDoc());
-					return ;
-				}
+                Norm norm = (Norm) norms[field];
+                if (norm == null)
+                {
+                    Array.Copy(FakeNorms(), 0, bytes, offset, MaxDoc());
+                    return ;
+                }
 				
-				if (norm.bytes != null)
-				{
-					// can copy from cache
-					Array.Copy(norm.bytes, 0, bytes, offset, MaxDoc());
-					return ;
-				}
+                if (norm.bytes != null)
+                {
+                    // can copy from cache
+                    Array.Copy(norm.bytes, 0, bytes, offset, MaxDoc());
+                    return ;
+                }
 				
-				IndexInput normStream = (IndexInput) norm.in_Renamed.Clone();
-				try
-				{
-					// read from disk
-					normStream.Seek(0);
-					normStream.ReadBytes(bytes, offset, MaxDoc());
-				}
-				finally
-				{
-					normStream.Close();
-				}
-			}
-		}
-		
-		
-		private void  OpenNorms(Directory cfsDir)
-		{
-			for (int i = 0; i < fieldInfos.Size(); i++)
-			{
-				FieldInfo fi = fieldInfos.FieldInfo(i);
-				if (fi.isIndexed && !fi.omitNorms)
-				{
-					// look first if there are separate norms in compound format
-					System.String fileName = segment + ".s" + fi.number;
-					Directory d = Directory();
-					if (!d.FileExists(fileName))
-					{
-						fileName = segment + ".f" + fi.number;
-						d = cfsDir;
-					}
-					norms[fi.name] = new Norm(this, d.OpenInput(fileName), fi.number);
-				}
-			}
-		}
-		
-		private void  CloseNorms()
-		{
-			lock (norms.SyncRoot)
-			{
-				System.Collections.IEnumerator enumerator = norms.Values.GetEnumerator();
-				while (enumerator.MoveNext())
-				{
-					Norm norm = (Norm) enumerator.Current;
-					norm.in_Renamed.Close();
-				}
-			}
-		}
-		
-		/// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
-		/// <returns> TermVectorsReader
-		/// </returns>
-		private TermVectorsReader GetTermVectorsReader()
-		{
-			TermVectorsReader tvReader = (TermVectorsReader) System.Threading.Thread.GetData(termVectorsLocal);
-			if (tvReader == null)
-			{
-				tvReader = (TermVectorsReader) termVectorsReaderOrig.Clone();
-				System.Threading.Thread.SetData(termVectorsLocal, tvReader);
-			}
-			return tvReader;
-		}
-		
-		/// <summary>Return a term frequency vector for the specified document and field. The
-		/// vector returned contains term numbers and frequencies for all terms in
-		/// the specified field of this document, if the field had storeTermVector
-		/// flag set.  If the flag was not set, the method returns null.
-		/// </summary>
-		/// <throws>  IOException </throws>
-		public override TermFreqVector GetTermFreqVector(int docNumber, System.String field)
-		{
-			// Check if this field is invalid or has no stored term vector
-			FieldInfo fi = fieldInfos.FieldInfo(field);
-			if (fi == null || !fi.storeTermVector || termVectorsReaderOrig == null)
-				return null;
-			
-			TermVectorsReader termVectorsReader = GetTermVectorsReader();
-			if (termVectorsReader == null)
-				return null;
-			
-			return termVectorsReader.Get(docNumber, field);
-		}
-		
-		
-		/// <summary>Return an array of term frequency vectors for the specified document.
-		/// The array contains a vector for each vectorized field in the document.
-		/// Each vector vector contains term numbers and frequencies for all terms
-		/// in a given vectorized field.
-		/// If no such fields existed, the method returns null.
-		/// </summary>
-		/// <throws>  IOException </throws>
-		public override TermFreqVector[] GetTermFreqVectors(int docNumber)
-		{
-			if (termVectorsReaderOrig == null)
-				return null;
-			
-			TermVectorsReader termVectorsReader = GetTermVectorsReader();
-			if (termVectorsReader == null)
-				return null;
+                IndexInput normStream = (IndexInput) norm.in_Renamed.Clone();
+                try
+                {
+                    // read from disk
+                    normStream.Seek(0);
+                    normStream.ReadBytes(bytes, offset, MaxDoc());
+                }
+                finally
+                {
+                    normStream.Close();
+                }
+            }
+        }
+		
+		
+        private void  OpenNorms(Directory cfsDir)
+        {
+            for (int i = 0; i < fieldInfos.Size(); i++)
+            {
+                FieldInfo fi = fieldInfos.FieldInfo(i);
+                if (fi.isIndexed && !fi.omitNorms)
+                {
+                    // look first if there are separate norms in compound format
+                    System.String fileName = segment + ".s" + fi.number;
+                    Directory d = Directory();
+                    if (!d.FileExists(fileName))
+                    {
+                        fileName = segment + ".f" + fi.number;
+                        d = cfsDir;
+                    }
+                    norms[fi.name] = new Norm(this, d.OpenInput(fileName), fi.number);
+                }
+            }
+        }
+		
+        private void  CloseNorms()
+        {
+            lock (norms.SyncRoot)
+            {
+                System.Collections.IEnumerator enumerator = norms.Values.GetEnumerator();
+                while (enumerator.MoveNext())
+                {
+                    Norm norm = (Norm) enumerator.Current;
+                    norm.in_Renamed.Close();
+                }
+            }
+        }
+		
+        /// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
+        /// <returns> TermVectorsReader
+        /// </returns>
+        private TermVectorsReader GetTermVectorsReader()
+        {
+            TermVectorsReader tvReader = (TermVectorsReader) System.Threading.Thread.GetData(termVectorsLocal);
+            if (tvReader == null)
+            {
+                tvReader = (TermVectorsReader) termVectorsReaderOrig.Clone();
+                System.Threading.Thread.SetData(termVectorsLocal, tvReader);
+            }
+            return tvReader;
+        }
+		
+        /// <summary>Return a term frequency vector for the specified document and field. The
+        /// vector returned contains term numbers and frequencies for all terms in
+        /// the specified field of this document, if the field had storeTermVector
+        /// flag set.  If the flag was not set, the method returns null.
+        /// </summary>
+        /// <throws>  IOException </throws>
+        public override TermFreqVector GetTermFreqVector(int docNumber, System.String field)
+        {
+            // Check if this field is invalid or has no stored term vector
+            FieldInfo fi = fieldInfos.FieldInfo(field);
+            if (fi == null || !fi.storeTermVector || termVectorsReaderOrig == null)
+                return null;
+			
+            TermVectorsReader termVectorsReader = GetTermVectorsReader();
+            if (termVectorsReader == null)
+                return null;
 			
-			return termVectorsReader.Get(docNumber);
-		}
+            return termVectorsReader.Get(docNumber, field);
+        }
+		
+		
+        /// <summary>Return an array of term frequency vectors for the specified document.
+        /// The array contains a vector for each vectorized field in the document.
+        /// Each vector vector contains term numbers and frequencies for all terms
+        /// in a given vectorized field.
+        /// If no such fields existed, the method returns null.
+        /// </summary>
+        /// <throws>  IOException </throws>
+        public override TermFreqVector[] GetTermFreqVectors(int docNumber)
+        {
+            if (termVectorsReaderOrig == null)
+                return null;
+			
+            TermVectorsReader termVectorsReader = GetTermVectorsReader();
+            if (termVectorsReader == null)
+                return null;
+			
+            return termVectorsReader.Get(docNumber);
+        }
 
         static SegmentReader()
-		{
-			{
-				try
-				{
+        {
+            {
+                try
+                {
                     System.String name = SupportClass.AppSettings.Get("Lucene.Net.SegmentReader.class", typeof(SegmentReader).FullName);
-					IMPL = System.Type.GetType(name);
-				}
-				catch (System.Security.SecurityException)
-				{
-					try
-					{
-						IMPL = System.Type.GetType(typeof(SegmentReader).FullName);
-					}
-					catch (System.Exception e)
-					{
-						throw new System.SystemException("cannot load default SegmentReader class: " + e);
-					}
-				}
+                    IMPL = System.Type.GetType(name);
+                }
+                catch (System.Security.SecurityException)
+                {
+                    try
+                    {
+                        IMPL = System.Type.GetType(typeof(SegmentReader).FullName);
+                    }
+                    catch (System.Exception e)
+                    {
+                        throw new System.Exception("cannot load default SegmentReader class: " + e, e); // {{Aroush-2.0}} How do we throw a RuntimeException
+                    }
+                }
                 catch (System.Exception e)
                 {
-                    throw new System.SystemException("cannot load SegmentReader class: " + e);
+                    throw new System.Exception("cannot load SegmentReader class: " + e, e); // {{Aroush-2.0}} How do we throw a RuntimeException
                 }
             }
-		}
-	}
+        }
+    }
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/Term.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs Thu Aug 17 06:49:26 2006
@@ -119,20 +119,30 @@
 			return field + ":" + text;
 		}
 		
-		private void  ReadObject(System.IO.BinaryReader in_Renamed)
-		{
-			// This function is private and is never been called, so this may not be a port issue.          // {{Aroush-1.4.3}}
-            // 'java.io.ObjectInputStream.defaultReadObject' was not converted                              // {{Aroush-1.4.3}}
-			// in_Renamed.defaultReadObject();                                                              // {{Aroush-1.4.3}}
-			field = String.Intern(field);
-		}
-		
-        // {{Aroush-1.4.3: or is this method is what we want (vs. the above)?!!
-        private void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
+        private Term(System.Runtime.Serialization.SerializationInfo in_Renamed, System.Runtime.Serialization.StreamingContext context)
         {
-            info.AddValue("field", field);
-            info.AddValue("text", text);
+            System.Type thisType = this.GetType();
+            System.Reflection.MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(thisType, context);
+            for (int i = 0 ; i < mi.Length; i++) 
+            {
+                System.Reflection.FieldInfo fi = (System.Reflection.FieldInfo) mi[i];
+                fi.SetValue(this, in_Renamed.GetValue(fi.Name, fi.FieldType));
+            }
+            field = String.Intern(field);
+        }
+
+        public Term()
+        {
+        }
+
+        public void  GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
+        {
+            System.Type thisType = this.GetType();
+            System.Reflection.MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(thisType, context);
+            for (int i = 0 ; i < mi.Length; i++) 
+            {
+                info.AddValue(mi[i].Name, ((System.Reflection.FieldInfo) mi[i]).GetValue(this));
+            }
         }
-        // Aroush-1.4.3}}
     }
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermInfosWriter.cs?rev=432239&r1=432238&r2=432239&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs Thu Aug 17 06:49:26 2006
@@ -95,12 +95,14 @@
 		/// </summary>
 		public /*internal*/ void  Add(Term term, TermInfo ti)
 		{
-			if (!isIndex && term.CompareTo(lastTerm) <= 0)
-				throw new System.IO.IOException("term out of order");
+            if (!isIndex && term.CompareTo(lastTerm) <= 0)
+            {
+                throw new System.IO.IOException("term out of order (\"" + term + "\".compareTo(\"" + lastTerm + "\") <= 0)");
+            }
 			if (ti.freqPointer < lastTi.freqPointer)
-				throw new System.IO.IOException("freqPointer out of order");
+				throw new System.IO.IOException("freqPointer out of order (" + ti.freqPointer + " < " + lastTi.freqPointer + ")");
 			if (ti.proxPointer < lastTi.proxPointer)
-				throw new System.IO.IOException("proxPointer out of order");
+				throw new System.IO.IOException("proxPointer out of order (" + ti.proxPointer + " < " + lastTi.proxPointer + ")");
 			
 			if (!isIndex && size % indexInterval == 0)
 				other.Add(lastTerm, lastTi); // add an index term



Mime
View raw message