lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r411501 [29/30] - 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/Docu...
Date Sun, 04 Jun 2006 02:41:25 GMT
Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestPhrasePrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestPhrasePrefixQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestPhrasePrefixQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestPhrasePrefixQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 using Document = Lucene.Net.Documents.Document;
@@ -23,6 +24,7 @@
 using TermEnum = Lucene.Net.Index.TermEnum;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using NUnit.Framework;
+
 namespace Lucene.Net.Search
 {
 	
@@ -31,27 +33,28 @@
 	/// </summary>
 	/// <author>  Otis Gospodnetic
 	/// </author>
-	/// <version>  $Id: TestPhrasePrefixQuery.java,v 1.3 2004/03/29 22:48:06 cutting Exp $
+	/// <version>  $Id: TestPhrasePrefixQuery.java 150497 2004-09-07 18:26:36Z dnaber $
 	/// </version>
 	[TestFixture]
     public class TestPhrasePrefixQuery
 	{
+		
 		/// <summary> </summary>
 		[Test]
-		public virtual void  TestPhrasePrefix()
+        public virtual void  TestPhrasePrefix()
 		{
 			RAMDirectory indexStore = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
-			Document doc1 = new Document();
-			Document doc2 = new Document();
-			Document doc3 = new Document();
-			Document doc4 = new Document();
-			Document doc5 = new Document();
-			doc1.Add(Field.Text("body", "blueberry pie"));
-			doc2.Add(Field.Text("body", "blueberry strudel"));
-			doc3.Add(Field.Text("body", "blueberry pizza"));
-			doc4.Add(Field.Text("body", "blueberry chewing gum"));
-			doc5.Add(Field.Text("body", "piccadilly circus"));
+			Lucene.Net.Documents.Document doc1 = new Lucene.Net.Documents.Document();
+			Lucene.Net.Documents.Document doc2 = new Lucene.Net.Documents.Document();
+			Lucene.Net.Documents.Document doc3 = new Lucene.Net.Documents.Document();
+			Lucene.Net.Documents.Document doc4 = new Lucene.Net.Documents.Document();
+			Lucene.Net.Documents.Document doc5 = new Lucene.Net.Documents.Document();
+			doc1.Add(new Field("body", "blueberry pie", Field.Store.YES, Field.Index.TOKENIZED));
+			doc2.Add(new Field("body", "blueberry strudel", Field.Store.YES, Field.Index.TOKENIZED));
+			doc3.Add(new Field("body", "blueberry pizza", Field.Store.YES, Field.Index.TOKENIZED));
+			doc4.Add(new Field("body", "blueberry chewing gum", Field.Store.YES, Field.Index.TOKENIZED));
+			doc5.Add(new Field("body", "piccadilly circus", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc1);
 			writer.AddDocument(doc2);
 			writer.AddDocument(doc3);

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestPhraseQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestPhraseQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestPhraseQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestPhraseQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,15 +13,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
+using Analyzer = Lucene.Net.Analysis.Analyzer;
 using StopAnalyzer = Lucene.Net.Analysis.StopAnalyzer;
+using TokenStream = Lucene.Net.Analysis.TokenStream;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+using WhitespaceTokenizer = Lucene.Net.Analysis.WhitespaceTokenizer;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
+using Directory = Lucene.Net.Store.Directory;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
 namespace Lucene.Net.Search
 {
 	
@@ -35,18 +41,53 @@
 	[TestFixture]
     public class TestPhraseQuery
 	{
-		private IndexSearcher searcher;
+		private class AnonymousClassAnalyzer : Analyzer
+		{
+			public AnonymousClassAnalyzer(TestPhraseQuery enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(TestPhraseQuery enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestPhraseQuery enclosingInstance;
+			public TestPhraseQuery Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+
+            public override TokenStream TokenStream(System.String fieldName, System.IO.TextReader reader)
+			{
+				return new WhitespaceTokenizer(reader);
+			}
+			
+			public override int GetPositionIncrementGap(System.String fieldName)
+			{
+				return 100;
+			}
+		}
+
+        private IndexSearcher searcher;
 		private PhraseQuery query;
 		private RAMDirectory directory;
 		
-        [TestFixtureSetUp]
-		public virtual void  SetUp()
+		[TestFixtureSetUp]
+        public virtual void  SetUp()
 		{
 			directory = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+			Analyzer analyzer = new AnonymousClassAnalyzer(this);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true);
 			
-			Document doc = new Document();
-			doc.Add(Field.Text("Field", "one two three four five"));
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("field", "one two three four five", Field.Store.YES, Field.Index.TOKENIZED));
+			doc.Add(new Field("repeated", "this is a repeated field - first part", Field.Store.YES, Field.Index.TOKENIZED));
+			Field repeatedField = new Field("repeated", "second part of a repeated field", Field.Store.YES, Field.Index.TOKENIZED);
+			doc.Add(repeatedField);
 			writer.AddDocument(doc);
 			
 			writer.Optimize();
@@ -56,59 +97,57 @@
 			query = new PhraseQuery();
 		}
 		
-        [TestFixtureTearDown]
-		public virtual void  TearDown()
+		[TestFixtureTearDown]
+        public virtual void  TearDown()
 		{
 			searcher.Close();
 			directory.Close();
 		}
 		
-        [Test]
-		public virtual void  TestNotCloseEnough()
+		[Test]
+        public virtual void  TestNotCloseEnough()
 		{
 			query.SetSlop(2);
-			query.Add(new Term("Field", "one"));
-			query.Add(new Term("Field", "five"));
+			query.Add(new Term("field", "one"));
+			query.Add(new Term("field", "five"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(0, hits.Length());
 		}
 		
-        [Test]
-		public virtual void  TestBarelyCloseEnough()
+		[Test]
+        public virtual void  TestBarelyCloseEnough()
 		{
 			query.SetSlop(3);
-			query.Add(new Term("Field", "one"));
-			query.Add(new Term("Field", "five"));
+			query.Add(new Term("field", "one"));
+			query.Add(new Term("field", "five"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length());
 		}
 		
 		/// <summary> Ensures slop of 0 works for exact matches, but not reversed</summary>
 		[Test]
-		public virtual void  TestExact()
+        public virtual void  TestExact()
 		{
 			// slop is zero by default
-			query.Add(new Term("Field", "four"));
-			query.Add(new Term("Field", "five"));
+			query.Add(new Term("field", "four"));
+			query.Add(new Term("field", "five"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length(), "exact match");
 			
 			query = new PhraseQuery();
-			query.Add(new Term("Field", "two"));
-			query.Add(new Term("Field", "one"));
+			query.Add(new Term("field", "two"));
+			query.Add(new Term("field", "one"));
 			hits = searcher.Search(query);
 			Assert.AreEqual(0, hits.Length(), "reverse not exact");
 		}
 		
-        [Test]
-		public virtual void  TestSlop1()
+		[Test]
+        public virtual void  TestSlop1()
 		{
-            SetUp();
-
 			// Ensures slop of 1 works with terms in order.
 			query.SetSlop(1);
-			query.Add(new Term("Field", "one"));
-			query.Add(new Term("Field", "two"));
+			query.Add(new Term("field", "one"));
+			query.Add(new Term("field", "two"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length(), "in order");
 			
@@ -116,8 +155,8 @@
 			// must be at least 2.
 			query = new PhraseQuery();
 			query.SetSlop(1);
-			query.Add(new Term("Field", "two"));
-			query.Add(new Term("Field", "one"));
+			query.Add(new Term("field", "two"));
+			query.Add(new Term("field", "one"));
 			hits = searcher.Search(query);
 			Assert.AreEqual(0, hits.Length(), "reversed, slop not 2 or more");
 		}
@@ -126,18 +165,16 @@
 		[Test]
         public virtual void  TestOrderDoesntMatter()
 		{
-            SetUp();
-
 			query.SetSlop(2); // must be at least two for reverse order match
-			query.Add(new Term("Field", "two"));
-			query.Add(new Term("Field", "one"));
+			query.Add(new Term("field", "two"));
+			query.Add(new Term("field", "one"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length(), "just sloppy enough");
 			
 			query = new PhraseQuery();
 			query.SetSlop(2);
-			query.Add(new Term("Field", "three"));
-			query.Add(new Term("Field", "one"));
+			query.Add(new Term("field", "three"));
+			query.Add(new Term("field", "one"));
 			hits = searcher.Search(query);
 			Assert.AreEqual(0, hits.Length(), "not sloppy enough");
 		}
@@ -148,20 +185,18 @@
 		[Test]
         public virtual void  TestMulipleTerms()
 		{
-            SetUp();
-
 			query.SetSlop(2);
-			query.Add(new Term("Field", "one"));
-			query.Add(new Term("Field", "three"));
-			query.Add(new Term("Field", "five"));
+			query.Add(new Term("field", "one"));
+			query.Add(new Term("field", "three"));
+			query.Add(new Term("field", "five"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length(), "two total moves");
 			
 			query = new PhraseQuery();
 			query.SetSlop(5); // it takes six moves to match this phrase
-			query.Add(new Term("Field", "five"));
-			query.Add(new Term("Field", "three"));
-			query.Add(new Term("Field", "one"));
+			query.Add(new Term("field", "five"));
+			query.Add(new Term("field", "three"));
+			query.Add(new Term("field", "one"));
 			hits = searcher.Search(query);
 			Assert.AreEqual(0, hits.Length(), "slop of 5 not close enough");
 			
@@ -170,14 +205,14 @@
 			Assert.AreEqual(1, hits.Length(), "slop of 6 just right");
 		}
 		
-        [Test]
-		public virtual void  TestPhraseQueryWithStopAnalyzer()
+		[Test]
+        public virtual void  TestPhraseQueryWithStopAnalyzer()
 		{
 			RAMDirectory directory = new RAMDirectory();
 			StopAnalyzer stopAnalyzer = new StopAnalyzer();
 			IndexWriter writer = new IndexWriter(directory, stopAnalyzer, true);
-			Document doc = new Document();
-			doc.Add(Field.Text("Field", "the stop words are here"));
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("field", "the stop words are here", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			writer.Close();
 			
@@ -185,34 +220,34 @@
 			
 			// valid exact phrase query
 			PhraseQuery query = new PhraseQuery();
-			query.Add(new Term("Field", "stop"));
-			query.Add(new Term("Field", "words"));
+			query.Add(new Term("field", "stop"));
+			query.Add(new Term("field", "words"));
 			Hits hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length());
 			
 			// currently StopAnalyzer does not leave "holes", so this matches.
 			query = new PhraseQuery();
-			query.Add(new Term("Field", "words"));
-			query.Add(new Term("Field", "here"));
+			query.Add(new Term("field", "words"));
+			query.Add(new Term("field", "here"));
 			hits = searcher.Search(query);
 			Assert.AreEqual(1, hits.Length());
 			
 			searcher.Close();
 		}
 		
-        [Test]
-		public virtual void  TestPhraseQueryInConjunctionScorer()
+		[Test]
+        public virtual void  TestPhraseQueryInConjunctionScorer()
 		{
 			RAMDirectory directory = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
 			
-			Document doc = new Document();
-			doc.Add(new Field("source", "marketing info", true, true, true));
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("source", "marketing info", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			
-			doc = new Document();
-			doc.Add(new Field("contents", "foobar", true, true, true));
-			doc.Add(new Field("source", "marketing info", true, true, true));
+			doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("contents", "foobar", Field.Store.YES, Field.Index.TOKENIZED));
+			doc.Add(new Field("source", "marketing info", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			
 			writer.Optimize();
@@ -228,24 +263,24 @@
 			
 			TermQuery termQuery = new TermQuery(new Term("contents", "foobar"));
 			BooleanQuery booleanQuery = new BooleanQuery();
-			booleanQuery.Add(termQuery, true, false);
-			booleanQuery.Add(phraseQuery, true, false);
+			booleanQuery.Add(termQuery, BooleanClause.Occur.MUST);
+			booleanQuery.Add(phraseQuery, BooleanClause.Occur.MUST);
 			hits = searcher.Search(booleanQuery);
 			Assert.AreEqual(1, hits.Length());
 			
 			searcher.Close();
 			
 			writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
-			doc = new Document();
-			doc.Add(new Field("contents", "map entry woo", true, true, true));
+			doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("contents", "map entry woo", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			
-			doc = new Document();
-			doc.Add(new Field("contents", "woo map entry", true, true, true));
+			doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("contents", "woo map entry", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			
-			doc = new Document();
-			doc.Add(new Field("contents", "map foobarword entry woo", true, true, true));
+			doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("contents", "map foobarword entry woo", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			
 			writer.Optimize();
@@ -264,19 +299,70 @@
 			Assert.AreEqual(2, hits.Length());
 			
 			booleanQuery = new BooleanQuery();
-			booleanQuery.Add(termQuery, true, false);
-			booleanQuery.Add(phraseQuery, true, false);
+			booleanQuery.Add(termQuery, BooleanClause.Occur.MUST);
+			booleanQuery.Add(phraseQuery, BooleanClause.Occur.MUST);
 			hits = searcher.Search(booleanQuery);
 			Assert.AreEqual(2, hits.Length());
 			
 			booleanQuery = new BooleanQuery();
-			booleanQuery.Add(phraseQuery, true, false);
-			booleanQuery.Add(termQuery, true, false);
+			booleanQuery.Add(phraseQuery, BooleanClause.Occur.MUST);
+			booleanQuery.Add(termQuery, BooleanClause.Occur.MUST);
 			hits = searcher.Search(booleanQuery);
 			Assert.AreEqual(2, hits.Length());
 			
 			searcher.Close();
 			directory.Close();
+		}
+		
+		[Test]
+        public virtual void  TestSlopScoring()
+		{
+			Directory directory = new RAMDirectory();
+			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+			
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("field", "foo firstname lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+			writer.AddDocument(doc);
+			
+			Lucene.Net.Documents.Document doc2 = new Lucene.Net.Documents.Document();
+			doc2.Add(new Field("field", "foo firstname xxx lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+			writer.AddDocument(doc2);
+			
+			Lucene.Net.Documents.Document doc3 = new Lucene.Net.Documents.Document();
+			doc3.Add(new Field("field", "foo firstname xxx yyy lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
+			writer.AddDocument(doc3);
+			
+			writer.Optimize();
+			writer.Close();
+			
+			Searcher searcher = new IndexSearcher(directory);
+			PhraseQuery query = new PhraseQuery();
+			query.Add(new Term("field", "firstname"));
+			query.Add(new Term("field", "lastname"));
+			query.SetSlop(System.Int32.MaxValue);
+			Hits hits = searcher.Search(query);
+			Assert.AreEqual(3, hits.Length());
+			// Make sure that those matches where the terms appear closer to
+			// each other get a higher score:
+			Assert.AreEqual(0.71, hits.Score(0), 0.01);
+			Assert.AreEqual(0, hits.Id(0));
+			Assert.AreEqual(0.44, hits.Score(1), 0.01);
+			Assert.AreEqual(1, hits.Id(1));
+			Assert.AreEqual(0.31, hits.Score(2), 0.01);
+			Assert.AreEqual(2, hits.Id(2));
+		}
+		
+		[Test]
+        public virtual void  TestWrappedPhrase()
+		{
+			query.Add(new Term("repeated", "first"));
+			query.Add(new Term("repeated", "part"));
+			query.Add(new Term("repeated", "second"));
+			query.Add(new Term("repeated", "part"));
+			query.SetSlop(99);
+			
+			Hits hits = searcher.Search(query);
+			Assert.AreEqual(0, hits.Length());
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestPositionIncrement.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestPositionIncrement.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestPositionIncrement.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestPositionIncrement.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using Analyzer = Lucene.Net.Analysis.Analyzer;
 using Token = Lucene.Net.Analysis.Token;
@@ -24,6 +25,7 @@
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using NUnit.Framework;
+
 namespace Lucene.Net.Search
 {
 	
@@ -32,7 +34,7 @@
 	/// </summary>
 	/// <author>  Doug Cutting
 	/// </author>
-	/// <version>  $Revision: 1.4 $
+	/// <version>  $Revision: 150585 $
 	/// </version>
 	[TestFixture]
     public class TestPositionIncrement
@@ -43,7 +45,8 @@
 			{
 				InitBlock(enclosingInstance);
 			}
-			private class AnonymousClassTokenStream : TokenStream
+
+            private class AnonymousClassTokenStream : TokenStream
 			{
 				public AnonymousClassTokenStream(AnonymousClassAnalyzer enclosingInstance)
 				{
@@ -62,7 +65,8 @@
 					}
 					
 				}
-				private System.String[] TOKENS = new System.String[]{"1", "2", "3", "4", "5"};
+
+                private System.String[] TOKENS = new System.String[]{"1", "2", "3", "4", "5"};
 				private int[] INCREMENTS = new int[]{1, 2, 1, 0, 1};
 				private int i = 0;
 				
@@ -95,14 +99,14 @@
 			}
 		}
 		
-        [Test]
-		public virtual void  TestSetPosition()
+		[Test]
+        public virtual void  TestSetPosition()
 		{
 			Analyzer analyzer = new AnonymousClassAnalyzer(this);
 			RAMDirectory store = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(store, analyzer, true);
-			Document d = new Document();
-			d.Add(Field.Text("Field", "bogus"));
+			Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
+			d.Add(new Field("field", "bogus", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(d);
 			writer.Optimize();
 			writer.Close();
@@ -112,44 +116,44 @@
 			Hits hits;
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "1"));
-			q.Add(new Term("Field", "2"));
+			q.Add(new Term("field", "1"));
+			q.Add(new Term("field", "2"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(0, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "2"));
-			q.Add(new Term("Field", "3"));
+			q.Add(new Term("field", "2"));
+			q.Add(new Term("field", "3"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(1, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "3"));
-			q.Add(new Term("Field", "4"));
+			q.Add(new Term("field", "3"));
+			q.Add(new Term("field", "4"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(0, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "2"));
-			q.Add(new Term("Field", "4"));
+			q.Add(new Term("field", "2"));
+			q.Add(new Term("field", "4"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(1, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "3"));
-			q.Add(new Term("Field", "5"));
+			q.Add(new Term("field", "3"));
+			q.Add(new Term("field", "5"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(1, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "4"));
-			q.Add(new Term("Field", "5"));
+			q.Add(new Term("field", "4"));
+			q.Add(new Term("field", "5"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(1, hits.Length());
 			
 			q = new PhraseQuery();
-			q.Add(new Term("Field", "2"));
-			q.Add(new Term("Field", "5"));
+			q.Add(new Term("field", "2"));
+			q.Add(new Term("field", "5"));
 			hits = searcher.Search(q);
 			Assert.AreEqual(0, hits.Length());
 		}
@@ -161,7 +165,7 @@
         public virtual void  TestIncrementingPositions()
 		{
 			Analyzer analyzer = new WhitespaceAnalyzer();
-			TokenStream ts = analyzer.TokenStream("Field", new System.IO.StringReader("one two three four five"));
+			TokenStream ts = analyzer.TokenStream("field", new System.IO.StringReader("one two three four five"));
 			
 			while (true)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestPrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestPrefixQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestPrefixQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestPrefixQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
@@ -21,6 +22,7 @@
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
 namespace Lucene.Net.Search
 {
 	
@@ -30,10 +32,10 @@
 	/// <author>  Erik Hatcher
 	/// </author>
 	[TestFixture]
-    public class TestPrefixQuery_
+    public class TestPrefixQuery
 	{
-        [Test]
-		public virtual void  TestPrefixQuery()
+		[Test]
+        public virtual void  TestPrefixQuery_Renamed_Method()
 		{
 			RAMDirectory directory = new RAMDirectory();
 			
@@ -41,8 +43,8 @@
 			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
 			for (int i = 0; i < categories.Length; i++)
 			{
-				Document doc = new Document();
-				doc.Add(Field.Keyword("category", categories[i]));
+				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+				doc.Add(new Field("category", categories[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
 				writer.AddDocument(doc);
 			}
 			writer.Close();

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestQueryTermVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestQueryTermVector.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestQueryTermVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestQueryTermVector.cs Sat Jun  3 19:41:13 2006
@@ -13,21 +13,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+
 namespace Lucene.Net.Search
 {
 	[TestFixture]
 	public class TestQueryTermVector
 	{
-        [TestFixtureSetUp]
-		protected virtual void  SetUp()
+		
+		[TestFixtureSetUp]
+        public virtual void  SetUp()
 		{
 		}
 		
-        [TestFixtureTearDown]
-		protected virtual void  TearDown()
+		[TestFixtureTearDown]
+        public virtual void  TearDown()
 		{
 			
 		}

Added: incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestRangeFilter.cs?rev=411501&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeFilter.cs Sat Jun  3 19:41:13 2006
@@ -0,0 +1,187 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ * 
+ * Licensed 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 NUnit.Framework;
+using IndexReader = Lucene.Net.Index.IndexReader;
+using Term = Lucene.Net.Index.Term;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary> A basic 'positive' Unit test class for the RangeFilter class.
+	/// 
+	/// <p>
+	/// NOTE: at the moment, this class only tests for 'positive' results,
+	/// it does not verify the results to ensure there are no 'false positives',
+	/// nor does it adequately test 'negative' results.  It also does not test
+	/// that garbage in results in an Exception.
+	/// </summary>
+	public class TestRangeFilter:BaseTestRangeFilter
+	{
+		public TestRangeFilter(System.String name) : base(name)
+		{
+		}
+		
+        public TestRangeFilter() : base()
+		{
+		}
+		
+        public virtual void  TestRangeFilterId()
+		{
+			
+			IndexReader reader = IndexReader.Open(index);
+			IndexSearcher search = new IndexSearcher(reader);
+			
+			int medId = ((maxId - minId) / 2);
+			
+			System.String minIP = Pad(minId);
+			System.String maxIP = Pad(maxId);
+			System.String medIP = Pad(medId);
+			
+			int numDocs = reader.NumDocs();
+			
+			Assert.AreEqual(numDocs, 1 + maxId - minId, "num of docs");
+			
+			Hits result;
+			Query q = new TermQuery(new Term("body", "body"));
+			
+			// test id, bounded on both ends
+			
+			result = search.Search(q, new RangeFilter("id", minIP, maxIP, T, T));
+			Assert.AreEqual(numDocs, result.Length(), "find all");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, maxIP, T, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "all but last");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, maxIP, F, T));
+			Assert.AreEqual(numDocs - 1, result.Length(), "all but first");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, maxIP, F, F));
+			Assert.AreEqual(numDocs - 2, result.Length(), "all but ends");
+			
+			result = search.Search(q, new RangeFilter("id", medIP, maxIP, T, T));
+			Assert.AreEqual(1 + maxId - medId, result.Length(), "med and up");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, medIP, T, T));
+			Assert.AreEqual(1 + medId - minId, result.Length(), "up to med");
+			
+			// unbounded id
+			
+			result = search.Search(q, new RangeFilter("id", minIP, null, T, F));
+			Assert.AreEqual(numDocs, result.Length(), "min and up");
+			
+			result = search.Search(q, new RangeFilter("id", null, maxIP, F, T));
+			Assert.AreEqual(numDocs, result.Length(), "max and down");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, null, F, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "not min, but up");
+			
+			result = search.Search(q, new RangeFilter("id", null, maxIP, F, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "not max, but down");
+			
+			result = search.Search(q, new RangeFilter("id", medIP, maxIP, T, F));
+			Assert.AreEqual(maxId - medId, result.Length(), "med and up, not max");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, medIP, F, T));
+			Assert.AreEqual(medId - minId, result.Length(), "not min, up to med");
+			
+			// very small sets
+			
+			result = search.Search(q, new RangeFilter("id", minIP, minIP, F, F));
+			Assert.AreEqual(0, result.Length(), "min,min,F,F");
+			result = search.Search(q, new RangeFilter("id", medIP, medIP, F, F));
+			Assert.AreEqual(0, result.Length(), "med,med,F,F");
+			result = search.Search(q, new RangeFilter("id", maxIP, maxIP, F, F));
+			Assert.AreEqual(0, result.Length(), "max,max,F,F");
+			
+			result = search.Search(q, new RangeFilter("id", minIP, minIP, T, T));
+			Assert.AreEqual(1, result.Length(), "min,min,T,T");
+			result = search.Search(q, new RangeFilter("id", null, minIP, F, T));
+			Assert.AreEqual(1, result.Length(), "nul,min,F,T");
+			
+			result = search.Search(q, new RangeFilter("id", maxIP, maxIP, T, T));
+			Assert.AreEqual(1, result.Length(), "max,max,T,T");
+			result = search.Search(q, new RangeFilter("id", maxIP, null, T, F));
+			Assert.AreEqual(1, result.Length(), "max,nul,T,T");
+			
+			result = search.Search(q, new RangeFilter("id", medIP, medIP, T, T));
+			Assert.AreEqual(1, result.Length(), "med,med,T,T");
+		}
+		
+        public virtual void  TestRangeFilterRand()
+		{
+			
+			IndexReader reader = IndexReader.Open(index);
+			IndexSearcher search = new IndexSearcher(reader);
+			
+			System.String minRP = Pad(minR);
+			System.String maxRP = Pad(maxR);
+			
+			int numDocs = reader.NumDocs();
+			
+			Assert.AreEqual(numDocs, 1 + maxId - minId, "num of docs");
+			
+			Hits result;
+			Query q = new TermQuery(new Term("body", "body"));
+			
+			// test extremes, bounded on both ends
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, maxRP, T, T));
+			Assert.AreEqual(numDocs, result.Length(), "find all");
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, maxRP, T, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "all but biggest");
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, maxRP, F, T));
+			Assert.AreEqual(numDocs - 1, result.Length(), "all but smallest");
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, maxRP, F, F));
+			Assert.AreEqual(numDocs - 2, result.Length(), "all but extremes");
+			
+			// unbounded
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, null, T, F));
+			Assert.AreEqual(numDocs, result.Length(), "smallest and up");
+			
+			result = search.Search(q, new RangeFilter("rand", null, maxRP, F, T));
+			Assert.AreEqual(numDocs, result.Length(), "biggest and down");
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, null, F, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "not smallest, but up");
+			
+			result = search.Search(q, new RangeFilter("rand", null, maxRP, F, F));
+			Assert.AreEqual(numDocs - 1, result.Length(), "not biggest, but down");
+			
+			// very small sets
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, minRP, F, F));
+			Assert.AreEqual(0, result.Length(), "min,min,F,F");
+			result = search.Search(q, new RangeFilter("rand", maxRP, maxRP, F, F));
+			Assert.AreEqual(0, result.Length(), "max,max,F,F");
+			
+			result = search.Search(q, new RangeFilter("rand", minRP, minRP, T, T));
+			Assert.AreEqual(1, result.Length(), "min,min,T,T");
+			result = search.Search(q, new RangeFilter("rand", null, minRP, F, T));
+			Assert.AreEqual(1, result.Length(), "nul,min,F,T");
+			
+			result = search.Search(q, new RangeFilter("rand", maxRP, maxRP, T, T));
+			Assert.AreEqual(1, result.Length(), "max,max,T,T");
+			result = search.Search(q, new RangeFilter("rand", maxRP, null, T, F));
+			Assert.AreEqual(1, result.Length(), "max,nul,T,T");
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestRangeQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestRangeQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
 using Document = Lucene.Net.Documents.Document;
@@ -21,6 +22,7 @@
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using NUnit.Framework;
+
 namespace Lucene.Net.Search
 {
 	
@@ -33,14 +35,14 @@
 		private int docCount = 0;
 		private RAMDirectory dir;
 		
-        [TestFixtureSetUp]
-		public virtual void  SetUp()
+		[TestFixtureSetUp]
+        public virtual void  SetUp()
 		{
 			dir = new RAMDirectory();
 		}
 		
-        [Test]
-		public virtual void  TestExclusive()
+		[Test]
+        public virtual void  TestExclusive()
 		{
 			Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
 			InitializeIndex(new System.String[]{"A", "B", "C", "D"});
@@ -62,8 +64,8 @@
 			searcher.Close();
 		}
 		
-        [Test]
-		public virtual void  TestInclusive()
+		[Test]
+        public virtual void  TestInclusive()
 		{
 			Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
 			
@@ -86,6 +88,49 @@
 			searcher.Close();
 		}
 		
+		[Test]
+        public virtual void  TestEqualsHashcode()
+		{
+			Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
+			query.SetBoost(1.0f);
+			Query other = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
+			other.SetBoost(1.0f);
+			
+			Assert.AreEqual(query, query, "query equals itself is true");
+			Assert.AreEqual(query, other, "equivalent queries are equal");
+			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
+			
+			other.SetBoost(2.0f);
+			Assert.IsFalse(query.Equals(other), "Different boost queries are not equal");
+			
+			other = new RangeQuery(new Term("notcontent", "A"), new Term("notcontent", "C"), true);
+			Assert.IsFalse(query.Equals(other), "Different fields are not equal");
+			
+			other = new RangeQuery(new Term("content", "X"), new Term("content", "C"), true);
+			Assert.IsFalse(query.Equals(other), "Different lower terms are not equal");
+			
+			other = new RangeQuery(new Term("content", "A"), new Term("content", "Z"), true);
+			Assert.IsFalse(query.Equals(other), "Different upper terms are not equal");
+			
+			query = new RangeQuery(null, new Term("content", "C"), true);
+			other = new RangeQuery(null, new Term("content", "C"), true);
+			Assert.AreEqual(query, other, "equivalent queries with null lowerterms are equal()");
+			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
+			
+			query = new RangeQuery(new Term("content", "C"), null, true);
+			other = new RangeQuery(new Term("content", "C"), null, true);
+			Assert.AreEqual(query, other, "equivalent queries with null upperterms are equal()");
+			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode returns same value");
+			
+			query = new RangeQuery(null, new Term("content", "C"), true);
+			other = new RangeQuery(new Term("content", "C"), null, true);
+			Assert.IsFalse(query.Equals(other), "queries with different upper and lower terms are not equal");
+			
+			query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
+			other = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
+			Assert.IsFalse(query.Equals(other), "queries with different inclusive are not equal");
+		}
+		
 		private void  InitializeIndex(System.String[] values)
 		{
 			IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
@@ -105,10 +150,10 @@
 		
 		private void  InsertDoc(IndexWriter writer, System.String content)
 		{
-			Document doc = new Document();
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
 			
-			doc.Add(Field.Keyword("id", "id" + docCount));
-			doc.Add(Field.UnStored("content", content));
+			doc.Add(new Field("id", "id" + docCount, Field.Store.YES, Field.Index.UN_TOKENIZED));
+			doc.Add(new Field("content", content, Field.Store.NO, Field.Index.TOKENIZED));
 			
 			writer.AddDocument(doc);
 			docCount++;

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestRemoteSearchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestRemoteSearchable.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestRemoteSearchable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestRemoteSearchable.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
@@ -21,29 +22,27 @@
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
 namespace Lucene.Net.Search
 {
 	
-	/// <version>  $Id: TestRemoteSearchable.java,v 1.7 2004/03/29 22:48:06 cutting Exp $
+	/// <version>  $Id: TestRemoteSearchable.java 150500 2004-09-08 18:10:09Z dnaber $
 	/// </version>
 	[TestFixture]
     public class TestRemoteSearchable
 	{
-		private static Lucene.Net.Search.Searchable Remote
+		
+		private static Lucene.Net.Search.Searchable GetRemote()
 		{
-			get
+			try
 			{
-				try
-				{
-					return LookupRemote();
-				}
-				catch (System.Exception e)
-				{
-					StartServer();
-					return LookupRemote();
-				}
+				return LookupRemote();
+			}
+			catch (System.Exception e)
+			{
+				StartServer();
+				return LookupRemote();
 			}
-			
 		}
 		
 		private static Lucene.Net.Search.Searchable LookupRemote()
@@ -56,14 +55,14 @@
 			// construct an index
 			RAMDirectory indexStore = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true);
-			Document doc = new Document();
-			doc.Add(Field.Text("test", "test text"));
+			Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+			doc.Add(new Field("test", "test text", Field.Store.YES, Field.Index.TOKENIZED));
 			writer.AddDocument(doc);
 			writer.Optimize();
 			writer.Close();
 			
 			// publish it
-			//// LocateRegistry.CreateRegistry(1099); // {{Aroush}}
+			// LocateRegistry.createRegistry(1099); // {{Aroush}}
 			Lucene.Net.Search.Searchable local = new IndexSearcher(indexStore);
 			RemoteSearchable impl = new RemoteSearchable(local);
 			System.Runtime.Remoting.RemotingServices.Marshal(impl, "http://localhost/Searchable");
@@ -72,7 +71,7 @@
 		private static void  Search(Query query)
 		{
 			// try to search the published index
-			Lucene.Net.Search.Searchable[] searchables = new Lucene.Net.Search.Searchable[]{Remote};
+			Lucene.Net.Search.Searchable[] searchables = new Lucene.Net.Search.Searchable[]{GetRemote()};
 			Searcher searcher = new MultiSearcher(searchables);
 			Hits result = searcher.Search(query);
 			
@@ -80,22 +79,22 @@
 			Assert.AreEqual("test text", result.Doc(0).Get("test"));
 		}
 		
-        [Test]
-		public virtual void  TestTermQuery()
+		[Test]
+        public virtual void  TestTermQuery()
 		{
 			Search(new TermQuery(new Term("test", "test")));
 		}
 		
-        [Test]
-		public virtual void  TestBooleanQuery()
+		[Test]
+        public virtual void  TestBooleanQuery()
 		{
 			BooleanQuery query = new BooleanQuery();
-			query.Add(new TermQuery(new Term("test", "test")), true, false);
+			query.Add(new TermQuery(new Term("test", "test")), BooleanClause.Occur.MUST);
 			Search(query);
 		}
 		
-        [Test]
-		public virtual void  TestPhraseQuery()
+		[Test]
+        public virtual void  TestPhraseQuery()
 		{
 			PhraseQuery query = new PhraseQuery();
 			query.Add(new Term("test", "test"));
@@ -104,13 +103,14 @@
 		}
 		
 		// Tests bug fix at http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20290
-        [Test]
-		public virtual void  TestQueryFilter()
+		[Test]
+        public virtual void  TestQueryFilter()
 		{
 			// try to search the published index
-			Lucene.Net.Search.Searchable[] searchables = new Lucene.Net.Search.Searchable[]{Remote};
+			Lucene.Net.Search.Searchable[] searchables = new Lucene.Net.Search.Searchable[]{GetRemote()};
 			Searcher searcher = new MultiSearcher(searchables);
 			Hits hits = searcher.Search(new TermQuery(new Term("test", "text")), new QueryFilter(new TermQuery(new Term("test", "test"))));
+			Assert.AreEqual(1, hits.Length());
 			Hits nohits = searcher.Search(new TermQuery(new Term("test", "text")), new QueryFilter(new TermQuery(new Term("test", "non-existent-term"))));
 			Assert.AreEqual(0, nohits.Length());
 		}

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestSetNorm.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestSetNorm.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestSetNorm.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestSetNorm.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
@@ -22,6 +23,7 @@
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
 namespace Lucene.Net.Search
 {
 	
@@ -30,7 +32,7 @@
 	/// </summary>
 	/// <author>  Doug Cutting
 	/// </author>
-	/// <version>  $Revision: 1.2 $
+	/// <version>  $Revision: 150497 $
 	/// </version>
 	[TestFixture]
     public class TestSetNorm
@@ -46,7 +48,8 @@
 				this.scores = scores;
 				this.enclosingInstance = enclosingInstance;
 			}
-			private float[] scores;
+
+            private float[] scores;
 			private TestSetNorm enclosingInstance;
 			public TestSetNorm Enclosing_Instance
 			{
@@ -61,16 +64,16 @@
 				scores[doc] = score;
 			}
 		}
-		
-        [Test]
-		public virtual void  TestSetNorm_()
+
+		[Test]
+        public virtual void  TestSetNorm_Renamed_Method()
 		{
 			RAMDirectory store = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
 			
 			// add the same document four times
-			Field f1 = Field.Text("Field", "word");
-			Document d1 = new Document();
+			Field f1 = new Field("field", "word", Field.Store.YES, Field.Index.TOKENIZED);
+			Lucene.Net.Documents.Document d1 = new Lucene.Net.Documents.Document();
 			d1.Add(f1);
 			writer.AddDocument(d1);
 			writer.AddDocument(d1);
@@ -80,16 +83,16 @@
 			
 			// reset the boost of each instance of this document
 			IndexReader reader = IndexReader.Open(store);
-			reader.SetNorm(0, "Field", 1.0f);
-			reader.SetNorm(1, "Field", 2.0f);
-			reader.SetNorm(2, "Field", 4.0f);
-			reader.SetNorm(3, "Field", 16.0f);
+			reader.SetNorm(0, "field", 1.0f);
+			reader.SetNorm(1, "field", 2.0f);
+			reader.SetNorm(2, "field", 4.0f);
+			reader.SetNorm(3, "field", 16.0f);
 			reader.Close();
 			
 			// check that searches are ordered by this boost
 			float[] scores = new float[4];
 			
-			new IndexSearcher(store).Search(new TermQuery(new Term("Field", "word")), new AnonymousClassHitCollector(scores, this));
+			new IndexSearcher(store).Search(new TermQuery(new Term("field", "word")), new AnonymousClassHitCollector(scores, this));
 			
 			float lastScore = 0.0f;
 			

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestSimilarity.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestSimilarity.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestSimilarity.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestSimilarity.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
@@ -21,6 +22,7 @@
 using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
 namespace Lucene.Net.Search
 {
 	
@@ -29,7 +31,7 @@
 	/// </summary>
 	/// <author>  Doug Cutting
 	/// </author>
-	/// <version>  $Revision: 1.4 $
+	/// <version>  $Revision: 150497 $
 	/// </version>
 	[TestFixture]
     public class TestSimilarity
@@ -85,7 +87,7 @@
 			}
 		}
 
-        private class AnonymousClassHitCollector2:HitCollector
+        private class AnonymousClassHitCollector2 : HitCollector
 		{
 			public AnonymousClassHitCollector2(TestSimilarity enclosingInstance)
 			{
@@ -136,7 +138,9 @@
 				Assert.IsTrue(score == 2.0f);
 			}
 		}
+
 		
+		[Serializable]
 		public class SimpleSimilarity : Similarity
 		{
 			public override float LengthNorm(System.String field, int numTerms)
@@ -159,7 +163,7 @@
 			{
 				return 1.0f;
 			}
-			public override float Idf(int docFreq, int numDocs)
+			public override float Ldf(int docFreq, int numDocs)
 			{
 				return 1.0f;
 			}
@@ -169,49 +173,47 @@
 			}
 		}
 		
-        [Test]
-		public virtual void  TestSimilarity_()
+		[Test]
+        public virtual void  TestSimilarity_Renamed_Method()
 		{
 			RAMDirectory store = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
 			writer.SetSimilarity(new SimpleSimilarity());
 			
-			Document d1 = new Document();
-			d1.Add(Field.Text("Field", "a c"));
+			Lucene.Net.Documents.Document d1 = new Lucene.Net.Documents.Document();
+			d1.Add(new Field("field", "a c", Field.Store.YES, Field.Index.TOKENIZED));
 			
-			Document d2 = new Document();
-			d2.Add(Field.Text("Field", "a b c"));
+			Lucene.Net.Documents.Document d2 = new Lucene.Net.Documents.Document();
+			d2.Add(new Field("field", "a b c", Field.Store.YES, Field.Index.TOKENIZED));
 			
 			writer.AddDocument(d1);
 			writer.AddDocument(d2);
 			writer.Optimize();
 			writer.Close();
 			
-			float[] scores = new float[4];
-			
 			Searcher searcher = new IndexSearcher(store);
 			searcher.SetSimilarity(new SimpleSimilarity());
 			
-			Term a = new Term("Field", "a");
-			Term b = new Term("Field", "b");
-			Term c = new Term("Field", "c");
+			Term a = new Term("field", "a");
+			Term b = new Term("field", "b");
+			Term c = new Term("field", "c");
 			
 			searcher.Search(new TermQuery(b), new AnonymousClassHitCollector(this));
 			
 			BooleanQuery bq = new BooleanQuery();
-			bq.Add(new TermQuery(a), false, false);
-			bq.Add(new TermQuery(b), false, false);
-			//System.out.println(bq.toString("Field"));
+			bq.Add(new TermQuery(a), BooleanClause.Occur.SHOULD);
+			bq.Add(new TermQuery(b), BooleanClause.Occur.SHOULD);
+			//System.out.println(bq.toString("field"));
 			searcher.Search(bq, new AnonymousClassHitCollector1(this));
 			
 			PhraseQuery pq = new PhraseQuery();
 			pq.Add(a);
 			pq.Add(c);
-			//System.out.println(pq.toString("Field"));
+			//System.out.println(pq.toString("field"));
 			searcher.Search(pq, new AnonymousClassHitCollector2(this));
 			
 			pq.SetSlop(2);
-			//System.out.println(pq.toString("Field"));
+			//System.out.println(pq.toString("field"));
 			searcher.Search(pq, new AnonymousClassHitCollector3(this));
 		}
 	}

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestSort.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestSort.cs Sat Jun  3 19:41:13 2006
@@ -13,13 +13,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
 using Lucene.Net.Index;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Pattern = System.Text.RegularExpressions.Regex;
 using NUnit.Framework;
+
 namespace Lucene.Net.Search
 {
 	
@@ -32,59 +35,44 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: TestSort.java,v 1.7 2004/05/24 22:51:42 tjones Exp $
+	/// <version>  $Id: TestSort.java 332651 2005-11-11 21:19:02Z yonik $
 	/// </version>
 	
-	[Serializable] [TestFixture]
-	public class TestSort
+	[Serializable]
+	[TestFixture]
+    public class TestSort
 	{
-		private Searcher FullIndex
+		[Serializable]
+		private class AnonymousClassFilter : Filter
 		{
-			get
+			public AnonymousClassFilter(Lucene.Net.Search.TopDocs docs1, TestSort enclosingInstance)
 			{
-				return GetIndex(true, true);
+				InitBlock(docs1, enclosingInstance);
 			}
-			
-		}
-		private Searcher XIndex
-		{
-			get
-			{
-				return GetIndex(true, false);
-			}
-			
-		}
-		private Searcher YIndex
-		{
-			get
-			{
-				return GetIndex(false, true);
-			}
-			
-		}
-		private Searcher EmptyIndex
-		{
-			get
+			private void  InitBlock(Lucene.Net.Search.TopDocs docs1, TestSort enclosingInstance)
 			{
-				return GetIndex(false, false);
+				this.docs1 = docs1;
+				this.enclosingInstance = enclosingInstance;
 			}
-			
-		}
-		private Lucene.Net.Search.Searchable Remote
-		{
-			get
+
+            private Lucene.Net.Search.TopDocs docs1;
+			private TestSort enclosingInstance;
+
+            public TestSort Enclosing_Instance
 			{
-				try
-				{
-					return LookupRemote();
-				}
-				catch (System.Exception e)
+				get
 				{
-					StartServer();
-					return LookupRemote();
+					return enclosingInstance;
 				}
+				
+			}
+
+            public override System.Collections.BitArray Bits(IndexReader reader)
+			{
+				System.Collections.BitArray bs = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
+				bs.Set(docs1.scoreDocs[0].doc, true);
+				return bs;
 			}
-			
 		}
 		
 		private Searcher full;
@@ -93,17 +81,52 @@
 		private Query queryX;
 		private Query queryY;
 		private Query queryA;
+		private Query queryE;
 		private Query queryF;
+		private Query queryG;
 		private Sort sort;
 		
 		
+		[STAThread]
+		public static void  Main(System.String[] argv)
+		{
+			System.Runtime.Remoting.RemotingConfiguration.Configure("Lucene.Net.Search.TestSort.config");
+			System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Http.HttpChannel(8080));
+            if (argv == null || argv.Length < 1)
+            {
+                // NUnit.Core.TestRunner.Run(Suite());    // {{Aroush}} where is "Run" in NUnit?
+            }
+            else if ("server".Equals(argv[0]))
+            {
+                TestSort test = new TestSort();
+                try
+                {
+                    test.StartServer();
+                    System.Threading.Thread.Sleep(new System.TimeSpan((System.Int64) 10000 * 500000));
+                }
+                catch (System.Exception e)
+                {
+                    System.Console.Out.WriteLine(e);
+                    System.Console.Error.WriteLine(e.StackTrace);
+                }
+            }
+
+            System.Console.ReadLine();
+		}
+		
+		public static NUnit.Framework.TestCase Suite()
+		{
+			return null; // return new NUnit.Core.TestSuite(typeof(TestSort)); {{Aroush}} how do you do this in NUnit?
+		}
+		
+		
 		// document data:
-		// the tracer Field is used to determine which document was hit
-		// the contents Field is used to search and sort by relevance
-		// the int Field to sort by int
-		// the float Field to sort by float
-		// the string Field to sort by string
-		private System.String[][] data = new System.String[][]{new System.String[]{"A", "x a", "5", "4f", "c", "A-3"}, new System.String[]{"B", "y a", "5", "3.4028235E38", "i", "B-10"}, new System.String[]{"C", "x a b c", "2147483647", "1.0", "j", "A-2"}, new System.String[]{"D", "y a b c", "-1", "0.0f", "a", "C-0"}, new System.String[]{"E", "x a b c d", "5", "2f", "h", "B-8"}, new System.String[]{"F", "y a b c d", "2", "3.14159f", "g", "B-1"}, new System.String[]{"G", "x a b c d", "3", "-1.0", "f", "C-100"}, new System.String[]{"H", "y a b c d", "0", "1.4E-45", "e", "C-88"}, new System.String[]{"I", "x a b c d e f", "-2147483648", "1.0e+0", "d", "A-10"}, new System.String[]{"J", "y a b c d e f", "4", ".5", "b", "C-7"}, new System.String[]{"Z", "f", null, null, null, null}};
+		// the tracer field is used to determine which document was hit
+		// the contents field is used to search and sort by relevance
+		// the int field to sort by int
+		// the float field to sort by float
+		// the string field to sort by string
+		private System.String[][] data = new System.String[][]{new System.String[]{"A", "x a", "5", "4f", "c", "A-3"}, new System.String[]{"B", "y a", "5", "3.4028235E38", "i", "B-10"}, new System.String[]{"C", "x a b c", "2147483647", "1.0", "j", "A-2"}, new System.String[]{"D", "y a b c", "-1", "0.0f", "a", "C-0"}, new System.String[]{"E", "x a b c d", "5", "2f", "h", "B-8"}, new System.String[]{"F", "y a b c d", "2", "3.14159f", "g", "B-1"}, new System.String[]{"G", "x a b c d", "3", "-1.0", "f", "C-100"}, new System.String[]{"H", "y a b c d", "0", "1.4E-45", "e", "C-88"}, new System.String[]{"I", "x a b c d e f", "-2147483648", "1.0e+0", "d", "A-10"}, new System.String[]{"J", "y a b c d e f", "4", ".5", "b", "C-7"}, new System.String[]{"W", "g", "1", null, null, null}, new System.String[]{"X", "g", "1", "0.1", null, null}, new System.String[]{"Y", "g", "1", "0.2", null, null}, new System.String[]{"Z", "f g", null, null, null, null}};
 		
 		// create an index of all the documents, or just the x, or just the y documents
 		private Searcher GetIndex(bool even, bool odd)
@@ -114,17 +137,18 @@
 			{
 				if (((i % 2) == 0 && even) || ((i % 2) == 1 && odd))
 				{
-					Document doc = new Document(); // store, index, token
-					doc.Add(new Field("tracer", data[i][0], true, false, false));
-					doc.Add(new Field("contents", data[i][1], false, true, true));
+					Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+					doc.Add(new Field("tracer", data[i][0], Field.Store.YES, Field.Index.NO));
+					doc.Add(new Field("contents", data[i][1], Field.Store.NO, Field.Index.TOKENIZED));
 					if (data[i][2] != null)
-						doc.Add(new Field("int", data[i][2], false, true, false));
+						doc.Add(new Field("int", data[i][2], Field.Store.NO, Field.Index.UN_TOKENIZED));
 					if (data[i][3] != null)
-						doc.Add(new Field("float", data[i][3], false, true, false));
+						doc.Add(new Field("float", data[i][3], Field.Store.NO, Field.Index.UN_TOKENIZED));
 					if (data[i][4] != null)
-						doc.Add(new Field("string", data[i][4], false, true, false));
+						doc.Add(new Field("string", data[i][4], Field.Store.NO, Field.Index.UN_TOKENIZED));
 					if (data[i][5] != null)
-						doc.Add(new Field("custom", data[i][5], false, true, false));
+						doc.Add(new Field("custom", data[i][5], Field.Store.NO, Field.Index.UN_TOKENIZED));
+					doc.SetBoost(2); // produce some scores above 1.0
 					writer.AddDocument(doc);
 				}
 			}
@@ -133,22 +157,44 @@
 			return new IndexSearcher(indexStore);
 		}
 		
-        [TestFixtureSetUp]
-		public virtual void  SetUp()
+		private Searcher GetFullIndex()
+		{
+			return GetIndex(true, true);
+		}
+		
+		private Searcher GetXIndex()
+		{
+			return GetIndex(true, false);
+		}
+		
+		private Searcher GetYIndex()
+		{
+			return GetIndex(false, true);
+		}
+		
+		private Searcher GetEmptyIndex()
+		{
+			return GetIndex(false, false);
+		}
+		
+		[TestFixtureSetUp]
+        public virtual void  SetUp()
 		{
-			full = FullIndex;
-			searchX = XIndex;
-			searchY = YIndex;
+			full = GetFullIndex();
+			searchX = GetXIndex();
+			searchY = GetYIndex();
 			queryX = new TermQuery(new Term("contents", "x"));
 			queryY = new TermQuery(new Term("contents", "y"));
 			queryA = new TermQuery(new Term("contents", "a"));
+			queryE = new TermQuery(new Term("contents", "e"));
 			queryF = new TermQuery(new Term("contents", "f"));
+			queryG = new TermQuery(new Term("contents", "g"));
 			sort = new Sort();
 		}
 		
 		// test the sorts by score and document number
-        [Test]
-		public virtual void  TestBuiltInSorts()
+		[Test]
+        public virtual void  TestBuiltInSorts()
 		{
 			sort = new Sort();
 			AssertMatches(full, queryX, sort, "ACEGI");
@@ -159,9 +205,9 @@
 			AssertMatches(full, queryY, sort, "BDFHJ");
 		}
 		
-		// test sorts where the type of Field is specified
-        [Test]
-		public virtual void  TestTypedSort()
+		// test sorts where the type of field is specified
+		[Test]
+        public virtual void  TestTypedSort()
 		{
 			sort.SetSort(new SortField[]{new SortField("int", SortField.INT), SortField.FIELD_DOC});
 			AssertMatches(full, queryX, sort, "IGAEC");
@@ -177,10 +223,10 @@
 		}
 		
 		// test sorts when there's nothing in the index
-        [Test]
-		public virtual void  TestEmptyIndex()
+		[Test]
+        public virtual void  TestEmptyIndex()
 		{
-			Searcher empty = EmptyIndex;
+			Searcher empty = GetEmptyIndex();
 			
 			sort = new Sort();
 			AssertMatches(empty, queryX, sort, "");
@@ -198,9 +244,9 @@
 			AssertMatches(empty, queryX, sort, "");
 		}
 		
-		// test sorts where the type of Field is determined dynamically
-        [Test]
-		public virtual void  TestAutoSort()
+		// test sorts where the type of field is determined dynamically
+		[Test]
+        public virtual void  TestAutoSort()
 		{
 			sort.SetSort("int");
 			AssertMatches(full, queryX, sort, "IGAEC");
@@ -216,8 +262,8 @@
 		}
 		
 		// test sorts in reverse
-        [Test]
-		public virtual void  TestReverseSort()
+		[Test]
+        public virtual void  TestReverseSort()
 		{
 			sort.SetSort(new SortField[]{new SortField(null, SortField.SCORE, true), SortField.FIELD_DOC});
 			AssertMatches(full, queryX, sort, "IEGCA");
@@ -240,9 +286,9 @@
 			AssertMatches(full, queryY, sort, "BFHJD");
 		}
 		
-		// test sorting when the sort Field is empty (undefined) for some of the documents
-        [Test]
-		public virtual void  TestEmptyFieldSort()
+		// test sorting when the sort field is empty (undefined) for some of the documents
+		[Test]
+        public virtual void  TestEmptyFieldSort()
 		{
 			sort.SetSort("string");
 			AssertMatches(full, queryF, sort, "ZJI");
@@ -259,13 +305,46 @@
 			sort.SetSort("float");
 			AssertMatches(full, queryF, sort, "ZJI");
 			
+			// using a nonexisting field as first sort key shouldn't make a difference:
+			sort.SetSort(new SortField[]{new SortField("nosuchfield", SortField.STRING), new SortField("float")});
+			AssertMatches(full, queryF, sort, "ZJI");
+			
 			sort.SetSort("float", true);
 			AssertMatches(full, queryF, sort, "IJZ");
+			
+			// When a field is null for both documents, the next SortField should be used.
+			// Works for
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float")});
+			AssertMatches(full, queryG, sort, "ZWXY");
+			
+			// Reverse the last criterium to make sure the test didn't pass by chance
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float", true)});
+			AssertMatches(full, queryG, sort, "ZYXW");
+			
+			// Do the same for a MultiSearcher
+			Searcher multiSearcher = new MultiSearcher(new Lucene.Net.Search.Searchable[]{full});
+			
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float")});
+			AssertMatches(multiSearcher, queryG, sort, "ZWXY");
+			
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float", true)});
+			AssertMatches(multiSearcher, queryG, sort, "ZYXW");
+			// Don't close the multiSearcher. it would close the full searcher too!
+			
+			// Do the same for a ParallelMultiSearcher
+			Searcher parallelSearcher = new ParallelMultiSearcher(new Lucene.Net.Search.Searchable[]{full});
+			
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float")});
+			AssertMatches(parallelSearcher, queryG, sort, "ZWXY");
+			
+			sort.SetSort(new SortField[]{new SortField("int"), new SortField("string", SortField.STRING), new SortField("float", true)});
+			AssertMatches(parallelSearcher, queryG, sort, "ZYXW");
+			// Don't close the parallelSearcher. it would close the full searcher too!
 		}
 		
 		// test sorts using a series of fields
-        [Test]
-		public virtual void  TestSortCombos()
+		[Test]
+        public virtual void  TestSortCombos()
 		{
 			sort.SetSort(new System.String[]{"int", "float"});
 			AssertMatches(full, queryX, sort, "IGEAC");
@@ -278,8 +357,8 @@
 		}
 		
 		// test using a Locale for sorting strings
-        [Test]
-		public virtual void  TestLocaleSort()
+		[Test]
+        public virtual void  TestLocaleSort()
 		{
 			sort.SetSort(new SortField[]{new SortField("string", new System.Globalization.CultureInfo("en-US"))});
 			AssertMatches(full, queryX, sort, "AIGEC");
@@ -291,14 +370,14 @@
 		}
 		
 		// test a custom sort function
-        [Test]
-		public virtual void  TestCustomSorts()
+		[Test]
+        public virtual void  TestCustomSorts()
 		{
-			sort.SetSort(new SortField("custom", SampleComparable.ComparatorSource));
+			sort.SetSort(new SortField("custom", SampleComparable.GetComparatorSource()));
 			AssertMatches(full, queryX, sort, "CAIEG");
-			sort.SetSort(new SortField("custom", SampleComparable.ComparatorSource, true));
+			sort.SetSort(new SortField("custom", SampleComparable.GetComparatorSource(), true));
 			AssertMatches(full, queryY, sort, "HJDBF");
-			SortComparator custom = SampleComparable.Comparator;
+			SortComparator custom = SampleComparable.GetComparator();
 			sort.SetSort(new SortField("custom", custom));
 			AssertMatches(full, queryX, sort, "CAIEG");
 			sort.SetSort(new SortField("custom", custom, true));
@@ -306,41 +385,41 @@
 		}
 		
 		// test a variety of sorts using more than one searcher
-        [Test]
-		public virtual void  TestMultiSort()
+		[Test]
+        public virtual void  TestMultiSort()
 		{
 			MultiSearcher searcher = new MultiSearcher(new Lucene.Net.Search.Searchable[]{searchX, searchY});
 			RunMultiSorts(searcher);
 		}
 		
 		// test a variety of sorts using a parallel multisearcher
-        [Test]
-		public virtual void  TestParallelMultiSort()
+		[Test]
+        public virtual void  TestParallelMultiSort()
 		{
 			Searcher searcher = new ParallelMultiSearcher(new Lucene.Net.Search.Searchable[]{searchX, searchY});
 			RunMultiSorts(searcher);
 		}
 		
 		// test a variety of sorts using a remote searcher
-        [Test]
-		public virtual void  TestRemoteSort()
+		[Test]
+        public virtual void  TestRemoteSort()
 		{
-			Lucene.Net.Search.Searchable searcher = Remote;
+			Lucene.Net.Search.Searchable searcher = GetRemote();
 			MultiSearcher multi = new MultiSearcher(new Lucene.Net.Search.Searchable[]{searcher});
 			RunMultiSorts(multi);
 		}
 		
 		// test custom search when remote
-        [Test]
-		public virtual void  TestRemoteCustomSort()
+		[Test]
+        public virtual void  TestRemoteCustomSort()
 		{
-			Lucene.Net.Search.Searchable searcher = Remote;
+			Lucene.Net.Search.Searchable searcher = GetRemote();
 			MultiSearcher multi = new MultiSearcher(new Lucene.Net.Search.Searchable[]{searcher});
-			sort.SetSort(new SortField("custom", SampleComparable.ComparatorSource));
+			sort.SetSort(new SortField("custom", SampleComparable.GetComparatorSource()));
 			AssertMatches(multi, queryX, sort, "CAIEG");
-			sort.SetSort(new SortField("custom", SampleComparable.ComparatorSource, true));
+			sort.SetSort(new SortField("custom", SampleComparable.GetComparatorSource(), true));
 			AssertMatches(multi, queryY, sort, "HJDBF");
-			SortComparator custom = SampleComparable.Comparator;
+			SortComparator custom = SampleComparable.GetComparator();
 			sort.SetSort(new SortField("custom", custom));
 			AssertMatches(multi, queryX, sort, "CAIEG");
 			sort.SetSort(new SortField("custom", custom, true));
@@ -349,8 +428,8 @@
 		
 		// test that the relevancy scores are the same even if
 		// hits are sorted
-        [Test]
-		public virtual void  TestNormalizedScores()
+		[Test]
+        public virtual void  TestNormalizedScores()
 		{
 			
 			// capture relevancy scores
@@ -359,12 +438,8 @@
 			System.Collections.Hashtable scoresA = GetScores(full.Search(queryA));
 			
 			// we'll test searching locally, remote and multi
-			// note: the multi test depends on each separate index containing
-			// the same documents as our local index, so the computed normalization
-			// will be the same.  so we make a multi searcher over two equal document
-			// sets - not realistic, but necessary for testing.
-			MultiSearcher remote = new MultiSearcher(new Lucene.Net.Search.Searchable[]{Remote});
-			MultiSearcher multi = new MultiSearcher(new Lucene.Net.Search.Searchable[]{full, full});
+			MultiSearcher remote = new MultiSearcher(new Lucene.Net.Search.Searchable[]{GetRemote()});
+			MultiSearcher multi = new MultiSearcher(new Lucene.Net.Search.Searchable[]{searchX, searchY});
 			
 			// change sorting and make sure relevancy stays the same
 			
@@ -457,6 +532,28 @@
 			AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
 		}
 		
+        [Test]
+		public virtual void  TestTopDocsScores()
+		{
+			
+			// There was previously a bug in FieldSortedHitQueue.maxscore when only a single
+			// doc was added.  That is what the following tests for.
+			Sort sort = new Sort();
+			int nDocs = 10;
+			
+			// try to pick a query that will result in an unnormalized
+			// score greater than 1 to test for correct normalization
+			TopDocs docs1 = full.Search(queryE, null, nDocs, sort);
+			
+			// a filter that only allows through the first hit
+			Filter filt = new AnonymousClassFilter(docs1, this);
+			
+			TopDocs docs2 = full.Search(queryE, filt, nDocs, sort);
+			
+			Assert.AreEqual(docs1.scoreDocs[0].score, docs2.scoreDocs[0].score, 1e-6);
+		}
+		
+		
 		// runs a variety of sorts useful for multisearchers
 		private void  RunMultiSorts(Searcher multi)
 		{
@@ -526,7 +623,7 @@
 			int n = result.Length();
 			for (int i = 0; i < n; ++i)
 			{
-				Document doc = result.Doc(i);
+				Lucene.Net.Documents.Document doc = result.Doc(i);
 				System.String[] v = doc.GetValues("tracer");
 				for (int j = 0; j < v.Length; ++j)
 				{
@@ -544,7 +641,7 @@
 			int n = result.Length();
 			for (int i = 0; i < n; ++i)
 			{
-				Document doc = result.Doc(i);
+				Lucene.Net.Documents.Document doc = result.Doc(i);
 				System.String[] v = doc.GetValues("tracer");
 				for (int j = 0; j < v.Length; ++j)
 				{
@@ -552,8 +649,8 @@
 				}
 			}
 			// System.out.println ("matching \""+buff+"\" against pattern \""+pattern+"\"");
-            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern);
-            Assert.IsTrue(regex.IsMatch(buff.ToString()));
+            Pattern p = new System.Text.RegularExpressions.Regex(pattern);
+			Assert.IsTrue(p.Match(buff.ToString()).Success);
 		}
 		
 		private System.Collections.Hashtable GetScores(Hits hits)
@@ -562,7 +659,7 @@
 			int n = hits.Length();
 			for (int i = 0; i < n; ++i)
 			{
-				Document doc = hits.Doc(i);
+				Lucene.Net.Documents.Document doc = hits.Doc(i);
 				System.String[] v = doc.GetValues("tracer");
 				Assert.AreEqual(v.Length, 1);
 				scoreMap[v[0]] = (float) hits.Score(i);
@@ -576,11 +673,33 @@
 			int n = m1.Count;
 			int m = m2.Count;
 			Assert.AreEqual(n, m);
-			System.Collections.IEnumerator iter = new System.Collections.Hashtable(m1).GetEnumerator();
+			System.Collections.IEnumerator iter = new System.Collections.Hashtable().GetEnumerator();
 			while (iter.MoveNext())
 			{
 				System.Object key = iter.Current;
-				Assert.AreEqual(m1[key], m2[key]);
+				System.Object o1 = m1[key];
+				System.Object o2 = m2[key];
+				if (o1 is System.Single)
+				{
+					Assert.AreEqual((float) ((System.Single) o1), (float) ((System.Single) o2), 1e-6);
+				}
+				else
+				{
+					Assert.AreEqual(m1[key], m2[key]);
+				}
+			}
+		}
+		
+		private Lucene.Net.Search.Searchable GetRemote()
+		{
+			try
+			{
+				return LookupRemote();
+			}
+			catch (System.Exception e)
+			{
+				StartServer();
+				return LookupRemote();
 			}
 		}
 		
@@ -592,13 +711,14 @@
 		private void  StartServer()
 		{
 			// construct an index
-			Searcher local = FullIndex;
+			Searcher local = GetFullIndex();
 			// local.search (queryA, new Sort());
 			
 			// publish it
-			System.Runtime.Remoting.RemotingConfiguration reg = null; //// java.rmi.registry.LocateRegistry.CreateRegistry(1099); // {{Aroush}}
-			RemoteSearchable impl = new RemoteSearchable(local);
-			System.Runtime.Remoting.RemotingServices.Marshal(impl, ("http://localhost/SortedSearchable"));
+			//System.Runtime.Remoting.RemotingConfiguration reg = LocateRegistry.createRegistry(1099);
+			//RemoteSearchable impl = new RemoteSearchable(local);
+			//System.Runtime.Remoting.RemotingServices.Marshal(impl, SupportClass.ParseURIBind("//localhost/SortedSearchable"));
+            Assert.Fail("Need to port Java to C#");     // {{Aroush-1.9}} We need to do this in C#
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestTermVectors.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestTermVectors.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestTermVectors.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestTermVectors.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using NUnit.Framework;
 using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
@@ -22,6 +23,7 @@
 using Directory = Lucene.Net.Store.Directory;
 using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using English = Lucene.Net.Util.English;
+
 namespace Lucene.Net.Search
 {
 	[TestFixture]
@@ -29,40 +31,59 @@
 	{
 		private IndexSearcher searcher;
 		private RAMDirectory directory = new RAMDirectory();
+
 		
-        [TestFixtureSetUp]
-		public virtual void  SetUp()
+		[TestFixtureSetUp]
+        public virtual void  SetUp()
 		{
 			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
 			//writer.setUseCompoundFile(true);
 			//writer.infoStream = System.out;
-			System.Text.StringBuilder buffer = new System.Text.StringBuilder();
 			for (int i = 0; i < 1000; i++)
 			{
-				Document doc = new Document();
-				doc.Add(Field.Text("Field", English.IntToEnglish(i), true));
+				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+				Field.TermVector termVector;
+				int mod3 = i % 3;
+				int mod2 = i % 2;
+				if (mod2 == 0 && mod3 == 0)
+				{
+					termVector = Field.TermVector.WITH_POSITIONS_OFFSETS;
+				}
+				else if (mod2 == 0)
+				{
+					termVector = Field.TermVector.WITH_POSITIONS;
+				}
+				else if (mod3 == 0)
+				{
+					termVector = Field.TermVector.WITH_OFFSETS;
+				}
+				else
+				{
+					termVector = Field.TermVector.YES;
+				}
+				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED, termVector));
 				writer.AddDocument(doc);
 			}
 			writer.Close();
 			searcher = new IndexSearcher(directory);
 		}
 		
-        [TestFixtureTearDown]
-		protected virtual void  TearDown()
+		[TestFixtureTearDown]
+        public virtual void  TearDown()
 		{
 			
 		}
 		
-        [Test]
-		public virtual void  Test()
+		[Test]
+        public virtual void  Test()
 		{
 			Assert.IsTrue(searcher != null);
 		}
 		
-        [Test]
-		public virtual void  TestTermVectors_()
+		[Test]
+        public virtual void  TestTermVectors_Renamed_Method()
 		{
-			Query query = new TermQuery(new Term("Field", "seventy"));
+			Query query = new TermQuery(new Term("field", "seventy"));
 			try
 			{
 				Hits hits = searcher.Search(query);
@@ -70,14 +91,10 @@
 				
 				for (int i = 0; i < hits.Length(); i++)
 				{
-					TermFreqVector[] vector = searcher.reader.GetTermFreqVectors(hits.Id(i));
+					TermFreqVector[] vector = searcher.Reader.GetTermFreqVectors(hits.Id(i));
 					Assert.IsTrue(vector != null);
 					Assert.IsTrue(vector.Length == 1);
-					//Assert.IsTrue();
 				}
-				TermFreqVector[] vector2 = searcher.reader.GetTermFreqVectors(hits.Id(50));
-				//System.out.println("Explain: " + searcher.explain(query, hits.id(50)));
-				//System.out.println("Vector: " + vector[0].toString());
 			}
 			catch (System.IO.IOException e)
 			{
@@ -85,10 +102,81 @@
 			}
 		}
 		
-        [Test]
-		public virtual void  TestTermPositionVectors()
+		[Test]
+        public virtual void  TestTermPositionVectors()
+		{
+			Query query = new TermQuery(new Term("field", "zero"));
+			try
+			{
+				Hits hits = searcher.Search(query);
+				Assert.AreEqual(1, hits.Length());
+				
+				for (int i = 0; i < hits.Length(); i++)
+				{
+					TermFreqVector[] vector = searcher.Reader.GetTermFreqVectors(hits.Id(i));
+					Assert.IsTrue(vector != null);
+					Assert.IsTrue(vector.Length == 1);
+					
+					bool shouldBePosVector = (hits.Id(i) % 2 == 0)?true:false;
+					Assert.IsTrue((shouldBePosVector == false) || (shouldBePosVector == true && (vector[0] is TermPositionVector == true)));
+					
+					bool shouldBeOffVector = (hits.Id(i) % 3 == 0)?true:false;
+					Assert.IsTrue((shouldBeOffVector == false) || (shouldBeOffVector == true && (vector[0] is TermPositionVector == true)));
+					
+					if (shouldBePosVector || shouldBeOffVector)
+					{
+						TermPositionVector posVec = (TermPositionVector) vector[0];
+						System.String[] terms = posVec.GetTerms();
+						Assert.IsTrue(terms != null && terms.Length > 0);
+						
+						for (int j = 0; j < terms.Length; j++)
+						{
+							int[] positions = posVec.GetTermPositions(j);
+							TermVectorOffsetInfo[] offsets = posVec.GetOffsets(j);
+							
+							if (shouldBePosVector)
+							{
+								Assert.IsTrue(positions != null);
+								Assert.IsTrue(positions.Length > 0);
+							}
+							else
+								Assert.IsTrue(positions == null);
+							
+							if (shouldBeOffVector)
+							{
+								Assert.IsTrue(offsets != null);
+								Assert.IsTrue(offsets.Length > 0);
+							}
+							else
+								Assert.IsTrue(offsets == null);
+						}
+					}
+					else
+					{
+						try
+						{
+							TermPositionVector posVec = (TermPositionVector) vector[0];
+							Assert.IsTrue(false);
+						}
+						catch (System.InvalidCastException ignore)
+						{
+							TermFreqVector freqVec = vector[0];
+							System.String[] terms = freqVec.GetTerms();
+							Assert.IsTrue(terms != null && terms.Length > 0);
+						}
+					}
+				}
+			}
+			catch (System.IO.IOException e)
+			{
+				Assert.IsTrue(false);
+			}
+		}
+		
+		[Test]
+        public virtual void  TestTermOffsetVectors()
 		{
-			Query query = new TermQuery(new Term("Field", "fifty"));
+			Query query = new TermQuery(new Term("field", "fifty"));
 			try
 			{
 				Hits hits = searcher.Search(query);
@@ -96,9 +184,10 @@
 				
 				for (int i = 0; i < hits.Length(); i++)
 				{
-					TermFreqVector[] vector = searcher.reader.GetTermFreqVectors(hits.Id(i));
+					TermFreqVector[] vector = searcher.Reader.GetTermFreqVectors(hits.Id(i));
 					Assert.IsTrue(vector != null);
 					Assert.IsTrue(vector.Length == 1);
+					
 					//Assert.IsTrue();
 				}
 			}
@@ -108,10 +197,9 @@
 			}
 		}
 		
-        [Test]
-		public virtual void  TestKnownSetOfDocuments()
+		[Test]
+        public virtual void  TestKnownSetOfDocuments()
 		{
-			System.String[] termArray = new System.String[]{"eating", "chocolate", "in", "a", "computer", "lab", "grows", "old", "colored", "with", "an"};
 			System.String test1 = "eating chocolate in a computer lab"; //6 terms
 			System.String test2 = "computer in a computer lab"; //5 terms
 			System.String test3 = "a chocolate lab grows old"; //5 terms
@@ -129,13 +217,13 @@
 			test4Map["computer"] = 1;
 			test4Map["old"] = 1;
 			
-			Document testDoc1 = new Document();
+			Lucene.Net.Documents.Document testDoc1 = new Lucene.Net.Documents.Document();
 			SetupDoc(testDoc1, test1);
-			Document testDoc2 = new Document();
+			Lucene.Net.Documents.Document testDoc2 = new Lucene.Net.Documents.Document();
 			SetupDoc(testDoc2, test2);
-			Document testDoc3 = new Document();
+			Lucene.Net.Documents.Document testDoc3 = new Lucene.Net.Documents.Document();
 			SetupDoc(testDoc3, test3);
-			Document testDoc4 = new Document();
+			Lucene.Net.Documents.Document testDoc4 = new Lucene.Net.Documents.Document();
 			SetupDoc(testDoc4, test4);
 			
 			Directory dir = new RAMDirectory();
@@ -150,8 +238,8 @@
 				writer.AddDocument(testDoc4);
 				writer.Close();
 				IndexSearcher knownSearcher = new IndexSearcher(dir);
-				TermEnum termEnum = knownSearcher.reader.Terms();
-				TermDocs termDocs = knownSearcher.reader.TermDocs();
+				TermEnum termEnum = knownSearcher.Reader.Terms();
+				TermDocs termDocs = knownSearcher.Reader.TermDocs();
 				//System.out.println("Terms: " + termEnum.size() + " Orig Len: " + termArray.length);
 				
 				Similarity sim = knownSearcher.GetSimilarity();
@@ -165,12 +253,12 @@
 						int docId = termDocs.Doc();
 						int freq = termDocs.Freq();
 						//System.out.println("Doc Id: " + docId + " freq " + freq);
-						TermFreqVector vector = knownSearcher.reader.GetTermFreqVector(docId, "Field");
+						TermFreqVector vector = knownSearcher.Reader.GetTermFreqVector(docId, "field");
 						float tf = sim.Tf(freq);
 						float idf = sim.Idf(term, knownSearcher);
 						//float qNorm = sim.queryNorm()
 						//This is fine since we don't have stop words
-						float lNorm = sim.LengthNorm("Field", vector.GetTerms().Length);
+						float lNorm = sim.LengthNorm("field", vector.GetTerms().Length);
 						//float coord = sim.coord()
 						//System.out.println("TF: " + tf + " IDF: " + idf + " LenNorm: " + lNorm);
 						Assert.IsTrue(vector != null);
@@ -178,7 +266,7 @@
 						int[] freqs = vector.GetTermFrequencies();
 						for (int i = 0; i < vTerms.Length; i++)
 						{
-							if (term.Text().Equals(vTerms[i]) == true)
+							if (term.Text().Equals(vTerms[i]))
 							{
 								Assert.IsTrue(freqs[i] == freq);
 							}
@@ -186,7 +274,7 @@
 					}
 					//System.out.println("--------");
 				}
-				Query query = new TermQuery(new Term("Field", "chocolate"));
+				Query query = new TermQuery(new Term("field", "chocolate"));
 				Hits hits = knownSearcher.Search(query);
 				//doc 3 should be the first hit b/c it is the shortest match
 				Assert.IsTrue(hits.Length() == 3);
@@ -197,10 +285,10 @@
 				System.out.println("Explain: " + knownSearcher.explain(query, hits.id(1)));
 				System.out.println("Hit 2: " + hits.id(2) + " Score: " + hits.score(2) + " String: " +  hits.doc(2).toString());
 				System.out.println("Explain: " + knownSearcher.explain(query, hits.id(2)));*/
-				Assert.IsTrue(testDoc3.ToString().Equals(hits.Doc(0).ToString()));
-				Assert.IsTrue(testDoc4.ToString().Equals(hits.Doc(1).ToString()));
-				Assert.IsTrue(testDoc1.ToString().Equals(hits.Doc(2).ToString()));
-				TermFreqVector vector2 = knownSearcher.reader.GetTermFreqVector(hits.Id(1), "Field");
+				Assert.IsTrue(hits.Id(0) == 2);
+				Assert.IsTrue(hits.Id(1) == 3);
+				Assert.IsTrue(hits.Id(2) == 0);
+				TermFreqVector vector2 = knownSearcher.Reader.GetTermFreqVector(hits.Id(1), "field");
 				Assert.IsTrue(vector2 != null);
 				//System.out.println("Vector: " + vector);
 				System.String[] terms = vector2.GetTerms();
@@ -208,27 +296,26 @@
 				Assert.IsTrue(terms != null && terms.Length == 10);
 				for (int i = 0; i < terms.Length; i++)
 				{
-                    System.String term = terms[i];
-                    //System.out.println("Term: " + term);
-                    int freq = freqs2[i];
-                    Assert.IsTrue(test4.IndexOf(term) != - 1);
-                    System.Int32 freqInt = (System.Int32) test4Map[term];
-                    System.Object tmpFreqInt = test4Map[term];
-                    Assert.IsTrue(tmpFreqInt != null);
-                    Assert.IsTrue(freqInt == freq);
-                }
+					System.String term = terms[i];
+					//System.out.println("Term: " + term);
+					int freq = freqs2[i];
+					Assert.IsTrue(test4.IndexOf(term) != - 1);
+					System.Int32 freqInt = (System.Int32) test4Map[term];
+					Assert.IsTrue(false); // Assert.IsTrue(freqInt != null);   // {{Aroush}} how do we test for 'null'?
+					Assert.IsTrue(freqInt == freq);
+				}
 				knownSearcher.Close();
 			}
 			catch (System.IO.IOException e)
 			{
-				System.Console.Error.WriteLine(e.StackTrace);
+                System.Console.Error.WriteLine(e.StackTrace);
 				Assert.IsTrue(false);
 			}
 		}
 		
-		private void  SetupDoc(Document doc, System.String text)
+		private void  SetupDoc(Lucene.Net.Documents.Document doc, System.String text)
 		{
-			doc.Add(Field.Text("Field", text, true));
+			doc.Add(new Field("field", text, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
 			//System.out.println("Document: " + doc);
 		}
 	}



Mime
View raw message