lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r677059 [13/19] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Index/ Lucene.Net/Search/ Lucene.Net/Search/Function/...
Date Tue, 15 Jul 2008 21:44:10 GMT
Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestCustomScoreQuery.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestCustomScoreQuery.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,293 @@
+/*
+ * 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 NUnit.Framework;
+
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using QueryParser = Lucene.Net.QueryParsers.QueryParser;
+using Explanation = Lucene.Net.Search.Explanation;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Query = Lucene.Net.Search.Query;
+using QueryUtils = Lucene.Net.Search.QueryUtils;
+using TopDocs = Lucene.Net.Search.TopDocs;
+
+namespace Lucene.Net.Search.Function
+{
+	
+	/// <summary> Test CustomScoreQuery search.</summary>
+	[TestFixture]
+	public class TestCustomScoreQuery : FunctionTestSetup
+	{
+		
+		/* @override constructor */
+		//public TestCustomScoreQuery(System.String name):base(name)
+		//{
+		//}
+		
+		/* @override */
+		[TearDown]
+		public override void  TearDown()
+		{
+			base.TearDown();
+		}
+		
+		/* @override */
+		[SetUp]
+		public override void  SetUp()
+		{
+			// prepare a small index with just a few documents.  
+			base.SetUp();
+		}
+		
+		/// <summary>Test that CustomScoreQuery of Type.BYTE returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestCustomScoreByte()
+		{
+			// INT field values are small enough to be parsed as byte
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.BYTE, 1.0);
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.BYTE, 2.0);
+		}
+		
+		/// <summary>Test that CustomScoreQuery of Type.SHORT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestCustomScoreShort()
+		{
+			// INT field values are small enough to be parsed as short
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.SHORT, 1.0);
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.SHORT, 3.0);
+		}
+		
+		/// <summary>Test that CustomScoreQuery of Type.INT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestCustomScoreInt()
+		{
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.INT, 1.0);
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.INT, 4.0);
+		}
+		
+		/// <summary>Test that CustomScoreQuery of Type.FLOAT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestCustomScoreFloat()
+		{
+			// INT field can be parsed as float
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.FLOAT, 1.0);
+			DoTestCustomScore(INT_FIELD, FieldScoreQuery.Type.FLOAT, 5.0);
+			// same values, but in flot format
+			DoTestCustomScore(FLOAT_FIELD, FieldScoreQuery.Type.FLOAT, 1.0);
+			DoTestCustomScore(FLOAT_FIELD, FieldScoreQuery.Type.FLOAT, 6.0);
+		}
+		
+		// must have static class otherwise serialization tests fail
+		[Serializable]
+		private class CustomAddQuery : CustomScoreQuery
+		{
+			// constructor
+			internal CustomAddQuery(Query q, ValueSourceQuery qValSrc):base(q, qValSrc)
+			{
+			}
+			/*(non-Javadoc) @see Lucene.Net.Search.Function.CustomScoreQuery#name() */
+			public override System.String Name()
+			{
+				return "customAdd";
+			}
+			/*(non-Javadoc) @see Lucene.Net.Search.Function.CustomScoreQuery#customScore(int, float, float) */
+			public override float CustomScore(int doc, float subQueryScore, float valSrcScore)
+			{
+				return subQueryScore + valSrcScore;
+			}
+			/* (non-Javadoc)@see Lucene.Net.Search.Function.CustomScoreQuery#customExplain(int, Lucene.Net.Search.Explanation, Lucene.Net.Search.Explanation)*/
+			public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation valSrcExpl)
+			{
+				float valSrcScore = valSrcExpl == null?0:valSrcExpl.GetValue();
+				Explanation exp = new Explanation(valSrcScore + subQueryExpl.GetValue(), "custom score: sum of:");
+				exp.AddDetail(subQueryExpl);
+				if (valSrcExpl != null)
+				{
+					exp.AddDetail(valSrcExpl);
+				}
+				return exp;
+			}
+		}
+		
+		// must have static class otherwise serialization tests fail
+		[Serializable]
+		private class CustomMulAddQuery : CustomScoreQuery
+		{
+			// constructor
+			internal CustomMulAddQuery(Query q, ValueSourceQuery qValSrc1, ValueSourceQuery qValSrc2):base(q, new ValueSourceQuery[]{qValSrc1, qValSrc2})
+			{
+			}
+			/*(non-Javadoc) @see Lucene.Net.Search.Function.CustomScoreQuery#name() */
+			public override System.String Name()
+			{
+				return "customMulAdd";
+			}
+			/*(non-Javadoc) @see Lucene.Net.Search.Function.CustomScoreQuery#customScore(int, float, float) */
+			public override float CustomScore(int doc, float subQueryScore, float[] valSrcScores)
+			{
+				if (valSrcScores.Length == 0)
+				{
+					return subQueryScore;
+				}
+				if (valSrcScores.Length == 1)
+				{
+					return subQueryScore + valSrcScores[0];
+				}
+				return (subQueryScore + valSrcScores[0]) * valSrcScores[1]; // we know there are two
+			}
+			/* (non-Javadoc)@see Lucene.Net.Search.Function.CustomScoreQuery#customExplain(int, Lucene.Net.Search.Explanation, Lucene.Net.Search.Explanation)*/
+			public override Explanation CustomExplain(int doc, Explanation subQueryExpl, Explanation[] valSrcExpls)
+			{
+				if (valSrcExpls.Length == 0)
+				{
+					return subQueryExpl;
+				}
+				Explanation exp = new Explanation(valSrcExpls[0].GetValue() + subQueryExpl.GetValue(), "sum of:");
+				exp.AddDetail(subQueryExpl);
+				exp.AddDetail(valSrcExpls[0]);
+				if (valSrcExpls.Length == 1)
+				{
+					exp.SetDescription("CustomMulAdd, sum of:");
+					return exp;
+				}
+				Explanation exp2 = new Explanation(valSrcExpls[1].GetValue() * exp.GetValue(), "custom score: product of:");
+				exp2.AddDetail(valSrcExpls[1]);
+				exp2.AddDetail(exp);
+				return exp2;
+			}
+		}
+		
+		// Test that FieldScoreQuery returns docs with expected score.
+		private void  DoTestCustomScore(System.String field, FieldScoreQuery.Type tp, double dboost)
+		{
+			float boost = (float) dboost;
+			IndexSearcher s = new IndexSearcher(dir);
+			FieldScoreQuery qValSrc = new FieldScoreQuery(field, tp); // a query that would score by the field
+			Lucene.Net.QueryParsers.QueryParser qp = new Lucene.Net.QueryParsers.QueryParser(TEXT_FIELD, anlzr);
+			System.String qtxt = "first aid text"; // from the doc texts in FunctionQuerySetup.
+			
+			// regular (boolean) query.
+			Query q1 = qp.Parse(qtxt);
+			Log(q1);
+			
+			// custom query, that should score the same as q1.
+			CustomScoreQuery q2CustomNeutral = new CustomScoreQuery(q1);
+			q2CustomNeutral.SetBoost(boost);
+			Log(q2CustomNeutral);
+			
+			// custom query, that should (by default) multiply the scores of q1 by that of the field
+			CustomScoreQuery q3CustomMul = new CustomScoreQuery(q1, qValSrc);
+			q3CustomMul.SetStrict(true);
+			q3CustomMul.SetBoost(boost);
+			Log(q3CustomMul);
+			
+			// custom query, that should add the scores of q1 to that of the field
+			CustomScoreQuery q4CustomAdd = new CustomAddQuery(q1, qValSrc);
+			q4CustomAdd.SetStrict(true);
+			q4CustomAdd.SetBoost(boost);
+			Log(q4CustomAdd);
+			
+			// custom query, that multiplies and adds the field score to that of q1
+			CustomScoreQuery q5CustomMulAdd = new CustomMulAddQuery(q1, qValSrc, qValSrc);
+			q5CustomMulAdd.SetStrict(true);
+			q5CustomMulAdd.SetBoost(boost);
+			Log(q5CustomMulAdd);
+			
+			// do al the searches 
+			TopDocs td1 = s.Search(q1, null, 1000);
+			TopDocs td2CustomNeutral = s.Search(q2CustomNeutral, null, 1000);
+			TopDocs td3CustomMul = s.Search(q3CustomMul, null, 1000);
+			TopDocs td4CustomAdd = s.Search(q4CustomAdd, null, 1000);
+			TopDocs td5CustomMulAdd = s.Search(q5CustomMulAdd, null, 1000);
+			
+			// put results in map so we can verify the scores although they have changed
+			System.Collections.Hashtable h1 = TopDocsToMap(td1);
+			System.Collections.Hashtable h2CustomNeutral = TopDocsToMap(td2CustomNeutral);
+			System.Collections.Hashtable h3CustomMul = TopDocsToMap(td3CustomMul);
+			System.Collections.Hashtable h4CustomAdd = TopDocsToMap(td4CustomAdd);
+			System.Collections.Hashtable h5CustomMulAdd = TopDocsToMap(td5CustomMulAdd);
+			
+			VerifyResults(boost, s, h1, h2CustomNeutral, h3CustomMul, h4CustomAdd, h5CustomMulAdd, q1, q2CustomNeutral, q3CustomMul, q4CustomAdd, q5CustomMulAdd);
+		}
+		
+		// verify results are as expected.
+		private void  VerifyResults(float boost, IndexSearcher s, System.Collections.Hashtable h1, System.Collections.Hashtable h2customNeutral, System.Collections.Hashtable h3CustomMul, System.Collections.Hashtable h4CustomAdd, System.Collections.Hashtable h5CustomMulAdd, Query q1, Query q2, Query q3, Query q4, Query q5)
+		{
+			
+			// verify numbers of matches
+			Log("#hits = " + h1.Count);
+			Assert.AreEqual(h1.Count, h2customNeutral.Count, "queries should have same #hits");
+			Assert.AreEqual(h1.Count, h3CustomMul.Count, "queries should have same #hits");
+			Assert.AreEqual(h1.Count, h4CustomAdd.Count, "queries should have same #hits");
+			Assert.AreEqual(h1.Count, h5CustomMulAdd.Count, "queries should have same #hits");
+			
+			// verify scores ratios
+			for (System.Collections.IEnumerator it = h1.Keys.GetEnumerator(); it.MoveNext(); )
+			{
+				System.Int32 x = (System.Int32) it.Current;
+				
+				int doc = x;
+				Log("doc = " + doc);
+				
+				float fieldScore = ExpectedFieldScore(s.GetIndexReader().Document(doc).Get(ID_FIELD));
+				Log("fieldScore = " + fieldScore);
+				Assert.IsTrue(fieldScore > 0, "fieldScore should not be 0");
+				
+				float score1 = (float) ((System.Single) h1[x]);
+				LogResult("score1=", s, q1, doc, score1);
+				
+				float score2 = (float) ((System.Single) h2customNeutral[x]);
+				LogResult("score2=", s, q2, doc, score2);
+				Assert.AreEqual(boost * score1, score2, TEST_SCORE_TOLERANCE_DELTA, "same score (just boosted) for neutral");
+				
+				float score3 = (float) ((System.Single) h3CustomMul[x]);
+				LogResult("score3=", s, q3, doc, score3);
+				Assert.AreEqual(boost * fieldScore * score1, score3, TEST_SCORE_TOLERANCE_DELTA, "new score for custom mul");
+				
+				float score4 = (float) ((System.Single) h4CustomAdd[x]);
+				LogResult("score4=", s, q4, doc, score4);
+				Assert.AreEqual(boost * (fieldScore + score1), score4, TEST_SCORE_TOLERANCE_DELTA, "new score for custom add");
+				
+				float score5 = (float) ((System.Single) h5CustomMulAdd[x]);
+				LogResult("score5=", s, q5, doc, score5);
+				Assert.AreEqual(boost * fieldScore * (score1 + fieldScore), score5, TEST_SCORE_TOLERANCE_DELTA, "new score for custom mul add");
+			}
+		}
+		
+		private void  LogResult(System.String msg, IndexSearcher s, Query q, int doc, float score1)
+		{
+			QueryUtils.Check(q, s);
+			Log(msg + " " + score1);
+			Log("Explain by: " + q);
+			Log(s.Explain(q, doc));
+		}
+		
+		// since custom scoring modifies the order of docs, map results 
+		// by doc ids so that we can later compare/verify them 
+		private System.Collections.Hashtable TopDocsToMap(TopDocs td)
+		{
+			System.Collections.Hashtable h = new System.Collections.Hashtable();
+			for (int i = 0; i < td.totalHits; i++)
+			{
+				h[(System.Int32) td.scoreDocs[i].doc] = (float) td.scoreDocs[i].score;
+			}
+			return h;
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestFieldScoreQuery.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestFieldScoreQuery.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,272 @@
+/*
+ * 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 NUnit.Framework;
+
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using Hits = Lucene.Net.Search.Hits;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Query = Lucene.Net.Search.Query;
+using QueryUtils = Lucene.Net.Search.QueryUtils;
+using ScoreDoc = Lucene.Net.Search.ScoreDoc;
+using TopDocs = Lucene.Net.Search.TopDocs;
+
+namespace Lucene.Net.Search.Function
+{
+	
+	/// <summary> Test FieldScoreQuery search.
+	/// <p>
+	/// Tests here create an index with a few documents, each having
+	/// an int value indexed  field and a float value indexed field.
+	/// The values of these fields are later used for scoring.
+	/// <p>
+	/// The rank tests use Hits to verify that docs are ordered (by score) as expected.
+	/// <p>
+	/// The exact score tests use TopDocs top to verify the exact score.  
+	/// </summary>
+	[TestFixture]
+	public class TestFieldScoreQuery : FunctionTestSetup
+	{
+		
+		/* @override constructor */
+		//public TestFieldScoreQuery(System.String name):base(name)
+		//{
+		//}
+		
+		/* @override */
+		[TearDown]
+		public override void  TearDown()
+		{
+			base.TearDown();
+		}
+		
+		/* @override */
+		[SetUp]
+		public override void  SetUp()
+		{
+			// prepare a small index with just a few documents.  
+			base.SetUp();
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.BYTE returns docs in expected order. </summary>
+		[Test]
+		public virtual void  TestRankByte()
+		{
+			// INT field values are small enough to be parsed as byte
+			DoTestRank(INT_FIELD, FieldScoreQuery.Type.BYTE);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.SHORT returns docs in expected order. </summary>
+		[Test]
+		public virtual void  TestRankShort()
+		{
+			// INT field values are small enough to be parsed as short
+			DoTestRank(INT_FIELD, FieldScoreQuery.Type.SHORT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.INT returns docs in expected order. </summary>
+		[Test]
+		public virtual void  TestRankInt()
+		{
+			DoTestRank(INT_FIELD, FieldScoreQuery.Type.INT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.FLOAT returns docs in expected order. </summary>
+		[Test]
+		public virtual void  TestRankFloat()
+		{
+			// INT field can be parsed as float
+			DoTestRank(INT_FIELD, FieldScoreQuery.Type.FLOAT);
+			// same values, but in flot format
+			DoTestRank(FLOAT_FIELD, FieldScoreQuery.Type.FLOAT);
+		}
+		
+		// Test that FieldScoreQuery returns docs in expected order.
+		private void  DoTestRank(System.String field, FieldScoreQuery.Type tp)
+		{
+			IndexSearcher s = new IndexSearcher(dir);
+			Query q = new FieldScoreQuery(field, tp);
+			Log("test: " + q);
+			QueryUtils.Check(q, s);
+			Hits h = s.Search(q);
+			Assert.AreEqual(N_DOCS, h.Length(), "All docs should be matched!");
+			System.String prevID = "ID" + (N_DOCS + 1); // greater than all ids of docs in this test
+			for (int i = 0; i < h.Length(); i++)
+			{
+				System.String resID = h.Doc(i).Get(ID_FIELD);
+				Log(i + ".   score=" + h.Score(i) + "  -  " + resID);
+				Log(s.Explain(q, h.Id(i)));
+				Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
+				prevID = resID;
+			}
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.BYTE returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestExactScoreByte()
+		{
+			// INT field values are small enough to be parsed as byte
+			DoTestExactScore(INT_FIELD, FieldScoreQuery.Type.BYTE);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.SHORT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestExactScoreShort()
+		{
+			// INT field values are small enough to be parsed as short
+			DoTestExactScore(INT_FIELD, FieldScoreQuery.Type.SHORT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.INT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestExactScoreInt()
+		{
+			DoTestExactScore(INT_FIELD, FieldScoreQuery.Type.INT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.FLOAT returns the expected scores. </summary>
+		[Test]
+		public virtual void  TestExactScoreFloat()
+		{
+			// INT field can be parsed as float
+			DoTestExactScore(INT_FIELD, FieldScoreQuery.Type.FLOAT);
+			// same values, but in flot format
+			DoTestExactScore(FLOAT_FIELD, FieldScoreQuery.Type.FLOAT);
+		}
+		
+		// Test that FieldScoreQuery returns docs with expected score.
+		private void  DoTestExactScore(System.String field, FieldScoreQuery.Type tp)
+		{
+			IndexSearcher s = new IndexSearcher(dir);
+			Query q = new FieldScoreQuery(field, tp);
+			TopDocs td = s.Search(q, null, 1000);
+			Assert.AreEqual(N_DOCS, td.totalHits, "All docs should be matched!");
+			ScoreDoc[] sd = td.scoreDocs;
+			for (int i = 0; i < sd.Length; i++)
+			{
+				float score = sd[i].score;
+				Log(s.Explain(q, sd[i].doc));
+				System.String id = s.GetIndexReader().Document(sd[i].doc).Get(ID_FIELD);
+				float expectedScore = ExpectedFieldScore(id); // "ID7" --> 7.0
+				Assert.AreEqual(expectedScore, score, TEST_SCORE_TOLERANCE_DELTA, "score of " + id + " shuould be " + expectedScore + " != " + score);
+			}
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.BYTE caches/reuses loaded values and consumes the proper RAM resources. </summary>
+		[Test]
+		public virtual void  TestCachingByte()
+		{
+			// INT field values are small enough to be parsed as byte
+			DoTestCaching(INT_FIELD, FieldScoreQuery.Type.BYTE);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.SHORT caches/reuses loaded values and consumes the proper RAM resources. </summary>
+		[Test]
+		public virtual void  TestCachingShort()
+		{
+			// INT field values are small enough to be parsed as short
+			DoTestCaching(INT_FIELD, FieldScoreQuery.Type.SHORT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.INT caches/reuses loaded values and consumes the proper RAM resources. </summary>
+		[Test]
+		public virtual void  TestCachingInt()
+		{
+			DoTestCaching(INT_FIELD, FieldScoreQuery.Type.INT);
+		}
+		
+		/// <summary>Test that FieldScoreQuery of Type.FLOAT caches/reuses loaded values and consumes the proper RAM resources. </summary>
+		[Test]
+		public virtual void  TestCachingFloat()
+		{
+			// INT field values can be parsed as float
+			DoTestCaching(INT_FIELD, FieldScoreQuery.Type.FLOAT);
+			// same values, but in flot format
+			DoTestCaching(FLOAT_FIELD, FieldScoreQuery.Type.FLOAT);
+		}
+		
+		// Test that values loaded for FieldScoreQuery are cached properly and consumes the proper RAM resources.
+		private void  DoTestCaching(System.String field, FieldScoreQuery.Type tp)
+		{
+			// prepare expected array types for comparison
+			System.Collections.Hashtable expectedArrayTypes = new System.Collections.Hashtable();
+			expectedArrayTypes[FieldScoreQuery.Type.BYTE] = new byte[0];
+			expectedArrayTypes[FieldScoreQuery.Type.SHORT] = new short[0];
+			expectedArrayTypes[FieldScoreQuery.Type.INT] = new int[0];
+			expectedArrayTypes[FieldScoreQuery.Type.FLOAT] = new float[0];
+			
+			IndexSearcher s = new IndexSearcher(dir);
+			System.Object innerArray = null;
+			
+			bool warned = false; // print warning once.
+			for (int i = 0; i < 10; i++)
+			{
+				FieldScoreQuery q = new FieldScoreQuery(field, tp);
+				Hits h = s.Search(q);
+				Assert.AreEqual(N_DOCS, h.Length(), "All docs should be matched!");
+				try
+				{
+					if (i == 0)
+					{
+						innerArray = q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray();
+						Log(i + ".  compare: " + innerArray.GetType() + " to " + expectedArrayTypes[tp].GetType());
+						Assert.AreEqual(innerArray.GetType(), expectedArrayTypes[tp].GetType(), "field values should be cached in the correct array type!");
+					}
+					else
+					{
+						Log(i + ".  compare: " + innerArray + " to " + q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
+						Assert.AreSame(innerArray, q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "field values should be cached and reused!");
+					}
+				}
+				catch (System.NotSupportedException)
+				{
+					if (!warned)
+					{
+						System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q);
+						warned = true;
+					}
+				}
+			}
+			
+			// verify new values are reloaded (not reused) for a new reader
+			s = new IndexSearcher(dir);
+			FieldScoreQuery q2 = new FieldScoreQuery(field, tp);
+			Hits h2 = s.Search(q2);
+			Assert.AreEqual(N_DOCS, h2.Length(), "All docs should be matched!");
+			try
+			{
+				Log("compare: " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
+				Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "cached field values should not be reused if reader as changed!");
+			}
+			catch (System.NotSupportedException)
+			{
+				if (!warned)
+				{
+					System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+					warned = true;
+				}
+			}
+		}
+		
+		private System.String TestName()
+		{
+			return GetType().FullName;
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Function/TestOrdValues.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Function/TestOrdValues.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,287 @@
+/*
+ * 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 NUnit.Framework;
+
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using Hits = Lucene.Net.Search.Hits;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Query = Lucene.Net.Search.Query;
+using QueryUtils = Lucene.Net.Search.QueryUtils;
+using ScoreDoc = Lucene.Net.Search.ScoreDoc;
+using TopDocs = Lucene.Net.Search.TopDocs;
+
+namespace Lucene.Net.Search.Function
+{
+	
+	/// <summary> Test search based on OrdFieldSource and ReverseOrdFieldSource.
+	/// <p>
+	/// Tests here create an index with a few documents, each having
+	/// an indexed "id" field.
+	/// The ord values of this field are later used for scoring.
+	/// <p>
+	/// The order tests use Hits to verify that docs are ordered as expected.
+	/// <p>
+	/// The exact score tests use TopDocs top to verify the exact score.  
+	/// </summary>
+	[TestFixture]
+	public class TestOrdValues : FunctionTestSetup
+	{
+		
+		/* @override constructor */
+		//public TestOrdValues(System.String name):base(name)
+		//{
+		//}
+		
+		/* @override */
+		[TearDown]
+		public override void  TearDown()
+		{
+			base.TearDown();
+		}
+		
+		/* @override */
+		[SetUp]
+		public override void  SetUp()
+		{
+			// prepare a small index with just a few documents.  
+			base.SetUp();
+		}
+		
+		/// <summary>Test OrdFieldSource </summary>
+		[Test]
+		public virtual void  TestOrdFieldRank()
+		{
+			DoTestRank(ID_FIELD, true);
+		}
+		
+		/// <summary>Test ReverseOrdFieldSource </summary>
+		[Test]
+		public virtual void  TestReverseOrdFieldRank()
+		{
+			DoTestRank(ID_FIELD, false);
+		}
+		
+		// Test that queries based on reverse/ordFieldScore scores correctly
+		private void  DoTestRank(System.String field, bool inOrder)
+		{
+			IndexSearcher s = new IndexSearcher(dir);
+			ValueSource vs;
+			if (inOrder)
+			{
+				vs = new OrdFieldSource(field);
+			}
+			else
+			{
+				vs = new ReverseOrdFieldSource(field);
+			}
+			
+			Query q = new ValueSourceQuery(vs);
+			Log("test: " + q);
+			QueryUtils.Check(q, s);
+			Hits h = s.Search(q);
+			Assert.AreEqual(N_DOCS, h.Length(), "All docs should be matched!");
+			System.String prevID = inOrder?"IE":"IC"; // smaller than all ids of docs in this test ("ID0001", etc.)
+			
+			for (int i = 0; i < h.Length(); i++)
+			{
+				System.String resID = h.Doc(i).Get(ID_FIELD);
+				Log(i + ".   score=" + h.Score(i) + "  -  " + resID);
+				Log(s.Explain(q, h.Id(i)));
+				if (inOrder)
+				{
+					Assert.IsTrue(String.CompareOrdinal(resID, prevID) < 0, "res id " + resID + " should be < prev res id " + prevID);
+				}
+				else
+				{
+					Assert.IsTrue(String.CompareOrdinal(resID, prevID) > 0, "res id " + resID + " should be > prev res id " + prevID);
+				}
+				prevID = resID;
+			}
+		}
+		
+		/// <summary>Test exact score for OrdFieldSource </summary>
+		[Test]
+		public virtual void  TestOrdFieldExactScore()
+		{
+			DoTestExactScore(ID_FIELD, true);
+		}
+		
+		/// <summary>Test exact score for ReverseOrdFieldSource </summary>
+		[Test]
+		public virtual void  TestReverseOrdFieldExactScore()
+		{
+			DoTestExactScore(ID_FIELD, false);
+		}
+		
+		
+		// Test that queries based on reverse/ordFieldScore returns docs with expected score.
+		private void  DoTestExactScore(System.String field, bool inOrder)
+		{
+			IndexSearcher s = new IndexSearcher(dir);
+			ValueSource vs;
+			if (inOrder)
+			{
+				vs = new OrdFieldSource(field);
+			}
+			else
+			{
+				vs = new ReverseOrdFieldSource(field);
+			}
+			Query q = new ValueSourceQuery(vs);
+			TopDocs td = s.Search(q, null, 1000);
+			Assert.AreEqual(N_DOCS, td.totalHits, "All docs should be matched!");
+			ScoreDoc[] sd = td.scoreDocs;
+			for (int i = 0; i < sd.Length; i++)
+			{
+				float score = sd[i].score;
+				System.String id = s.GetIndexReader().Document(sd[i].doc).Get(ID_FIELD);
+				Log("-------- " + i + ". Explain doc " + id);
+				Log(s.Explain(q, sd[i].doc));
+				float expectedScore = N_DOCS - i;
+				Assert.AreEqual(expectedScore, score, TEST_SCORE_TOLERANCE_DELTA, "score of result " + i + " shuould be " + expectedScore + " != " + score);
+				System.String expectedId = inOrder?Id2String(N_DOCS - i):Id2String(i + 1); // reverse  ==> smaller values first 
+				Assert.IsTrue(expectedId.Equals(id), "id of result " + i + " shuould be " + expectedId + " != " + score);
+			}
+		}
+		
+		/// <summary>Test caching OrdFieldSource </summary>
+		[Test]
+		public virtual void  TestCachingOrd()
+		{
+			DoTestCaching(ID_FIELD, true);
+		}
+		
+		/// <summary>Test caching for ReverseOrdFieldSource </summary>
+		[Test]
+		public virtual void  TesCachingReverseOrd()
+		{
+			DoTestCaching(ID_FIELD, false);
+		}
+		
+		// Test that values loaded for FieldScoreQuery are cached properly and consumes the proper RAM resources.
+		private void  DoTestCaching(System.String field, bool inOrder)
+		{
+			IndexSearcher s = new IndexSearcher(dir);
+			System.Object innerArray = null;
+			
+			bool warned = false; // print warning once
+			
+			for (int i = 0; i < 10; i++)
+			{
+				ValueSource vs;
+				if (inOrder)
+				{
+					vs = new OrdFieldSource(field);
+				}
+				else
+				{
+					vs = new ReverseOrdFieldSource(field);
+				}
+				ValueSourceQuery q = new ValueSourceQuery(vs);
+				Hits h = s.Search(q);
+				try
+				{
+					Assert.AreEqual(N_DOCS, h.Length(), "All docs should be matched!");
+					if (i == 0)
+					{
+						innerArray = q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray();
+					}
+					else
+					{
+						Log(i + ".  compare: " + innerArray + " to " + q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
+						Assert.AreSame(innerArray, q.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "field values should be cached and reused!");
+					}
+				}
+				catch (System.NotSupportedException)
+				{
+					if (!warned)
+					{
+						System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q);
+						warned = true;
+					}
+				}
+			}
+			
+			ValueSource vs2;
+			ValueSourceQuery q2;
+			Hits h2;
+			
+			// verify that different values are loaded for a different field
+			System.String field2 = INT_FIELD;
+			Assert.IsFalse(field.Equals(field2)); // otherwise this test is meaningless.
+			if (inOrder)
+			{
+				vs2 = new OrdFieldSource(field2);
+			}
+			else
+			{
+				vs2 = new ReverseOrdFieldSource(field2);
+			}
+			q2 = new ValueSourceQuery(vs2);
+			h2 = s.Search(q2);
+			Assert.AreEqual(N_DOCS, h2.Length(), "All docs should be matched!");
+			try
+			{
+				Log("compare (should differ): " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
+				Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "different values shuold be loaded for a different field!");
+			}
+			catch (System.NotSupportedException)
+			{
+				if (!warned)
+				{
+					System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+					warned = true;
+				}
+			}
+			
+			// verify new values are reloaded (not reused) for a new reader
+			s = new IndexSearcher(dir);
+			if (inOrder)
+			{
+				vs2 = new OrdFieldSource(field);
+			}
+			else
+			{
+				vs2 = new ReverseOrdFieldSource(field);
+			}
+			q2 = new ValueSourceQuery(vs2);
+			h2 = s.Search(q2);
+			Assert.AreEqual(N_DOCS, h2.Length(), "All docs should be matched!");
+			try
+			{
+				Log("compare (should differ): " + innerArray + " to " + q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray());
+				Assert.AreNotSame(innerArray, q2.ValSrc_ForNUnitTest.GetValues(s.GetIndexReader()).GetInnerArray(), "cached field values should not be reused if reader as changed!");
+			}
+			catch (System.NotSupportedException)
+			{
+				if (!warned)
+				{
+					System.Console.Error.WriteLine("WARNING: " + TestName() + " cannot fully test values of " + q2);
+					warned = true;
+				}
+			}
+		}
+		
+		private System.String TestName()
+		{
+			return GetType().FullName;
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/MockFilter.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/MockFilter.cs Tue Jul 15 14:44:04 2008
@@ -27,7 +27,7 @@
 	{
 		private bool wasCalled;
 		
-        public override System.Collections.BitArray Bits(IndexReader reader)
+		public override System.Collections.BitArray Bits(IndexReader reader)
 		{
 			wasCalled = true;
 			return new System.Collections.BitArray(64);

Added: incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Payloads/TestBoostingTermQuery.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,311 @@
+/*
+ * 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 NUnit.Framework;
+
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using Payload = Lucene.Net.Index.Payload;
+using Term = Lucene.Net.Index.Term;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Lucene.Net.Analysis;
+using Lucene.Net.Search;
+using Searchable = Lucene.Net.Search.Searchable;
+using TermSpans = Lucene.Net.Search.Spans.TermSpans;
+using English = Lucene.Net.Util.English;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
+
+namespace Lucene.Net.Search.Payloads
+{
+	
+	[TestFixture]
+	public class TestBoostingTermQuery : LuceneTestCase
+	{
+		public TestBoostingTermQuery() : base()
+		{
+			InitBlock();
+		}
+
+		private void  InitBlock()
+		{
+			similarity = new BoostingSimilarity();
+		}
+		private IndexSearcher searcher;
+		private BoostingSimilarity similarity;
+		private byte[] payloadField = new byte[]{1};
+		private byte[] payloadMultiField1 = new byte[]{2};
+		private byte[] payloadMultiField2 = new byte[]{4};
+		
+		public TestBoostingTermQuery(System.String s):base(s)
+		{
+			InitBlock();
+		}
+		
+		private class PayloadAnalyzer : Analyzer
+		{
+			public PayloadAnalyzer(TestBoostingTermQuery enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(TestBoostingTermQuery enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestBoostingTermQuery enclosingInstance;
+			public TestBoostingTermQuery Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			
+			
+			public override TokenStream TokenStream(System.String fieldName, System.IO.TextReader reader)
+			{
+				TokenStream result = new LowerCaseTokenizer(reader);
+				result = new PayloadFilter(enclosingInstance, result, fieldName);
+				return result;
+			}
+		}
+		
+		private class PayloadFilter : TokenFilter
+		{
+			private void  InitBlock(TestBoostingTermQuery enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestBoostingTermQuery enclosingInstance;
+			public TestBoostingTermQuery Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			internal System.String fieldName;
+			internal int numSeen = 0;
+			
+			public PayloadFilter(TestBoostingTermQuery enclosingInstance, TokenStream input, System.String fieldName):base(input)
+			{
+				InitBlock(enclosingInstance);
+				this.fieldName = fieldName;
+			}
+			
+			public override Token Next()
+			{
+				Token result = input.Next();
+				if (result != null)
+				{
+					if (fieldName.Equals("field"))
+					{
+						result.SetPayload(new Payload(Enclosing_Instance.payloadField));
+					}
+					else if (fieldName.Equals("multiField"))
+					{
+						if (numSeen % 2 == 0)
+						{
+							result.SetPayload(new Payload(Enclosing_Instance.payloadMultiField1));
+						}
+						else
+						{
+							result.SetPayload(new Payload(Enclosing_Instance.payloadMultiField2));
+						}
+						numSeen++;
+					}
+				}
+				return result;
+			}
+		}
+		
+		[SetUp]
+		public override void  SetUp()
+		{
+			base.SetUp();
+			RAMDirectory directory = new RAMDirectory();
+			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true);
+			writer.SetSimilarity(similarity);
+			//writer.infoStream = System.out;
+			for (int i = 0; i < 1000; i++)
+			{
+				Document doc = new Document();
+				Field noPayloadField = new Field("noPayLoad", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED);
+				noPayloadField.SetBoost(0);
+				doc.Add(noPayloadField);
+				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
+				doc.Add(new Field("multiField", English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
+				writer.AddDocument(doc);
+			}
+			writer.Optimize();
+			writer.Close();
+			
+			searcher = new IndexSearcher(directory);
+			searcher.SetSimilarity(similarity);
+		}
+		
+		[Test]
+		public virtual void  Test()
+		{
+			BoostingTermQuery query = new BoostingTermQuery(new Term("field", "seventy"));
+			TopDocs hits = searcher.Search(query, null, 100);
+			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
+			Assert.IsTrue(hits.totalHits == 100, "hits Size: " + hits.totalHits + " is not: " + 100);
+			
+			//they should all have the exact same score, because they all contain seventy once, and we set
+			//all the other similarity factors to be 1
+			
+			Assert.IsTrue(hits.GetMaxScore() == 1, hits.GetMaxScore() + " does not equal: " + 1);
+			for (int i = 0; i < hits.scoreDocs.Length; i++)
+			{
+				ScoreDoc doc = hits.scoreDocs[i];
+				Assert.IsTrue(doc.score == 1, doc.score + " does not equal: " + 1);
+			}
+			CheckHits.CheckExplanations(query, "field", searcher, true);
+			Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
+			/*float score = hits.score(0);
+			for (int i =1; i < hits.length(); i++)
+			{
+			Assert.IsTrue(score == hits.score(i), "scores are not equal and they should be");
+			}*/
+		}
+		
+		[Test]
+		public virtual void  TestMultipleMatchesPerDoc()
+		{
+			BoostingTermQuery query = new BoostingTermQuery(new Term("multiField", "seventy"));
+			TopDocs hits = searcher.Search(query, null, 100);
+			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
+			Assert.IsTrue(hits.totalHits == 100, "hits Size: " + hits.totalHits + " is not: " + 100);
+			
+			//they should all have the exact same score, because they all contain seventy once, and we set
+			//all the other similarity factors to be 1
+			
+			//System.out.println("Hash: " + seventyHash + " Twice Hash: " + 2*seventyHash);
+			Assert.IsTrue(hits.GetMaxScore() == 3, hits.GetMaxScore() + " does not equal: " + 3);
+			//there should be exactly 10 items that score a 3, all the rest should score a 2
+			//The 10 items are: 70 + i*100 where i in [0-9]
+			int numTens = 0;
+			for (int i = 0; i < hits.scoreDocs.Length; i++)
+			{
+				ScoreDoc doc = hits.scoreDocs[i];
+				if (doc.doc % 10 == 0)
+				{
+					numTens++;
+					Assert.IsTrue(doc.score == 3, doc.score + " does not equal: " + 3);
+				}
+				else
+				{
+					Assert.IsTrue(doc.score == 2, doc.score + " does not equal: " + 2);
+				}
+			}
+			Assert.IsTrue(numTens == 10, numTens + " does not equal: " + 10);
+			CheckHits.CheckExplanations(query, "field", searcher, true);
+			Lucene.Net.Search.Spans.Spans spans = query.GetSpans(searcher.GetIndexReader());
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			Assert.IsTrue(spans is TermSpans, "spans is not an instanceof " + typeof(TermSpans));
+			//should be two matches per document
+			int count = 0;
+			//100 hits times 2 matches per hit, we should have 200 in count
+			while (spans.Next())
+			{
+				count++;
+			}
+			Assert.IsTrue(count == 200, count + " does not equal: " + 200);
+		}
+		
+		[Test]
+		public virtual void  TestNoMatch()
+		{
+			BoostingTermQuery query = new BoostingTermQuery(new Term("field", "junk"));
+			TopDocs hits = searcher.Search(query, null, 100);
+			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
+			Assert.IsTrue(hits.totalHits == 0, "hits Size: " + hits.totalHits + " is not: " + 0);
+		}
+		
+		[Test]
+		public virtual void  TestNoPayload()
+		{
+			BoostingTermQuery q1 = new BoostingTermQuery(new Term("noPayLoad", "zero"));
+			BoostingTermQuery q2 = new BoostingTermQuery(new Term("noPayLoad", "foo"));
+			BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
+			BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
+			BooleanQuery query = new BooleanQuery();
+			query.Add(c1);
+			query.Add(c2);
+			TopDocs hits = searcher.Search(query, null, 100);
+			Assert.IsTrue(hits != null, "hits is null and it shouldn't be");
+			//Assert.IsTrue(hits.totalHits == 1, "hits Size: " + hits.totalHits + " is not: " + 1);
+			int[] results = new int[1];
+			results[0] = 0; //hits.scoreDocs[0].doc;
+			CheckHits.CheckHitCollector(query, "noPayLoad", searcher, results);
+		}
+		
+		// must be static for weight serialization tests 
+		[Serializable]
+		internal class BoostingSimilarity : DefaultSimilarity
+		{
+			
+			// TODO: Remove warning after API has been finalized
+			public override float ScorePayload(System.String fieldName, byte[] payload, int offset, int length)
+			{
+				//we know it is size 4 here, so ignore the offset/length
+				return payload[0];
+			}
+			
+			//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+			//Make everything else 1 so we see the effect of the payload
+			//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+			public override float LengthNorm(System.String fieldName, int numTerms)
+			{
+				return 1;
+			}
+			
+			public override float QueryNorm(float sumOfSquaredWeights)
+			{
+				return 1;
+			}
+			
+			public override float SloppyFreq(int distance)
+			{
+				return 1;
+			}
+			
+			public override float Coord(int overlap, int maxOverlap)
+			{
+				return 1;
+			}
+			
+			public override float Idf(int docFreq, int numDocs)
+			{
+				return 1;
+			}
+			
+			public override float Tf(float freq)
+			{
+				return freq == 0?0:1;
+			}
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/QueryUtils.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/QueryUtils.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/QueryUtils.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/QueryUtils.cs Tue Jul 15 14:44:04 2008
@@ -16,7 +16,9 @@
  */
 
 using System;
+
 using NUnit.Framework;
+
 namespace Lucene.Net.Search
 {
 	
@@ -37,50 +39,100 @@
 			}
 		}
 
-        private class AnonymousClassHitCollector : HitCollector
-        {
-            public AnonymousClassHitCollector(int[] which, Lucene.Net.Search.Scorer scorer, int[] sdoc, float maxDiff, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s)
-            {
-                InitBlock(which, scorer, sdoc, maxDiff, q, s);
-            }
-            private void  InitBlock(int[] which, Lucene.Net.Search.Scorer scorer, int[] sdoc, float maxDiff, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s)
-            {
-                this.which = which;
-                this.scorer = scorer;
-                this.sdoc = sdoc;
-                this.maxDiff = maxDiff;
-                this.q = q;
-                this.s = s;
-            }
-            private int[] which;
-            private Lucene.Net.Search.Scorer scorer;
-            private int[] sdoc;
-            private float maxDiff;
-            private Lucene.Net.Search.Query q;
-            private Lucene.Net.Search.IndexSearcher s;
-            public override void  Collect(int doc, float score)
-            {
-                try
-                {
-                    bool more = (which[0]++ & 0x02) == 0?scorer.SkipTo(sdoc[0] + 1):scorer.Next();
-                    sdoc[0] = scorer.Doc();
-                    float scorerScore = scorer.Score();
-                    float scoreDiff = System.Math.Abs(score - scorerScore);
-                    scoreDiff = 0; // TODO: remove this go get LUCENE-697
-                    // failures
-                    if (more == false || doc != sdoc[0] || scoreDiff > maxDiff)
-                    {
-                        throw new System.SystemException("ERROR matching docs:" + "\n\tscorer.more=" + more + " doc=" + sdoc[0] + " score=" + scorerScore + "\n\thitCollector.doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + "\n\t Searcher=" + s);
-                    }
-                }
-                catch (System.IO.IOException e)
-                {
-                    throw new System.SystemException("", e);
-                }
-            }
-        }
+		private class AnonymousClassHitCollector : HitCollector
+		{
+			public AnonymousClassHitCollector(int[] order, int[] opidx, int skip_op, Lucene.Net.Search.Scorer scorer, int[] sdoc, float maxDiff, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s)
+			{
+				InitBlock(order, opidx, skip_op, scorer, sdoc, maxDiff, q, s);
+			}
+			private void  InitBlock(int[] order, int[] opidx, int skip_op, Lucene.Net.Search.Scorer scorer, int[] sdoc, float maxDiff, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s)
+			{
+				this.order = order;
+				this.opidx = opidx;
+				this.skip_op = skip_op;
+				this.scorer = scorer;
+				this.sdoc = sdoc;
+				this.maxDiff = maxDiff;
+				this.q = q;
+				this.s = s;
+			}
+			private int[] order;
+			private int[] opidx;
+			private int skip_op;
+			private Lucene.Net.Search.Scorer scorer;
+			private int[] sdoc;
+			private float maxDiff;
+			private Lucene.Net.Search.Query q;
+			private Lucene.Net.Search.IndexSearcher s;
+			public override void  Collect(int doc, float score)
+			{
+				try
+				{
+					int op = order[(opidx[0]++) % order.Length];
+					//System.out.println(op==skip_op ? "skip("+(sdoc[0]+1)+")":"next()");
+					bool more = op == skip_op?scorer.SkipTo(sdoc[0] + 1):scorer.Next();
+					sdoc[0] = scorer.Doc();
+					float scorerScore = scorer.Score();
+					float scorerScore2 = scorer.Score();
+					float scoreDiff = System.Math.Abs(score - scorerScore);
+					float scorerDiff = System.Math.Abs(scorerScore2 - scorerScore);
+					if (!more || doc != sdoc[0] || scoreDiff > maxDiff || scorerDiff > maxDiff)
+					{
+						System.Text.StringBuilder sbord = new System.Text.StringBuilder();
+						for (int i = 0; i < order.Length; i++)
+							sbord.Append(order[i] == skip_op?" skip()":" next()");
+						throw new System.SystemException("ERROR matching docs:" + "\n\t" + (doc != sdoc[0]?"--> ":"") + "doc=" + sdoc[0] + "\n\t" + (!more?"--> ":"") + "tscorer.more=" + more + "\n\t" + (scoreDiff > maxDiff?"--> ":"") + "scorerScore=" + scorerScore + " scoreDiff=" + scoreDiff + " maxDiff=" + maxDiff + "\n\t" + (scorerDiff > maxDiff?"--> ":"") + "scorerScore2=" + scorerScore2 + " scorerDiff=" + scorerDiff + "\n\thitCollector.doc=" + doc + " score=" + score + "\n\t Scorer=" + scorer + "\n\t Query=" + q + "  " + q.GetType().FullName + "\n\t Searcher=" + s + "\n\t Order=" + sbord + "\n\t Op=" + (op == skip_op?" skip()":" next()"));
+					}
+				}
+				catch (System.IO.IOException e)
+				{
+					throw new System.Exception("", e);
+				}
+			}
+		}
 		
-        /// <summary>Check the types of things query objects should be able to do. </summary>
+		private class AnonymousClassHitCollector1 : HitCollector
+		{
+			public AnonymousClassHitCollector1(int[] lastDoc, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s, float maxDiff)
+			{
+				InitBlock(lastDoc, q, s, maxDiff);
+			}
+			private void  InitBlock(int[] lastDoc, Lucene.Net.Search.Query q, Lucene.Net.Search.IndexSearcher s, float maxDiff)
+			{
+				this.lastDoc = lastDoc;
+				this.q = q;
+				this.s = s;
+				this.maxDiff = maxDiff;
+			}
+			private int[] lastDoc;
+			private Lucene.Net.Search.Query q;
+			private Lucene.Net.Search.IndexSearcher s;
+			private float maxDiff;
+			public override void  Collect(int doc, float score)
+			{
+				//System.out.println("doc="+doc);
+				try
+				{
+					for (int i = lastDoc[0] + 1; i <= doc; i++)
+					{
+						Weight w = q.Weight(s);
+						Scorer scorer = w.Scorer(s.GetIndexReader());
+						Assert.IsTrue(scorer.SkipTo(i), "query collected " + doc + " but skipTo(" + i + ") says no more docs!");
+						Assert.AreEqual(doc, scorer.Doc(), "query collected " + doc + " but skipTo(" + i + ") got to " + scorer.Doc());
+						float skipToScore = scorer.Score();
+						Assert.AreEqual(skipToScore, scorer.Score(), maxDiff, "unstable skipTo(" + i + ") score!");
+						Assert.AreEqual(score, skipToScore, maxDiff, "query assigned doc " + doc + " a score of <" + score + "> but skipTo(" + i + ") has <" + skipToScore + ">!");
+					}
+					lastDoc[0] = doc;
+				}
+				catch (System.IO.IOException e)
+				{
+					throw new System.Exception("", e);
+				}
+			}
+		}
+		
+		/// <summary>Check the types of things query objects should be able to do. </summary>
 		public static void  Check(Query q)
 		{
 			CheckHashEquals(q);
@@ -111,53 +163,125 @@
 		
 		public static void  CheckUnequal(Query q1, Query q2)
 		{
-            Assert.IsTrue(q1.ToString() != q2.ToString());
-            Assert.IsTrue(q2.ToString() != q1.ToString());
+			Assert.IsTrue(q1.ToString() != q2.ToString());
+			Assert.IsTrue(q2.ToString() != q1.ToString());
 			
 			// possible this test can fail on a hash collision... if that
 			// happens, please change test to use a different example.
 			Assert.IsTrue(q1.GetHashCode() != q2.GetHashCode());
 		}
 		
-        /// <summary>various query sanity checks on a searcher </summary>
-        public static void  Check(Query q1, Searcher s)
-        {
-            try
-            {
-                Check(q1);
-                if (s != null && s is IndexSearcher)
-                {
-                    IndexSearcher is_Renamed = (IndexSearcher) s;
-                    CheckSkipTo(q1, is_Renamed);
-                }
-            }
-            catch (System.IO.IOException e)
-            {
-                throw new System.SystemException("", e);
-            }
-        }
-		
-        /// <summary> alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc
-        /// and ensure a hitcollector receives same docs and scores
-        /// </summary>
-        public static void  CheckSkipTo(Query q, IndexSearcher s)
-        {
-            // System.out.println("Checking "+q);
-            Weight w = q.Weight(s);
-            Scorer scorer = w.Scorer(s.GetIndexReader());
-			
-            // FUTURE: ensure scorer.doc()==-1
-			
-            if (BooleanQuery.GetUseScorer14())
-                return ; // 1.4 doesn't support skipTo
+		/// <summary>deep check that explanations of a query 'score' correctly </summary>
+		public static void  CheckExplanations(Query q, Searcher s)
+		{
+			CheckHits.CheckExplanations(q, null, s, true);
+		}
+		
+		/// <summary> various query sanity checks on a searcher, including explanation checks.</summary>
+		/// <seealso cref="checkExplanations">
+		/// </seealso>
+		/// <seealso cref="checkSkipTo">
+		/// </seealso>
+		/// <seealso cref="Check(Query)">
+		/// </seealso>
+		public static void  Check(Query q1, Searcher s)
+		{
+			try
+			{
+				Check(q1);
+				if (s != null)
+				{
+					if (s is IndexSearcher)
+					{
+						IndexSearcher is_Renamed = (IndexSearcher) s;
+						CheckFirstSkipTo(q1, is_Renamed);
+						CheckSkipTo(q1, is_Renamed);
+					}
+					CheckExplanations(q1, s);
+					CheckSerialization(q1, s);
+				}
+			}
+			catch (System.IO.IOException e)
+			{
+				throw new System.Exception("", e);
+			}
+		}
+		
+		/// <summary>check that the query weight is serializable. </summary>
+		/// <throws>  IOException if serialization check fail.  </throws>
+		private static void  CheckSerialization(Query q, Searcher s)
+		{
+			Weight w = q.Weight(s);
+			try
+			{
+				System.IO.MemoryStream bos = new System.IO.MemoryStream();
+				System.IO.BinaryWriter oos = new System.IO.BinaryWriter(bos);
+				System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
+				formatter.Serialize(oos.BaseStream, w);
+				oos.Close();
+				System.IO.BinaryReader ois = new System.IO.BinaryReader(new System.IO.MemoryStream(bos.ToArray()));
+				formatter.Deserialize(ois.BaseStream);
+				ois.Close();
+				
+				//skip rquals() test for now - most weights don't overide equals() and we won't add this just for the tests.
+				//TestCase.assertEquals("writeObject(w) != w.  ("+w+")",w2,w);   
+			}
+			catch (System.Exception e)
+			{
+				System.IO.IOException e2 = new System.IO.IOException("Serialization failed for " + w, e);
+				throw e2;
+			}
+		}
+		
+		
+		/// <summary>alternate scorer skipTo(),skipTo(),next(),next(),skipTo(),skipTo(), etc
+		/// and ensure a hitcollector receives same docs and scores
+		/// </summary>
+		public static void  CheckSkipTo(Query q, IndexSearcher s)
+		{
+			//System.out.println("Checking "+q);
 			
-            int[] which = new int[1];
-            int[] sdoc = new int[]{- 1};
-            float maxDiff = 1e-5f;
-            s.Search(q, new AnonymousClassHitCollector(which, scorer, sdoc, maxDiff, q, s));
+			if (BooleanQuery.GetAllowDocsOutOfOrder())
+				return ; // in this case order of skipTo() might differ from that of next().
 			
-            // make sure next call to scorer is false.
-            Assert.IsFalse((which[0]++ & 0x02) == 0 ? scorer.SkipTo(sdoc[0] + 1) : scorer.Next());
-        }
-    }
+			int skip_op = 0;
+			int next_op = 1;
+			int[][] orders = new int[][]{new int[]{next_op}, new int[]{skip_op}, new int[]{skip_op, next_op}, new int[]{next_op, skip_op}, new int[]{skip_op, skip_op, next_op, next_op}, new int[]{next_op, next_op, skip_op, skip_op}, new int[]{skip_op, skip_op, skip_op, next_op, next_op}};
+			for (int k = 0; k < orders.Length; k++)
+			{
+				int[] order = orders[k];
+				//System.out.print("Order:");for (int i = 0; i < order.length; i++) System.out.print(order[i]==skip_op ? " skip()":" next()"); System.out.println();
+				int[] opidx = new int[]{0};
+				
+				Weight w = q.Weight(s);
+				Scorer scorer = w.Scorer(s.GetIndexReader());
+				
+				// FUTURE: ensure scorer.doc()==-1
+				
+				int[] sdoc = new int[]{- 1};
+				float maxDiff = 1e-5f;
+				s.Search(q, new AnonymousClassHitCollector(order, opidx, skip_op, scorer, sdoc, maxDiff, q, s));
+				
+				// make sure next call to scorer is false.
+				int op = order[(opidx[0]++) % order.Length];
+				//System.out.println(op==skip_op ? "last: skip()":"last: next()");
+				bool more = op == skip_op?scorer.SkipTo(sdoc[0] + 1):scorer.Next();
+				Assert.IsFalse(more);
+			}
+		}
+		
+		// check that first skip on just created scorers always goes to the right doc
+		private static void  CheckFirstSkipTo(Query q, IndexSearcher s)
+		{
+			//System.out.println("checkFirstSkipTo: "+q);
+			float maxDiff = 1e-5f;
+			int[] lastDoc = new int[]{- 1};
+			s.Search(q, new AnonymousClassHitCollector1(lastDoc, q, s, maxDiff));
+			Weight w = q.Weight(s);
+			Scorer scorer = w.Scorer(s.GetIndexReader());
+			bool more = scorer.SkipTo(lastDoc[0] + 1);
+			if (more)
+				Assert.IsFalse(more, "query's last doc was " + lastDoc[0] + " but skipTo(" + (lastDoc[0] + 1) + ") got to " + scorer.Doc());
+		}
+	}
 }
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Test/Search/RemoteCachingWrapperFilterHelper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/RemoteCachingWrapperFilterHelper.cs?rev=677059&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/RemoteCachingWrapperFilterHelper.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/RemoteCachingWrapperFilterHelper.cs Tue Jul 15 14:44:04 2008
@@ -0,0 +1,69 @@
+/*
+ * 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 NUnit.Framework;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary> A unit test helper class to help with RemoteCachingWrapperFilter testing and
+	/// assert that it is working correctly.
+	/// </summary>
+	/// <author>  Matt Ericson
+	/// </author>
+	[Serializable]
+	public class RemoteCachingWrapperFilterHelper : RemoteCachingWrapperFilter
+	{
+		
+		private bool shouldHaveCache;
+		
+		public RemoteCachingWrapperFilterHelper(Filter filter, bool shouldHaveCache) : base(filter)
+		{
+			this.shouldHaveCache = shouldHaveCache;
+		}
+		
+		public virtual void  ShouldHaveCache(bool shouldHaveCache)
+		{
+			this.shouldHaveCache = shouldHaveCache;
+		}
+		
+		public override System.Collections.BitArray Bits(IndexReader reader)
+		{
+			Filter cachedFilter = FilterManager.GetInstance().GetFilter(filter);
+			
+			Assert.IsNotNull(cachedFilter, "Filter should not be null");
+			if (!shouldHaveCache)
+			{
+				Assert.AreSame(filter, cachedFilter, "First time filter should be the same ");
+			}
+			else
+			{
+				Assert.AreNotSame(filter, cachedFilter, "We should have a cached version of the filter");
+			}
+			
+			if (filter is CachingWrapperFilterHelper)
+			{
+				((CachingWrapperFilterHelper) cachedFilter).SetShouldHaveCache(shouldHaveCache);
+			}
+			return cachedFilter.Bits(reader);
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/SampleComparable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/SampleComparable.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/SampleComparable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/SampleComparable.cs Tue Jul 15 14:44:04 2008
@@ -41,11 +41,10 @@
 	/// <p/>
 	/// <p>Created: Apr 21, 2004 5:34:47 PM
 	/// 
+	/// 
 	/// </summary>
-	/// <author>  Tim Jones
-	/// </author>
-    /// <version>  $Id: SampleComparable.java 472959 2006-11-09 16:21:50Z yonik $
-    /// </version>
+	/// <version>  $Id: SampleComparable.java 564236 2007-08-09 15:21:19Z gsingers $
+	/// </version>
 	/// <since> 1.4
 	/// </since>
 	[Serializable]
@@ -81,7 +80,7 @@
 					
 				}
 
-                protected internal System.IComparable[] cachedValues;
+				protected internal System.IComparable[] cachedValues;
 				
 				public virtual int Compare(ScoreDoc i, ScoreDoc j)
 				{
@@ -174,15 +173,15 @@
 			}
 		}
 
-        public static SortComparatorSource GetComparatorSource()
-        {
-            return new AnonymousClassSortComparatorSource();
-        }
+		public static SortComparatorSource GetComparatorSource()
+		{
+			return new AnonymousClassSortComparatorSource();
+		}
 
-        public static SortComparator GetComparator()
-        {
-            return new AnonymousClassSortComparator();
-        }
+		public static SortComparator GetComparator()
+		{
+			return new AnonymousClassSortComparator();
+		}
 		
 		internal System.String string_part;
 		internal System.Int32 int_part;

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/SingleDocTestFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/SingleDocTestFilter.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/SingleDocTestFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/SingleDocTestFilter.cs Tue Jul 15 14:44:04 2008
@@ -22,27 +22,27 @@
 namespace Lucene.Net.search
 {
 	
-    [Serializable]
-    public class SingleDocTestFilter : Lucene.Net.Search.Filter
-    {
-        private int doc;
+	[Serializable]
+	public class SingleDocTestFilter : Lucene.Net.Search.Filter
+	{
+		private int doc;
 		
-        public SingleDocTestFilter(int doc)
-        {
-            this.doc = doc;
-        }
+		public SingleDocTestFilter(int doc)
+		{
+			this.doc = doc;
+		}
 		
-        public override System.Collections.BitArray Bits(IndexReader reader)
-        {
-            System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
+		public override System.Collections.BitArray Bits(IndexReader reader)
+		{
+			System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
 
-            for (int increment = 0; doc >= bits.Length; increment =+ 64)
-            {
-                bits.Length += increment;
-            }
-            bits.Set(doc, true);
-            
-            return bits;
-        }
-    }
+			for (int increment = 0; doc >= bits.Length; increment =+ 64)
+			{
+				bits.Length += increment;
+			}
+			bits.Set(doc, true);
+			
+			return bits;
+		}
+	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestBasics.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestBasics.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestBasics.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestBasics.cs Tue Jul 15 14:44:04 2008
@@ -19,15 +19,16 @@
 
 using NUnit.Framework;
 
-using English = Lucene.Net.Util.English;
-using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 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 RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using SimpleAnalyzer = Lucene.Net.Analysis.SimpleAnalyzer;
 using Lucene.Net.Search;
 using Searchable = Lucene.Net.Search.Searchable;
+using English = Lucene.Net.Util.English;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Search.Spans
 {
@@ -46,13 +47,14 @@
 	/// <author>  Doug Cutting
 	/// </author>
 	[TestFixture]
-    public class TestBasics
+	public class TestBasics : LuceneTestCase
 	{
 		private IndexSearcher searcher;
 		
 		[SetUp]
-        public virtual void  SetUp()
+		public override void SetUp()
 		{
+			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
 			//writer.infoStream = System.out;
@@ -69,21 +71,21 @@
 		}
 		
 		[Test]
-        public virtual void  TestTerm()
+		public virtual void  TestTerm()
 		{
 			Query query = new TermQuery(new Term("field", "seventy"));
 			CheckHits(query, new int[]{70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979});
 		}
 		
 		[Test]
-        public virtual void  TestTerm2()
+		public virtual void  TestTerm2()
 		{
 			Query query = new TermQuery(new Term("field", "seventish"));
 			CheckHits(query, new int[]{});
 		}
 		
 		[Test]
-        public virtual void  TestPhrase()
+		public virtual void  TestPhrase()
 		{
 			PhraseQuery query = new PhraseQuery();
 			query.Add(new Term("field", "seventy"));
@@ -92,7 +94,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestPhrase2()
+		public virtual void  TestPhrase2()
 		{
 			PhraseQuery query = new PhraseQuery();
 			query.Add(new Term("field", "seventish"));
@@ -101,7 +103,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestBoolean()
+		public virtual void  TestBoolean()
 		{
 			BooleanQuery query = new BooleanQuery();
 			query.Add(new TermQuery(new Term("field", "seventy")), BooleanClause.Occur.MUST);
@@ -110,7 +112,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestBoolean2()
+		public virtual void  TestBoolean2()
 		{
 			BooleanQuery query = new BooleanQuery();
 			query.Add(new TermQuery(new Term("field", "sevento")), BooleanClause.Occur.MUST);
@@ -119,7 +121,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestSpanNearExact()
+		public virtual void  TestSpanNearExact()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "seven"));
@@ -129,23 +131,24 @@
 			Assert.IsTrue(searcher.Explain(query, 77).GetValue() > 0.0f);
 			Assert.IsTrue(searcher.Explain(query, 977).GetValue() > 0.0f);
 			
-            QueryUtils.Check(term1);
-            QueryUtils.Check(term2);
-            QueryUtils.CheckUnequal(term1, term2);
-        }
+			QueryUtils.Check(term1);
+			QueryUtils.Check(term2);
+			QueryUtils.CheckUnequal(term1, term2);
+		}
 		
 		[Test]
-        public virtual void  TestSpanNearUnordered()
+		public virtual void  TestSpanNearUnordered()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six"));
 			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, false);
-			
-			CheckHits(query, new int[]{609, 629, 639, 649, 659, 669, 679, 689, 699, 906, 926, 936, 946, 956, 966, 976, 986, 996});
+
+			//CheckHits(query, new int[] { 609, 629, 639, 649, 659, 669, 679, 689, 699, 906, 926, 936, 946, 956, 966, 976, 986, 996 });
+			CheckHits(query, new int[] { 609, 906, 629, 639, 649, 659, 669, 679, 689, 699, 926, 936, 946, 956, 966, 976, 986, 996 });
 		}
 		
 		[Test]
-        public virtual void  TestSpanNearOrdered()
+		public virtual void  TestSpanNearOrdered()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "nine"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "six"));
@@ -154,7 +157,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestSpanNot()
+		public virtual void  TestSpanNot()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
@@ -168,81 +171,81 @@
 			Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
 		}
 		
-        [Test]
-        public virtual void  TestSpanWithMultipleNotSingle()
-        {
-            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
-            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
-            SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
-            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
-			
-            SpanOrQuery or = new SpanOrQuery(new SpanQuery[]{term3});
-			
-            SpanNotQuery query = new SpanNotQuery(near, or);
-			
-            CheckHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891});
-			
-            Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
-            Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
-        }
-		
-        [Test]
-        public virtual void  TestSpanWithMultipleNotMany()
-        {
-            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
-            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
-            SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
-            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
-            SpanTermQuery term4 = new SpanTermQuery(new Term("field", "sixty"));
-            SpanTermQuery term5 = new SpanTermQuery(new Term("field", "eighty"));
-			
-            SpanOrQuery or = new SpanOrQuery(new SpanQuery[]{term3, term4, term5});
-			
-            SpanNotQuery query = new SpanNotQuery(near, or);
-			
-            CheckHits(query, new int[]{801, 821, 831, 851, 871, 891});
-			
-            Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
-            Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
-        }
-		
-        [Test]
-        public virtual void  TestNpeInSpanNearWithSpanNot()
-        {
-            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
-            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
-            SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
-            SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
-            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
-            SpanNearQuery exclude = new SpanNearQuery(new SpanQuery[]{hun, term3}, 1, true);
-			
-            SpanNotQuery query = new SpanNotQuery(near, exclude);
-			
-            CheckHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891});
-			
-            Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
-            Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
-        }
-		
-		
-        [Test]
-        public virtual void  TestNpeInSpanNearInSpanFirstInSpanNot()
-        {
-            int n = 5;
-            SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
-            SpanTermQuery term40 = new SpanTermQuery(new Term("field", "forty"));
-            SpanTermQuery term40c = (SpanTermQuery) term40.Clone();
-			
-            SpanFirstQuery include = new SpanFirstQuery(term40, n);
-            SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{hun, term40c}, n - 1, true);
-            SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
-            SpanNotQuery q = new SpanNotQuery(include, exclude);
+		[Test]
+		public virtual void  TestSpanWithMultipleNotSingle()
+		{
+			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
+			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
+			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
+			SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
+			
+			SpanOrQuery or = new SpanOrQuery(new SpanQuery[]{term3});
 			
-            CheckHits(q, new int[]{40, 41, 42, 43, 44, 45, 46, 47, 48, 49});
-        }
+			SpanNotQuery query = new SpanNotQuery(near, or);
+			
+			CheckHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891});
+			
+			Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
+			Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
+		}
 		
-        [Test]
-        public virtual void  TestSpanFirst()
+		[Test]
+		public virtual void  TestSpanWithMultipleNotMany()
+		{
+			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
+			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
+			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
+			SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
+			SpanTermQuery term4 = new SpanTermQuery(new Term("field", "sixty"));
+			SpanTermQuery term5 = new SpanTermQuery(new Term("field", "eighty"));
+			
+			SpanOrQuery or = new SpanOrQuery(new SpanQuery[]{term3, term4, term5});
+			
+			SpanNotQuery query = new SpanNotQuery(near, or);
+			
+			CheckHits(query, new int[]{801, 821, 831, 851, 871, 891});
+			
+			Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
+			Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
+		}
+		
+		[Test]
+		public virtual void  TestNpeInSpanNearWithSpanNot()
+		{
+			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
+			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
+			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
+			SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
+			SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
+			SpanNearQuery exclude = new SpanNearQuery(new SpanQuery[]{hun, term3}, 1, true);
+			
+			SpanNotQuery query = new SpanNotQuery(near, exclude);
+			
+			CheckHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891});
+			
+			Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
+			Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
+		}
+		
+		
+		[Test]
+		public virtual void  TestNpeInSpanNearInSpanFirstInSpanNot()
+		{
+			int n = 5;
+			SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
+			SpanTermQuery term40 = new SpanTermQuery(new Term("field", "forty"));
+			SpanTermQuery term40c = (SpanTermQuery) term40.Clone();
+			
+			SpanFirstQuery include = new SpanFirstQuery(term40, n);
+			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{hun, term40c}, n - 1, true);
+			SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
+			SpanNotQuery q = new SpanNotQuery(include, exclude);
+			
+			CheckHits(q, new int[]{40, 41, 42, 43, 44, 45, 46, 47, 48, 49});
+		}
+		
+		[Test]
+		public virtual void  TestSpanFirst()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five"));
 			SpanFirstQuery query = new SpanFirstQuery(term1, 1);
@@ -254,7 +257,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestSpanOr()
+		public virtual void  TestSpanOr()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "thirty"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "three"));
@@ -272,7 +275,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestSpanExactNested()
+		public virtual void  TestSpanExactNested()
 		{
 			SpanTermQuery term1 = new SpanTermQuery(new Term("field", "three"));
 			SpanTermQuery term2 = new SpanTermQuery(new Term("field", "hundred"));
@@ -289,7 +292,7 @@
 		}
 		
 		[Test]
-        public virtual void  TestSpanNearOr()
+		public virtual void  TestSpanNearOr()
 		{
 			
 			SpanTermQuery t1 = new SpanTermQuery(new Term("field", "six"));
@@ -302,12 +305,13 @@
 			SpanOrQuery to2 = new SpanOrQuery(new SpanQuery[]{t5, t6});
 			
 			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{to1, to2}, 10, true);
-			
-			CheckHits(query, new int[]{606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
+
+			//CheckHits(query, new int[] { 606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797 });
+			CheckHits(query, new int[] { 606, 607, 706, 707, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797 });
 		}
 		
 		[Test]
-        public virtual void  TestSpanComplex1()
+		public virtual void  TestSpanComplex1()
 		{
 			
 			SpanTermQuery t1 = new SpanTermQuery(new Term("field", "six"));
@@ -325,14 +329,15 @@
 			SpanOrQuery to2 = new SpanOrQuery(new SpanQuery[]{t5, t6});
 			
 			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{to1, to2}, 100, true);
-			
-			CheckHits(query, new int[]{606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
+
+			//CheckHits(query, new int[] { 606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797 });
+			CheckHits(query, new int[] { 606, 607, 706, 707, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797 });
 		}
 		
 		
 		private void  CheckHits(Query query, int[] results)
 		{
-            Lucene.Net.Search.CheckHits.CheckHits_Renamed(query, "field", searcher, results);
-        }
+			Lucene.Net.Search.CheckHits.CheckHits_Renamed(query, "field", searcher, results);
+		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestNearSpansOrdered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestNearSpansOrdered.cs?rev=677059&r1=677058&r2=677059&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestNearSpansOrdered.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestNearSpansOrdered.cs Tue Jul 15 14:44:04 2008
@@ -19,39 +19,42 @@
 
 using NUnit.Framework;
 
+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 QueryParser = Lucene.Net.QueryParsers.QueryParser;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+using CheckHits = Lucene.Net.Search.CheckHits;
 using Explanation = Lucene.Net.Search.Explanation;
 using IndexSearcher = Lucene.Net.Search.IndexSearcher;
 using Scorer = Lucene.Net.Search.Scorer;
 using Weight = Lucene.Net.Search.Weight;
-using CheckHits = Lucene.Net.Search.CheckHits;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
-using IndexWriter = Lucene.Net.Index.IndexWriter;
-using Term = Lucene.Net.Index.Term;
-using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
-using QueryParser = Lucene.Net.QueryParsers.QueryParser;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Search.Spans
 {
 	
-    [TestFixture]
-	public class TestNearSpansOrdered
+	[TestFixture]
+	public class TestNearSpansOrdered : LuceneTestCase
 	{
 		protected internal IndexSearcher searcher;
 		
 		public const System.String FIELD = "field";
 		public static readonly Lucene.Net.QueryParsers.QueryParser qp = new Lucene.Net.QueryParsers.QueryParser(FIELD, new WhitespaceAnalyzer());
 		
-        [TearDown]
-		public virtual void  TearDown()
+		[TearDown]
+		public override void TearDown()
 		{
+			base.TearDown();
 			searcher.Close();
 		}
 		
-        [SetUp]
-		public virtual void  SetUp()
+		[SetUp]
+		public override void SetUp()
 		{
+			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
 			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
 			for (int i = 0; i < docFields.Length; i++)
@@ -76,7 +79,7 @@
 			return MakeQuery("w1", "w2", "w3", 1, true);
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestSpanNearQuery()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -93,7 +96,7 @@
 			return "s(" + doc + "," + start + "," + end + ")";
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansNext()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -121,7 +124,7 @@
 			Assert.AreEqual(false, span.SkipTo(2));
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansNextThenSkipTo()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -133,7 +136,7 @@
 			Assert.AreEqual(false, span.Next());
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansNextThenSkipPast()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -143,7 +146,7 @@
 			Assert.AreEqual(false, span.SkipTo(2));
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansSkipPast()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -151,7 +154,7 @@
 			Assert.AreEqual(false, span.SkipTo(2));
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansSkipTo0()
 		{
 			SpanNearQuery q = MakeQuery();
@@ -160,7 +163,7 @@
 			Assert.AreEqual(S(0, 0, 3), S(span));
 		}
 		
-        [Test]
+		[Test]
 		public virtual void  TestNearSpansSkipTo1()
 		{
 			SpanNearQuery q = MakeQuery();



Mime
View raw message