lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgar...@apache.org
Subject svn commit: r920415 [1/2] - in /lucene/lucene.net/trunk/C#/contrib/Contrib.Net: ./ Contrib.Net.Test/ Contrib.Net.Test/Index/ Contrib.Net.Test/Properties/ Contrib.Net.Test/Util/ Contrib.Net.Test/Util/Cache/ Contrib.Net/ Contrib.Net/Index/ Contrib.Net/Pr...
Date Mon, 08 Mar 2010 17:35:50 GMT
Author: mgarski
Date: Mon Mar  8 17:35:49 2010
New Revision: 920415

URL: http://svn.apache.org/viewvc?rev=920415&view=rev
Log:
LUCENENET-345 : new project for the contrib section containing Lucene.Net specific items that were not ported from the Java contrib section.

Added:
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Contrib.Net.Test.csproj
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/FieldEnumeratorTest.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/SegmentsGenCommitTest.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/TermVectorEnumeratorTest.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Properties/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Properties/AssemblyInfo.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/SegmentCacheTest.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.sln
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Contrib.Net.csproj
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/FieldEnumerator.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/SegmentsGenCommit.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/TermVectorEnumerator.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Properties/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Properties/AssemblyInfo.cs
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Util/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Util/Cache/
    lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Util/Cache/SegmentCache.cs

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Contrib.Net.Test.csproj
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Contrib.Net.Test.csproj?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Contrib.Net.Test.csproj (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Contrib.Net.Test.csproj Mon Mar  8 17:35:49 2010
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Lucene.Net.Test</RootNamespace>
+    <AssemblyName>Contrib.Net.Test</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="nunit.framework, Version=2.5.3.9345, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Index\FieldEnumeratorTest.cs" />
+    <Compile Include="Index\SegmentsGenCommitTest.cs" />
+    <Compile Include="Index\TermVectorEnumeratorTest.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Util\Cache\SegmentCacheTest.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\src\Lucene.Net\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\Contrib.Net\Contrib.Net.csproj">
+      <Project>{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}</Project>
+      <Name>Contrib.Net</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/FieldEnumeratorTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Index/FieldEnumeratorTest.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/FieldEnumeratorTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/FieldEnumeratorTest.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,290 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+
+namespace Lucene.Net.Test.Index
+{
+    /// <summary>
+    /// Summary description for FieldEnumeratorTest
+    /// </summary>
+    [TestFixture]
+    public class FieldEnumeratorTest
+    {
+        public FieldEnumeratorTest()
+        {
+            //
+            // TODO: Add constructor logic here
+            //
+        }
+
+        private static IndexReader reader;
+
+        #region setup/teardown methods
+        
+        [TestFixtureSetUp]
+        public static void MyClassInitialize()
+        {
+            RAMDirectory rd = new RAMDirectory();
+            IndexWriter writer = new IndexWriter(rd, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+            for (int i = 0; i < 1000; i++)
+            {
+                Document doc = new Document();
+                doc.Add(new Field("string", i.ToString(), Field.Store.YES, Field.Index.ANALYZED));
+                doc.Add(new NumericField("int", Field.Store.YES, true).SetIntValue(i));
+                doc.Add(new NumericField("long", Field.Store.YES, true).SetLongValue(i));
+                doc.Add(new NumericField("double", Field.Store.YES, true).SetDoubleValue(i));
+                doc.Add(new NumericField("float", Field.Store.YES, true).SetFloatValue(i));
+                writer.AddDocument(doc);
+            }
+            writer.Close();
+            reader = IndexReader.Open(rd, true);
+        }
+
+        [TestFixtureTearDown]
+        public static void MyClassCleanup()
+        {
+            if (reader != null)
+            {
+                reader.Close();
+                reader = null;
+            }
+        }
+
+        #endregion
+
+        [Test]
+        public void StringEnumTest()
+        {
+            using (StringFieldEnumerator sfe = new StringFieldEnumerator(reader, "string", false))
+            {
+                int value = 0;
+                foreach (string s in sfe.Terms)
+                {
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+
+            // now with the documents
+            using (StringFieldEnumerator sfe = new StringFieldEnumerator(reader, "string"))
+            {
+                int value = 0;
+                foreach (string s in sfe.Terms)
+                {
+                    foreach (int doc in sfe.Docs)
+                    {
+                        string expected = reader.Document(doc).Get("string");
+                        Assert.AreEqual(expected, s);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+        }
+
+        [Test]
+        public void IntEnumTest()
+        {
+            using (IntFieldEnumerator ife = new IntFieldEnumerator(reader, "string", FieldParser.String))
+            {
+                int value = 0;
+                foreach (int i in ife.Terms)
+                {
+                    foreach (int doc in ife.Docs)
+                    {
+                        int expected = Int32.Parse(reader.Document(doc).Get("string"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+
+            using (IntFieldEnumerator ife = new IntFieldEnumerator(reader, "int", FieldParser.Numeric))
+            {
+                int value = 0;
+                foreach (int i in ife.Terms)
+                {
+                    foreach (int doc in ife.Docs)
+                    {
+                        int expected = Int32.Parse(reader.Document(doc).Get("int"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+        }
+
+        [Test]
+        public void LongEnumTest()
+        {
+            using (LongFieldEnumerator lfe = new LongFieldEnumerator(reader, "string", FieldParser.String))
+            {
+                int value = 0;
+                foreach (long i in lfe.Terms)
+                {
+                    foreach (int doc in lfe.Docs)
+                    {
+                        long expected = Int64.Parse(reader.Document(doc).Get("string"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+
+            using (LongFieldEnumerator lfe = new LongFieldEnumerator(reader, "long", FieldParser.Numeric))
+            {
+                int value = 0;
+                foreach (int i in lfe.Terms)
+                {
+                    foreach (int doc in lfe.Docs)
+                    {
+                        long expected = Int64.Parse(reader.Document(doc).Get("long"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+        }
+
+        [Test]
+        public void FloatEnumTest()
+        {
+            using (FloatFieldEnumerator ffe = new FloatFieldEnumerator(reader, "string", FieldParser.String))
+            {
+                int value = 0;
+                foreach (int i in ffe.Terms)
+                {
+                    foreach (int doc in ffe.Docs)
+                    {
+                        float expected = Single.Parse(reader.Document(doc).Get("string"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+
+            using (FloatFieldEnumerator ffe = new FloatFieldEnumerator(reader, "float", FieldParser.Numeric))
+            {
+                int value = 0;
+                foreach (int i in ffe.Terms)
+                {
+                    foreach (int doc in ffe.Docs)
+                    {
+                        float expected = Single.Parse(reader.Document(doc).Get("float"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+        }
+
+        [Test]
+        public void DoubleEnumTest()
+        {
+            using (DoubleFieldEnumerator dfe = new DoubleFieldEnumerator(reader, "string", FieldParser.String))
+            {
+                int value = 0;
+                foreach (int i in dfe.Terms)
+                {
+                    foreach (int doc in dfe.Docs)
+                    {
+                        double expected = Double.Parse(reader.Document(doc).Get("string"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+
+            using (DoubleFieldEnumerator dfe = new DoubleFieldEnumerator(reader, "double", FieldParser.Numeric))
+            {
+                int value = 0;
+                foreach (int i in dfe.Terms)
+                {
+                    foreach (int doc in dfe.Docs)
+                    {
+                        double expected = Double.Parse(reader.Document(doc).Get("double"));
+                        Assert.AreEqual(expected, i);
+                    }
+                    value++;
+                }
+                Assert.AreEqual(1000, value);
+            }
+        }
+
+        [Test]
+        public void TermDocEnumeratorOnlyTestSingleTerm()
+        {
+            Term t = new Term("string", "500");
+            using (TermDocEnumerator tde = new TermDocEnumerator(reader.TermDocs()))
+            {
+                tde.Seek(t);
+                int count = 0;
+                foreach (int doc in tde)
+                {
+                    Assert.AreEqual(500, doc);
+                    count++;
+                }
+                Assert.AreEqual(1, count);
+            }
+        }
+
+        [Test]
+        public void TermDocEnumeratorOnlyTestMultipleTerms()
+        {
+            HashSet<Term> terms = new HashSet<Term>();
+            terms.Add(new Term("string", "500"));
+            terms.Add(new Term("string", "600"));
+            terms.Add(new Term("string", "400"));
+
+            HashSet<int> docs = new HashSet<int>();
+            using (TermDocEnumerator tde = new TermDocEnumerator(reader.TermDocs()))
+            {
+                foreach (Term t in terms)
+                {
+                    tde.Seek(t);
+                    foreach (int doc in tde)
+                    {
+                        docs.Add(doc);
+                    }
+                }
+            }
+
+            Assert.AreEqual(3, docs.Count);
+            Assert.IsTrue(docs.Contains(400));
+            Assert.IsTrue(docs.Contains(500));
+            Assert.IsTrue(docs.Contains(600));
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/SegmentsGenCommitTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Index/SegmentsGenCommitTest.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/SegmentsGenCommitTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/SegmentsGenCommitTest.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,103 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+
+namespace Lucene.Net.Test.Index
+{
+    /// <summary>
+    /// Summary description for SegmentsGenCommitTest
+    /// </summary>
+    [TestFixture]
+    public class SegmentsGenCommitTest
+    {
+        public SegmentsGenCommitTest()
+        {
+            //
+            // TODO: Add constructor logic here
+            //
+        }
+
+        private RAMDirectory directory;
+
+        #region setup/teardown methods
+
+        [SetUp]
+        public void MyTestInitialize()
+        {
+            this.directory = new RAMDirectory();
+            IndexWriter writer = new IndexWriter(this.directory, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+            for (int i = 0; i < 10; i++)
+            {
+                Document d = new Document();
+                d.Add(new Field("Text", i.ToString(), Field.Store.YES, Field.Index.ANALYZED));
+                writer.AddDocument(d);
+                writer.Commit();
+            }
+            writer.Close();
+        }
+
+        [TearDown]
+        public void MyTestCleanup()
+        {
+            if (this.directory != null)
+            {
+                this.directory.Close();
+                this.directory = null;
+            }
+        }
+
+        #endregion
+
+        [Test]
+        public void ReadSegmentsGenTest()
+        {
+            // check the generation in the directory
+            IndexReader reader = IndexReader.Open(this.directory, true);
+            IndexCommit commit = reader.GetIndexCommit();
+
+            // create a SegmentsGenCommit
+            SegmentsGenCommit sgCommit = new SegmentsGenCommit(this.directory);
+
+            Assert.AreEqual(commit.GetGeneration(), sgCommit.GetGeneration());
+            Assert.AreEqual(commit.GetSegmentsFileName(), sgCommit.GetSegmentsFileName());
+        }
+
+        [Test]
+        public void OpenWriterWithCommit()
+        {
+            SegmentsGenCommit sgCommit = new SegmentsGenCommit(this.directory);
+            IndexWriter writer = new IndexWriter(this.directory, new WhitespaceAnalyzer(), null, IndexWriter.MaxFieldLength.UNLIMITED, sgCommit);
+            Assert.AreEqual(10, writer.MaxDoc());
+            IndexReader reader = writer.GetReader();
+
+            IndexCommit commit = reader.GetIndexCommit();
+            Assert.AreEqual(commit.GetGeneration(), sgCommit.GetGeneration());
+            Assert.AreEqual(commit.GetSegmentsFileName(), sgCommit.GetSegmentsFileName());
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/TermVectorEnumeratorTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Index/TermVectorEnumeratorTest.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/TermVectorEnumeratorTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Index/TermVectorEnumeratorTest.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,138 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Store;
+
+namespace Lucene.Net.Test.Index
+{
+    /// <summary>
+    /// Summary description for TermVectorEnumeratorTest
+    /// </summary>
+    [TestFixture]
+    public class TermVectorEnumeratorTest
+    {
+        public TermVectorEnumeratorTest()
+        {
+            //
+            // TODO: Add constructor logic here
+            //
+        }
+
+        private IndexReader reader;
+
+        #region setup/teardown methods
+
+        [SetUp]
+        public void MyTestInitialize()
+        {
+            RAMDirectory rd = new RAMDirectory();
+            IndexWriter writer = new IndexWriter(rd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+            for (int i = 0; i < 5; i++)
+            {
+                Document doc = new Document();
+                string data = string.Format("{0} {1}", i, i * 10);
+                doc.Add(new Field("test", data, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
+                writer.AddDocument(doc);
+            }
+
+            // add document that does not have the vectored field
+            Document docDiffField = new Document();
+            string diffData = string.Format("{0} {1}", 10, 10 * 10);
+            docDiffField.Add(new Field("test2", diffData, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
+            writer.AddDocument(docDiffField);
+
+
+            writer.Close();
+            this.reader = IndexReader.Open(rd, false);
+        }
+
+        [TearDown]
+        public void MyTestCleanup()
+        {
+            if (this.reader != null)
+            {
+                this.reader.Close();
+                this.reader = null;
+            }
+        }
+
+        #endregion
+
+        [Test]
+        public void NoPosNoOffsetTest()
+        {
+            int doc = 0;
+            foreach (TermFreqVector vector in new TermVectorEnumerator(this.reader, "test"))
+            {
+                if (doc == 0)
+                {
+                    Assert.AreEqual(1, vector.GetTerms().Length);
+                    Assert.AreEqual(doc.ToString(), vector.GetTerms()[0]);
+                }
+                else if (doc == 5)
+                {
+                    Assert.IsInstanceOf<EmptyVector>(vector);
+                }
+                else
+                {
+                    Assert.AreEqual(2, vector.GetTerms().Length);
+                    Assert.AreEqual(doc.ToString(), vector.GetTerms()[0]);
+                    Assert.AreEqual((doc * 10).ToString(), vector.GetTerms()[1]);
+                }
+                doc++;
+            }
+        }
+
+        [Test]
+        public void DeletedDocumentTest()
+        {
+            this.reader.DeleteDocument(2);
+            this.reader.Flush();
+
+            int doc = 0;
+            foreach (TermFreqVector vector in new TermVectorEnumerator(this.reader, "test"))
+            {
+                if (doc == 0)
+                {
+                    Assert.AreEqual(1, vector.GetTerms().Length);
+                    Assert.AreEqual(doc.ToString(), vector.GetTerms()[0]);
+                }
+                else if (doc == 2 || doc == 5)
+                {
+                    Assert.IsInstanceOf<EmptyVector>(vector);
+                }
+                else
+                {
+                    Assert.AreEqual(2, vector.GetTerms().Length);
+                    Assert.AreEqual(doc.ToString(), vector.GetTerms()[0]);
+                    Assert.AreEqual((doc * 10).ToString(), vector.GetTerms()[1]);
+                }
+                doc++;
+            }
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Properties/AssemblyInfo.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Properties/AssemblyInfo.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Properties/AssemblyInfo.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Contrib.Net.Test(Apache Lucene.Net)")]
+[assembly: AssemblyDescription("Test project for Lucene.Net specific contrib items")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Contrib.Net.Test")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("83c3b038-52ef-4e84-9c42-b1b22917f838")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("2.9.2")]
+[assembly: AssemblyFileVersion("2.9.2")]

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/SegmentCacheTest.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/SegmentCacheTest.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/SegmentCacheTest.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.Test/Util/Cache/SegmentCacheTest.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,253 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+
+using NUnit.Framework;
+
+using Lucene.Net.Analysis;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Search;
+using Lucene.Net.Store;
+using Lucene.Net.Util.Cache;
+
+namespace Lucene.Net.Test.Util.Cache
+{
+    /// <summary>
+    /// Summary description for TestCache
+    /// </summary>
+    [TestFixture]
+    public class CacheTest
+    {
+        public CacheTest()
+        {
+            //
+            // TODO: Add constructor logic here
+            //
+        }
+
+        private RAMDirectory directory;
+
+        private IndexReader reader;
+
+        #region setup/teardown methods
+
+        [SetUp]
+        public void MyTestInitialize()
+        {
+            // create the initial index
+            this.directory = new RAMDirectory();
+            this.CreateInitialIndex(this.directory);
+            this.reader = IndexReader.Open(this.directory, true);
+        }
+
+        [TearDown]
+        public void MyTestCleanup()
+        {
+            if (this.reader != null)
+            {
+                this.reader.Close();
+                this.reader = null;
+            }
+            if (this.directory != null)
+            {
+                this.directory.Close();
+                this.directory = null;
+            }
+
+            GC.Collect();
+        }
+
+        #endregion
+
+        [Test]
+        public void CreateAddRetreive_SingleReader()
+        {
+            // warm the cache
+            Terms t = MockCache.Instance.Get(this.reader, "Cached");
+            this.AssertCache(t, 1, "Cached", 10);
+
+            // get the item from cache
+            t = MockCache.Instance.Get(this.reader, "Cached");
+            this.AssertCache(t, 1, "Cached", 10);
+        }
+
+        [Test]
+        public void CreateAddRetreive_TwoReaders()
+        {
+            RAMDirectory rd = new RAMDirectory();
+            this.CreateInitialIndex(rd);
+            IndexReader r2 = IndexReader.Open(rd, true);
+
+            // warm the cache with the class reader
+            Terms t = MockCache.Instance.Get(this.reader, "Cached");
+            this.AssertCache(t, 1, "Cached", 10);
+
+            // warm the cache with the method reader
+            t = MockCache.Instance.Get(r2, "Cached");
+            this.AssertCache(t, 2, "Cached", 10);
+        }
+
+        [Test]
+        public void GCRemoval()
+        {
+            // warm the cache
+            Terms t = MockCache.Instance.Get(this.reader, "Cached");
+            this.AssertCache(t, 1, "Cached", 10);
+
+            // add items to the existing index
+            this.AddItemsToIndex(this.directory);
+            IndexReader newReader = IndexReader.Open(this.directory, true);
+            Assert.AreEqual(20, newReader.NumDocs());
+
+            // test the cache, the old item from the class reader should still be there
+            t = MockCache.Instance.Get(newReader, "Cached");
+            this.AssertCache(t, 2, "Cached", 20);
+
+            // close and null out the class reader, then force a GC
+            this.reader.Close();
+            this.reader = null;
+            GC.Collect();
+
+            // test the cache, should still have the item from the method reader
+            // as there has been no addition to the cache since it was removed
+            t = MockCache.Instance.Get(newReader, "Cached");
+            this.AssertCache(t, 2, "Cached", 20);
+
+            // add another reader to the cache, which will clear out the class reader
+            IndexReader newReader2 = IndexReader.Open(this.directory, true);
+            t = MockCache.Instance.Get(newReader2, "Cached");
+            this.AssertCache(t, 2, "Cached", 20);
+
+            newReader.Close();
+            newReader = null;
+            newReader2.Close();
+            newReader2 = null;
+        }
+
+        private void AssertCache(Terms t, int keyCount, string field, int count)
+        {
+            Assert.AreEqual(keyCount, MockCache.Instance.KeyCount);
+            Assert.AreEqual(field, t.Field);
+            Assert.AreEqual(count, t.Count);
+        }
+
+        private void CreateInitialIndex(Directory dir)
+        {
+            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
+            this.AddDocuments(writer, 0, 10);
+            writer.Close();
+        }
+
+        private void AddItemsToIndex(Directory dir)
+        {
+            IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false, IndexWriter.MaxFieldLength.UNLIMITED);
+            this.AddDocuments(writer, 20, 30);
+            writer.Close();
+        }
+
+        private void AddDocuments(IndexWriter writer, int start, int end)
+        {
+            for (int i = start; i < end; i++)
+            {
+                Document doc = new Document();
+                doc.Add(new Field("Cached", i.ToString(), Field.Store.NO, Field.Index.ANALYZED));
+                doc.Add(new Field("Skipped", i.ToString(), Field.Store.NO, Field.Index.ANALYZED));
+                writer.AddDocument(doc);
+            }
+        }
+
+        /// <summary>
+        /// Mock cache that caches the number of terms in a field.
+        /// </summary>
+        public class MockCache : SegmentCache<Terms>
+        {
+            /// <summary>
+            /// Singleton.
+            /// </summary>
+            private static MockCache instance = new MockCache();
+
+            /// <summary>
+            /// Singleton accessor.
+            /// </summary>
+            public static MockCache Instance
+            {
+                get { return MockCache.instance; }
+            }
+
+            /// <summary>
+            /// Create the values for the cache.
+            /// </summary>
+            /// <param name="reader"></param>
+            /// <param name="key">The key for the item in cache - in this case a field name.</param>
+            /// <returns></returns>
+            protected override Terms CreateValue(IndexReader reader, string key)
+            {
+                Terms item = new Terms();
+                item.Field = key;
+
+                using (StringFieldEnumerator sfe = new StringFieldEnumerator(reader, key, false))
+                {
+                    foreach (string s in sfe.Terms)
+                    {
+                        item.Count++;
+                    }
+                }
+
+                return item;
+            }
+        }
+
+
+        /// <summary>
+        /// Simple item to cache.
+        /// </summary>
+        public class Terms
+        {
+            /// <summary>
+            /// The name of the field.
+            /// </summary>
+            public string Field
+            {
+                get;
+                set;
+            }
+
+            /// <summary>
+            /// The number of terms in a field.
+            /// </summary>
+            public int Count
+            {
+                get;
+                set;
+            }
+
+            /// <summary>
+            /// Reset the instance.
+            /// </summary>
+            public void Reset()
+            {
+                this.Field = string.Empty;
+                this.Count = 0;
+            }
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.sln
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net.sln?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.sln (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net.sln Mon Mar  8 17:35:49 2010
@@ -0,0 +1,32 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Net", "Contrib.Net\Contrib.Net.csproj", "{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contrib.Net.Test", "Contrib.Net.Test\Contrib.Net.Test.csproj", "{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lucene.Net", "..\..\src\Lucene.Net\Lucene.Net.csproj", "{5D4AD9BE-1FFB-41AB-9943-25737971BF57}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{A065904B-1EBA-48DA-8D3D-D92A85BA41FC}.Release|Any CPU.Build.0 = Release|Any CPU
+		{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{5D4AD9BE-1FFB-41AB-9943-25737971BF57}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Contrib.Net.csproj
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net/Contrib.Net.csproj?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Contrib.Net.csproj (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Contrib.Net.csproj Mon Mar  8 17:35:49 2010
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{FEF899EB-610C-4D3C-A556-A01F56F4AFE0}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Lucene.Net</RootNamespace>
+    <AssemblyName>Contrib.Net</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Index\FieldEnumerator.cs" />
+    <Compile Include="Index\SegmentsGenCommit.cs" />
+    <Compile Include="Index\TermVectorEnumerator.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Util\Cache\SegmentCache.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\src\Lucene.Net\Lucene.Net.csproj">
+      <Project>{5D4AD9BE-1FFB-41AB-9943-25737971BF57}</Project>
+      <Name>Lucene.Net</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/FieldEnumerator.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net/Index/FieldEnumerator.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/FieldEnumerator.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/FieldEnumerator.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,840 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Lucene.Net.Util;
+
+namespace Lucene.Net.Index
+{
+    /// <summary>
+    /// The type of parser for the value of the term.
+    /// </summary>
+    public enum FieldParser
+    {
+        String,
+        Numeric
+    }
+
+    /// <summary>
+    /// <para>Base class for the typed enumerators.</para> 
+    /// 
+    /// <para>
+    /// There are five implementations of FieldEnumerator<typeparamref name="T"/> for
+    /// strings, integers, longs, floats, and doubles. The numeric enumerators support both 
+    /// standard Field and NumericField implementations.  The string and numeric enumerators
+    /// have slightly different options, but both should be used within a using statment
+    /// to close the underlying TermEnum/TermDocs. Refer to the unit tests for usage examples.
+    /// </summary>
+    /// <typeparam name="T">The type of data being enumerated.</typeparam>
+    public abstract class FieldEnumerator<T> : IDisposable
+    {
+        /// <summary>
+        /// Whether the enumerator will include TermDocs.
+        /// </summary>
+        protected bool includeDocs;
+
+        /// <summary>
+        /// The underlying TermEnum;
+        /// </summary>
+        private TermEnum termEnum;
+
+        /// <summary>
+        /// The optional TermDocs.
+        /// </summary>
+        private TermDocs termDocs;
+
+        /// <summary>
+        /// The specialized TermEnum enumerator.
+        /// </summary>
+        protected TermEnumerator tEnum;
+
+        /// <summary>
+        /// The specialized TermDoc enumerator.
+        /// </summary>
+        private TermDocEnumerator.TermDocUsingTermsEnumerator tdEnum;
+
+        /// <summary>
+        /// Whether or not the instance has been disposed.
+        /// </summary>
+        private bool disposed;
+
+        /// <summary>
+        /// Initialization method called by subclasses to simulate a shared
+        /// base constructor as generic classes cannot have a parameterized ctor.
+        /// </summary>
+        /// <param name="reader">The index reader to read from.</param>
+        /// <param name="field">The field to enumerate.</param>
+        protected void Init(IndexReader reader, string field)
+        {
+            this.Init(reader, field, true);
+        }
+
+        /// <summary>
+        /// Initialization method called by subclasses to simulate a shared
+        /// base constructor as generic classes cannot have a parameterized ctor.
+        /// </summary>
+        /// <param name="reader">The index reader to read from.</param>
+        /// <param name="field">The field to enumerate.</param>
+        /// <param name="includeDocs">Whether this enumerator will support TermDocs.</param>
+        protected void Init(IndexReader reader, string fieldName, bool includeDocs)
+        {
+            this.termEnum = reader.Terms(new Term(fieldName));
+            if (includeDocs)
+            {
+                this.termDocs = reader.TermDocs();
+                this.tdEnum = new TermDocEnumerator.TermDocUsingTermsEnumerator(this.termDocs, this.termEnum);
+            }
+            this.tEnum = new TermEnumerator(termEnum, termDocs, fieldName, this);
+        }
+
+        /// <summary>
+        /// Method to attempt to parse out the value from the encoded string
+        /// and sets the value of Current.
+        /// </summary>
+        /// <param name="s">The encoded string.</param>
+        /// <param name="?">The value.</param>
+        /// <returns>True if the value was successfully parsed, false if we reached the
+        /// end of encoded values in the fiele and only the tries remain.</returns>
+        protected abstract bool TryParse(string s);
+
+        /// <summary>
+        /// Access the enumerator for the terms.
+        /// </summary>
+        public TermEnumerator Terms
+        {
+            get { return this.tEnum; }
+        }
+
+        /// <summary>
+        /// Access the enumerator for the TermDocs.
+        /// </summary>
+        public TermDocEnumerator.TermDocUsingTermsEnumerator Docs
+        {
+            get
+            {
+                if (this.termDocs == null)
+                {
+                    throw new NotSupportedException("This instance does not support enumeration over the document ids.");
+                }
+                else
+                {
+                    return this.tdEnum;
+                }
+            }
+        }
+
+        #region IDisposable Members
+
+        /// <summary>
+        /// Dispose of the instance.
+        /// </summary>
+        public void Dispose()
+        {
+            if (!this.disposed)
+            {
+                this.disposed = true;
+                if (this.termEnum != null)
+                {
+                    this.termEnum.Close();
+                }
+                if (this.termDocs != null)
+                {
+                    this.termDocs.Close();
+                }
+                GC.SuppressFinalize(this);
+            }
+        }
+
+        #endregion
+
+        /// <summary>
+        /// The enumerator over the terms in an index.
+        /// </summary>
+        public class TermEnumerator : IEnumerator<T>, IEnumerable<T>
+        {
+            /// <summary>
+            /// The underlying TermEnum;
+            /// </summary>
+            private TermEnum termEnum;
+
+            /// <summary>
+            /// The optional TermDocs.
+            /// </summary>
+            private TermDocs termDocs;
+
+            /// <summary>
+            /// The current term in the enum.
+            /// </summary>
+            private Term currentTerm;
+
+            /// <summary>
+            /// The field name, if any for the enum.
+            /// </summary>
+            protected string fieldName;
+
+            /// <summary>
+            /// Whether the enumerator has moved beyond the first position.
+            /// </summary>
+            private bool isFirst = true;
+
+            /// <summary>
+            /// THe enclosing instance, called back to in order to parse the field.
+            /// </summary>
+            private FieldEnumerator<T> enclosing;
+
+            /// <summary>
+            /// Ctor.
+            /// </summary>
+            /// <param name="termEnum">The TermEnum to wrap.</param>
+            /// <param name="termDocs">The TermDocs to wrap.</param>
+            public TermEnumerator(TermEnum termEnum, TermDocs termDocs, string field, FieldEnumerator<T> enclosing)
+            {
+                this.termEnum = termEnum;
+                this.termDocs = termDocs;
+                this.fieldName = field;
+                this.enclosing = enclosing;
+            }
+
+            #region IEnumerator<T> Members
+
+            /// <summary>
+            /// The current item in the enumerator.
+            /// </summary>
+            public T Current
+            {
+                get;
+                internal set;
+            }
+
+            #endregion
+
+            #region IEnumerator Members
+
+            /// <summary>
+            /// Current item in the enumerator.
+            /// </summary>
+            object IEnumerator.Current
+            {
+                get { return (object)this.Current; }
+            }
+
+            /// <summary>
+            /// Advance to the next item.
+            /// </summary>
+            /// <returns></returns>
+            public bool MoveNext()
+            {
+                if (this.isFirst)
+                {
+                    this.isFirst = false;
+                }
+                else
+                {
+                    if (!this.termEnum.Next())
+                    {
+                        return false;
+                    }
+                }
+
+                this.currentTerm = termEnum.Term();
+                if (this.currentTerm == null || (!this.currentTerm.Field().Equals(this.fieldName)))
+                {
+                    return false;
+                }
+
+                if (this.enclosing.TryParse(this.currentTerm.Text()))
+                {
+                    if (this.termDocs != null)
+                    {
+                        this.termDocs.Seek(this.termEnum);
+                    }
+                    return true;
+                }
+
+                return false;
+            }
+
+            /// <summary>
+            /// Reset the enumerator to the beginngin.
+            /// </summary>
+            public void Reset()
+            {
+                throw new NotSupportedException("The enumerator cannot be reset");
+            }
+
+            #endregion
+
+            #region IDisposable Members
+
+            public void Dispose()
+            {
+                // noop
+            }
+
+            #endregion
+
+            #region IEnumerable<T> Members
+
+            /// <summary>
+            /// Accessor to IEnumerator-T-."/>
+            /// </summary>
+            /// <returns></returns>
+            public IEnumerator<T> GetEnumerator()
+            {
+                return this;
+            }
+
+            #endregion
+
+            #region IEnumerable Members
+
+            /// <summary>
+            /// Accessor to IEnumertor.
+            /// </summary>
+            /// <returns></returns>
+            IEnumerator IEnumerable.GetEnumerator()
+            {
+                return this.GetEnumerator();
+            }
+
+            #endregion
+        }
+    }
+
+    /// <summary>
+    /// Class to handle creating a TermDocs and allowing for seeking and enumeration. Used
+    /// when you have a set of one or moreterms for which you want to enumerate over the 
+    /// documents that contain those terms.
+    /// </summary>
+    public class TermDocEnumerator : IEnumerable<int>, IDisposable
+    {
+        /// <summary>
+        /// The underlying TermDocs.
+        /// </summary>
+        private TermDocs termDocs;
+
+        /// <summary>
+        /// Ctor.
+        /// </summary>
+        /// <param name="termDocs">The TermDocs to wrap.</param>
+        public TermDocEnumerator(TermDocs termDocs)
+        {
+            this.termDocs = termDocs;
+        }
+
+        /// <summary>
+        /// Seek to a specific term.
+        /// </summary>
+        /// <param name="t"></param>
+        public void Seek(Term t)
+        {
+            this.termDocs.Seek(t);
+        }
+
+        #region IEnumerable<int> Members
+
+        public IEnumerator<int> GetEnumerator()
+        {
+            return new TermDocUsingTermsEnumerator(this.termDocs);
+        }
+
+        #endregion
+
+        #region IEnumerable Members
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return this.GetEnumerator();
+        }
+
+        #endregion
+
+        #region IDisposable Members
+
+        /// <summary>
+        /// Dispose of the instance, closing the termdocs.
+        /// </summary>
+        public void Dispose()
+        {
+            if (this.termDocs != null)
+            {
+                termDocs.Close();
+            }
+        }
+
+        #endregion
+
+        /// <summary>
+        /// Class to handle enumeration over the TermDocs that does NOT close them
+        /// on a call to Dispose!
+        /// </summary>
+        public class TermDocUsingTermsEnumerator : IEnumerable<int>, IEnumerator<int>
+        {
+            /// <summary>
+            /// A reference to an outside TermEnum that is used to position
+            /// the TermDocs.  It can be null.
+            /// </summary>
+            private TermEnum termEnum;
+
+            /// <summary>
+            /// The underlying TermDocs.
+            /// </summary>
+            private TermDocs termDocs;
+
+            /// <summary>
+            /// Ctor.
+            /// </summary>
+            /// <param name="termDocs">TermDocs to wrap</param>
+            internal TermDocUsingTermsEnumerator(TermDocs termDocs)
+                : this(termDocs, null)
+            { }
+
+            /// <summary>
+            /// Ctor.
+            /// </summary>
+            /// <param name="td">Underlying TermDocs.</param>
+            /// <param name="fieldEnum">Enclosing field enum.</param>
+            internal TermDocUsingTermsEnumerator(TermDocs td, TermEnum termEnum)
+            {
+                this.termDocs = td;
+                this.termEnum = termEnum;
+            }
+
+            /// <summary>
+            /// Seel to a term in the underlying TermDocs.
+            /// </summary>
+            /// <param name="te">The point to seek to.</param>
+            internal void Seek(TermEnum te)
+            {
+                this.termDocs.Seek(te);
+            }
+
+            #region IEnumerable<int> Members
+
+            /// <summary>
+            /// Get the enumerator.
+            /// </summary>
+            /// <returns></returns>
+            public IEnumerator<int> GetEnumerator()
+            {
+                return this;
+            }
+
+            #endregion
+
+            #region IEnumerable Members
+
+            /// <summary>
+            /// Get the enumerator.
+            /// </summary>
+            /// <returns></returns>
+            IEnumerator IEnumerable.GetEnumerator()
+            {
+                return this.GetEnumerator();
+            }
+
+            #endregion
+
+            #region IEnumerator<int> Members
+
+            /// <summary>
+            /// The current document id.
+            /// </summary>
+            public int Current
+            {
+                get { return this.termDocs.Doc(); }
+            }
+
+            #endregion
+
+            #region IDisposable Members
+
+            /// <summary>
+            /// Dispose impl.
+            /// </summary>
+            public void Dispose()
+            {
+                // noop as the closing of the underlying
+                // TermDocs is handled by the containing class
+            }
+
+            #endregion
+
+            #region IEnumerator Members
+
+            /// <summary>
+            /// The current item.
+            /// </summary>
+            object IEnumerator.Current
+            {
+                get { throw new NotImplementedException(); }
+            }
+
+            /// <summary>
+            /// Move to the next item.
+            /// </summary>
+            /// <returns>True if more, false if not.</returns>
+            public bool MoveNext()
+            {
+                return this.termDocs.Next();
+            }
+
+            /// <summary>
+            /// Not implemented. Use Seek instead.
+            /// </summary>
+            public void Reset()
+            {
+                throw new NotImplementedException();
+            }
+
+            #endregion
+        }
+    }
+
+
+    /// <summary>
+    /// Implementation for enumerating over terms with a string value.
+    /// </summary>
+    public class StringFieldEnumerator : FieldEnumerator<string>
+    {
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        public StringFieldEnumerator(IndexReader reader, string fieldName)
+        {
+            this.Init(reader, fieldName);
+        }
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        /// <param name="includeDocs">Whether the TermDocs will also be enumerated.</param>
+        public StringFieldEnumerator(IndexReader reader, string fieldName, bool includeDocs)
+        {
+            this.Init(reader, fieldName, includeDocs);
+        }
+
+        /// <summary>
+        /// Sets the value of current.
+        /// </summary>
+        /// <param name="s">The string.</param>
+        /// <returns>Always true.</returns>
+        protected override bool TryParse(string s)
+        {
+            this.tEnum.Current = s;
+            return true;
+        }
+    }
+
+    /// <summary>
+    /// Base for enumerating over numeric fields.
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    public abstract class NumericFieldEnum<T> : FieldEnumerator<T>
+    {
+        /// <summary>
+        /// The parser type for the field being enumerated.
+        /// </summary>
+        private FieldParser parser;
+
+        /// <summary>
+        /// Initialize the instance.
+        /// </summary>
+        /// <param name="reader">The reader.</param>
+        /// <param name="field">The field name.</param>
+        /// <param name="includeDocs">Whether to include a TermDoc enum.</param>
+        /// <param name="parser">The parser to use on the field.</param>
+        protected void Init(IndexReader reader, string field, bool includeDocs, FieldParser parser)
+        {
+            base.Init(reader, field, includeDocs);
+            this.parser = parser;
+        }
+
+        /// <summary>
+        /// Overridden from base.
+        /// </summary>
+        /// <param name="s">String to parse.</param>
+        /// <returns></returns>
+        protected override bool TryParse(string s)
+        {
+            if (this.parser == FieldParser.Numeric)
+            {
+                return this.TryParseNumeric(s);
+            }
+            else
+            {
+                return this.TryParseString(s);
+            }
+        }
+
+        /// <summary>
+        /// Parse out a standard string and set the value of current.
+        /// </summary>
+        /// <param name="s">String to parse.</param>
+        /// <returns>True on success.</returns>
+        protected abstract bool TryParseString(string s);
+
+        /// <summary>
+        /// Parse out an encoded numeric string and set the value of current.
+        /// </summary>
+        /// <param name="s">String to parse.</param>
+        /// <returns>True on success.</returns>
+        protected abstract bool TryParseNumeric(string s);
+    }
+
+    /// <summary>
+    /// Implementation for enumerating over all of the terms in an int numeric field.
+    /// </summary>
+    public class IntFieldEnumerator : NumericFieldEnum<int>
+    {
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        public IntFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser)
+        {
+            this.Init(reader, fieldName, true, parser);
+        }
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        /// <param name="includeDocs">Whether the TermDocs will also be enumerated.</param>
+        public IntFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser, bool includeDocs)
+        {
+            this.Init(reader, fieldName, includeDocs, parser);
+        }
+
+        /// <summary>
+        /// Parse the int from the string.
+        /// </summary>
+        /// <param name="s">String to parse.</param>
+        /// <returns>Always true.</returns>
+        protected override bool TryParseString(string s)
+        {
+            this.tEnum.Current = Int32.Parse(s);
+            return true;
+        }
+
+        /// <summary>
+        /// Parse the int from an encoded string.
+        /// </summary>
+        /// <param name="s">String to parse.</param>
+        /// <returns>True if the parse was successful, false indicating failure
+        /// and the end of useful terms in the numeric field.</returns>
+        protected override bool TryParseNumeric(string s)
+        {
+            int shift = s[0] - NumericUtils.SHIFT_START_INT;
+            if (shift > 0 && shift <= 31)
+            {
+                return false;
+            }
+            else
+            {
+                this.tEnum.Current = NumericUtils.PrefixCodedToInt(s);
+                return true;
+            }
+        }
+    }
+
+    /// <summary>
+    /// Implementation for enumerating over all of the terms in a float numeric field.
+    /// </summary>
+    public class FloatFieldEnumerator : NumericFieldEnum<float>
+    {
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        public FloatFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser)
+        {
+            this.Init(reader, fieldName, true, parser);
+        }
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        /// <param name="includeDocs">Whether the TermDocs will also be enumerated.</param>
+        public FloatFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser, bool includeDocs)
+        {
+            this.Init(reader, fieldName, includeDocs, parser);
+        }
+
+        /// <summary>
+        /// Parse the float from a string.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>Always true.</returns>
+        protected override bool TryParseString(string s)
+        {
+            this.tEnum.Current = float.Parse(s);
+            return true;
+        }
+
+        /// <summary>
+        /// Parse the float from a numeric field.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>True if the string was parsed, false to signify the
+        /// end of usable terms in a numeric field.</returns>
+        protected override bool TryParseNumeric(string s)
+        {
+            int shift = s[0] - NumericUtils.SHIFT_START_INT;
+            if (shift > 0 && shift <= 31)
+            {
+                return false;
+            }
+            else
+            {
+                this.tEnum.Current = NumericUtils.SortableIntToFloat(NumericUtils.PrefixCodedToInt(s));
+                return true;
+            }
+        }
+    }
+
+    /// <summary>
+    /// Implementation for enumerating over all of the terms in a double numeric field.
+    /// </summary>
+    public class DoubleFieldEnumerator : NumericFieldEnum<double>
+    {
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        public DoubleFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser)
+        {
+            this.Init(reader, fieldName, true, parser);
+        }
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        /// <param name="includeDocs">Whether the TermDocs will also be enumerated.</param>
+        public DoubleFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser, bool includeDocs)
+        {
+            this.Init(reader, fieldName, includeDocs, parser);
+        }
+
+        /// <summary>
+        /// Parse the double from a string.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>Always true.</returns>
+        protected override bool TryParseString(string s)
+        {
+            this.tEnum.Current = Double.Parse(s);
+            return true;
+        }
+
+        /// <summary>
+        /// Parse the double from a numeric field.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>True if the string was parsed, false to indicate the end
+        /// of usable numeric terms.</returns>
+        protected override bool TryParseNumeric(string s)
+        {
+            int shift = s[0] - NumericUtils.SHIFT_START_LONG;
+            if (shift > 0 && shift <= 63)
+            {
+                return false;
+            }
+            else
+            {
+                this.tEnum.Current = NumericUtils.SortableLongToDouble(NumericUtils.PrefixCodedToLong(s));
+                return true;
+            }
+        }
+    }
+
+    /// <summary>
+    /// Implementation for enumerating over all of the terms in a long numeric field.
+    /// </summary>
+    public class LongFieldEnumerator : NumericFieldEnum<long>
+    {
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        public LongFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser)
+        {
+            this.Init(reader, fieldName, true, parser);
+        }
+
+        /// <summary>
+        /// Construct an enumerator over one field.
+        /// </summary>
+        /// <param name="reader">Index reader.</param>
+        /// <param name="fieldName">The field to read.</param>
+        /// <param name="includeDocs">Whether the TermDocs will also be enumerated.</param>
+        public LongFieldEnumerator(IndexReader reader, string fieldName, FieldParser parser, bool includeDocs)
+        {
+            this.Init(reader, fieldName, includeDocs, parser);
+        }
+
+        /// <summary>
+        /// Parse the long from a string.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>Always true.</returns>
+        protected override bool TryParseString(string s)
+        {
+            this.tEnum.Current = long.Parse(s);
+            return true;
+        }
+
+        /// <summary>
+        /// Parse the long from a numeric field.
+        /// </summary>
+        /// <param name="s">The string to parse.</param>
+        /// <returns>True if the string was parsed, false to inidicate
+        /// the end of usable terms in a numeric field.</returns>
+        protected override bool TryParseNumeric(string s)
+        {
+            int shift = s[0] - NumericUtils.SHIFT_START_LONG;
+            if (shift > 0 && shift <= 63)
+            {
+                return false;
+            }
+            else
+            {
+                this.tEnum.Current = NumericUtils.PrefixCodedToLong(s);
+                return true;
+            }
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/SegmentsGenCommit.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net/Index/SegmentsGenCommit.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/SegmentsGenCommit.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/SegmentsGenCommit.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,115 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Lucene.Net.Store;
+
+namespace Lucene.Net.Index
+{
+    /// <summary>
+    /// Class that will force an index writer to open an index based
+    /// on the generation in the segments.gen file as opposed to the
+    /// highest generation found in a directory listing.
+    /// 
+    /// A use case for using this IndexCommit when opening an IndexWriter
+    /// would be if index snapshots (source) are being copied over an 
+    /// existing index (target) and the source now has a lower generation
+    /// than the target due to initiating a rebuild of the index. 
+    /// </summary>
+    public class SegmentsGenCommit : IndexCommit
+    {
+        /// <summary>
+        /// The index.
+        /// </summary>
+        private Directory directory;
+
+        /// <summary>
+        /// The generation to use.
+        /// </summary>
+        private long generation = long.MinValue;
+
+        /// <summary>
+        /// Ctor.
+        /// </summary>
+        /// <param name="d">The index directory.</param>
+        public SegmentsGenCommit(Directory d)
+        {
+            this.directory = d;
+            this.ReadDirectory();
+        }
+
+        /// <summary>
+        /// Get the segments_n file for the generation found in the 
+        /// segments.gen file.
+        /// </summary>
+        /// <returns>The segments_n file to use.</returns>
+        public override string GetSegmentsFileName()
+        {
+            return IndexFileNames.FileNameFromGeneration(IndexFileNames.SEGMENTS, string.Empty, this.generation);
+        }
+
+        public override long GetGeneration()
+        {
+            return this.generation;
+        }
+
+        public override ICollection<string> GetFileNames()
+        {
+            throw new NotImplementedException();
+        }
+
+        public override Directory GetDirectory()
+        {
+            return this.directory;
+        }
+
+        /// <summary>
+        /// Read the segments.gen file to get the generation number.
+        /// </summary>
+        private void ReadDirectory()
+        {
+            IndexInput genInput = null;
+            try
+            {
+                genInput = directory.OpenInput(IndexFileNames.SEGMENTS_GEN);
+
+                if (genInput != null)
+                {
+                    int version = genInput.ReadInt();
+                    if (version == Lucene.Net.Index.SegmentInfos.FORMAT_LOCKLESS)
+                    {
+                        long gen0 = genInput.ReadLong();
+                        long gen1 = genInput.ReadLong();
+                        if (gen0 == gen1)
+                        {
+                            // The file is consistent, use the generation
+                            this.generation = gen0;
+                        }
+                    }
+                }
+            }
+            finally
+            {
+                genInput.Close();
+            }
+        }
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/TermVectorEnumerator.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net/Index/TermVectorEnumerator.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/TermVectorEnumerator.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Index/TermVectorEnumerator.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,194 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Lucene.Net.Index
+{
+    /// <summary>
+    /// Class to allow for enumerating over the documents in the index to 
+    /// retrieve the term vector for each one.
+    /// </summary>
+    public class TermVectorEnumerator : IEnumerator<TermFreqVector>, IEnumerable<TermFreqVector>
+    {
+        /// <summary>
+        /// Current document being accessed.
+        /// </summary>
+        private int document = -1;
+
+        /// <summary>
+        /// The field name the vectors are being accessed from.
+        /// </summary>
+        private string fieldName;
+
+        /// <summary>
+        /// The index reader that the vetors are retreived from.
+        /// </summary>
+        private IndexReader reader;
+
+        /// <summary>
+        /// The return value should a document be deleted.
+        /// </summary>
+        private EmptyVector emptyVector;
+
+        /// <summary>
+        /// Ctor.
+        /// </summary>
+        /// <param name="reader">The index reader used to read the vectors.</param>
+        /// <param name="field">The name of the field the vectors are read from.</param>
+        public TermVectorEnumerator(IndexReader reader, string field)
+        {
+            this.reader = reader;
+            this.fieldName = field;
+            this.emptyVector = new EmptyVector(field);
+        }
+
+        #region IEnumerator<TermFreqVector> Members
+
+        public TermFreqVector Current
+        {
+            get { return this.CurrentVector(); }
+        }
+
+        #endregion
+
+        #region IDisposable Members
+
+        public void Dispose()
+        {
+            // this is a noop as we do not want to close the reader
+        }
+
+        #endregion
+
+        #region IEnumerator Members
+
+        object IEnumerator.Current
+        {
+            get { return this.CurrentVector(); }
+        }
+
+        public bool MoveNext()
+        {
+            this.document++;
+            return this.document < this.reader.MaxDoc();
+        }
+
+        public void Reset()
+        {
+            this.document = 0;
+        }
+
+        #endregion
+
+        #region IEnumerable<TermFreqVector> Members
+
+        public IEnumerator<TermFreqVector> GetEnumerator()
+        {
+            return (IEnumerator<TermFreqVector>)this;
+        }
+
+        #endregion
+
+        #region IEnumerable Members
+
+        IEnumerator IEnumerable.GetEnumerator()
+        {
+            return (IEnumerator<TermFreqVector>)this;
+        }
+
+        #endregion
+
+        /// <summary>
+        /// Retrieve the current TermFreqVector from the index.
+        /// </summary>
+        /// <returns>The current TermFreqVector.</returns>
+        private TermFreqVector CurrentVector()
+        {
+            if (this.reader.IsDeleted(this.document))
+            {
+                return this.emptyVector;
+            }
+            else
+            {
+                TermFreqVector vector = this.reader.GetTermFreqVector(this.document, this.fieldName);
+                if (vector == null)
+                {
+                    vector = this.emptyVector;
+                }
+                return vector;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A simple TermFreqVector implementation for an empty vector for use
+    /// with a deleted document or a document that does not have the field
+    /// that is being enumerated.
+    /// </summary>
+    public class EmptyVector : TermFreqVector
+    {
+        private string field;
+
+        private string[] emptyString = new string[0];
+
+        private int[] emptyInt = new int[0];
+
+        public EmptyVector(string field)
+        {
+            this.field = field;
+        }
+
+        #region TermFreqVector Members
+
+        public string GetField()
+        {
+            return this.field;
+        }
+
+        public int Size()
+        {
+            return 0;
+        }
+
+        public string[] GetTerms()
+        {
+            return this.emptyString;
+        }
+
+        public int[] GetTermFrequencies()
+        {
+            return this.emptyInt;
+        }
+
+        public int IndexOf(string term)
+        {
+            return 0;
+        }
+
+        public int[] IndexesOf(string[] terms, int start, int len)
+        {
+            return this.emptyInt;
+        }
+
+        #endregion
+    }
+}

Added: lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Properties/AssemblyInfo.cs
URL: http://svn.apache.org/viewvc/lucene/lucene.net/trunk/C%23/contrib/Contrib.Net/Contrib.Net/Properties/AssemblyInfo.cs?rev=920415&view=auto
==============================================================================
--- lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Properties/AssemblyInfo.cs (added)
+++ lucene/lucene.net/trunk/C#/contrib/Contrib.Net/Contrib.Net/Properties/AssemblyInfo.cs Mon Mar  8 17:35:49 2010
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Contrib.Net(Apache Lucene.Net)")]
+[assembly: AssemblyDescription("Project for containing Lucene.Net specific contrib items")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("The Apache Software Foundation")]
+[assembly: AssemblyProduct("Contrib.Net")]
+[assembly: AssemblyCopyright("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyTrademark("Copyright 2006 - 2010 The Apache Software Foundation")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("07022a0d-81bd-4d33-aba1-0bc8241524f5")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("2.9.2")]
+[assembly: AssemblyFileVersion("2.9.2")]



Mime
View raw message