lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dougs...@apache.org
Subject svn commit: r798995 [30/35] - in /incubator/lucene.net/trunk/C#/src: Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Analysis/Standard/ Lucene.Net/Document/ Lucene.Net/Index/ Lucene.Net/QueryParser/ Lucene.Net/Search/ Lucene.Net/Search/Function/ Lucene.Net...
Date Wed, 29 Jul 2009 18:04:24 GMT
Added: incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Payloads/PayloadHelper.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/PayloadHelper.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,123 @@
+/*
+ * 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 Analyzer = Lucene.Net.Analysis.Analyzer;
+using LowerCaseTokenizer = Lucene.Net.Analysis.LowerCaseTokenizer;
+using Token = Lucene.Net.Analysis.Token;
+using TokenFilter = Lucene.Net.Analysis.TokenFilter;
+using TokenStream = Lucene.Net.Analysis.TokenStream;
+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 IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Similarity = Lucene.Net.Search.Similarity;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using English = Lucene.Net.Util.English;
+
+namespace Lucene.Net.Search.Payloads
+{
+    public class PayloadHelper
+    {
+        private static readonly byte[] payloadField = new byte[] { 1 };
+        private static readonly byte[] payloadMultiField1 = new byte[] { 2 };
+        private static readonly byte[] payloadMultiField2 = new byte[] { 4 };
+        public static readonly string NO_PAYLOAD_FIELD = "noPayloadField";
+        public static readonly string MULTI_FIELD = "multiField";
+        public static readonly string FIELD = "field";
+
+        public class PayloadAnalyzer : Analyzer
+        {
+            public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
+            {
+                TokenStream result = new LowerCaseTokenizer(reader);
+                result = new PayloadFilter(result, fieldName);
+                return result;
+            }
+        }
+
+        public class PayloadFilter : TokenFilter
+        {
+            string fieldName;
+            int numSeen = 0;
+
+            public PayloadFilter(TokenStream input, string fieldName)
+                : base(input)
+            {
+                this.fieldName = fieldName;
+            }
+
+            public override Token Next()
+            {
+                Token result = input.Next();
+                if (result != null)
+                {
+                    if (fieldName.Equals(FIELD))
+                    {
+                        result.SetPayload(new _Payload(PayloadHelper.payloadField));
+                    }
+                    else if (fieldName.Equals(MULTI_FIELD))
+                    {
+                        if (numSeen % 2 == 0)
+                        {
+                            result.SetPayload(new _Payload(PayloadHelper.payloadMultiField1));
+                        }
+                        else
+                        {
+                            result.SetPayload(new _Payload(PayloadHelper.payloadMultiField2));
+                        }
+                        numSeen++;
+                    }
+
+                }
+                return result;
+            }
+        }
+
+        /**
+         * Sets up a RAMDirectory, and adds documents (using English.intToEnglish()) with two fields: field and multiField
+         * and analyzes them using the PayloadAnalyzer
+         * @param similarity The Similarity class to use in the Searcher
+         * @param numDocs The num docs to add
+         * @return An IndexSearcher
+         * @throws IOException
+         */
+        public IndexSearcher SetUp(Similarity similarity, int numDocs)
+        {
+            RAMDirectory directory = new RAMDirectory();
+            PayloadAnalyzer analyzer = new PayloadAnalyzer();
+            IndexWriter writer
+                    = new IndexWriter(directory, analyzer, true);
+            writer.SetSimilarity(similarity);
+            //writer.infoStream = System.out;
+            for (int i = 0; i < numDocs; i++)
+            {
+                Document doc = new Document();
+                doc.Add(new Field(FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+                doc.Add(new Field(MULTI_FIELD, English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+                doc.Add(new Field(NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+                writer.AddDocument(doc);
+            }
+            //writer.optimize();
+            writer.Close();
+
+            IndexSearcher searcher = new IndexSearcher(directory);
+            searcher.SetSimilarity(similarity);
+            return searcher;
+        }
+    }
+}

Modified: 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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Payloads/TestBoostingTermQuery.cs Wed Jul 29 18:04:12 2009
@@ -19,22 +19,31 @@
 
 using NUnit.Framework;
 
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using LowerCaseTokenizer = Lucene.Net.Analysis.LowerCaseTokenizer;
+using Token = Lucene.Net.Analysis.Token;
+using TokenFilter = Lucene.Net.Analysis.TokenFilter;
+using TokenStream = Lucene.Net.Analysis.TokenStream;
 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 _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 BooleanClause = Lucene.Net.Search.BooleanClause;
+using BooleanQuery = Lucene.Net.Search.BooleanQuery;
+using CheckHits = Lucene.Net.Search.CheckHits;
+using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using ScoreDoc = Lucene.Net.Search.ScoreDoc;
+using TopDocs = Lucene.Net.Search.TopDocs;
+using _Spans = Lucene.Net.Search.Spans.Spans;
 using TermSpans = Lucene.Net.Search.Spans.TermSpans;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using English = Lucene.Net.Util.English;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Search.Payloads
 {
-	
 	[TestFixture]
 	public class TestBoostingTermQuery : LuceneTestCase
 	{
@@ -111,29 +120,30 @@
 				this.fieldName = fieldName;
 			}
 			
-			public override Token Next()
+			public override Token Next(Token reusableToken)
 			{
-				Token result = input.Next();
-				if (result != null)
+                System.Diagnostics.Debug.Assert(reusableToken != null);
+				Token nextToken = input.Next(reusableToken);
+				if (nextToken != null)
 				{
 					if (fieldName.Equals("field"))
 					{
-						result.SetPayload(new Payload(Enclosing_Instance.payloadField));
+						nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadField));
 					}
 					else if (fieldName.Equals("multiField"))
 					{
 						if (numSeen % 2 == 0)
 						{
-							result.SetPayload(new Payload(Enclosing_Instance.payloadMultiField1));
+                            nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadMultiField1));
 						}
 						else
 						{
-							result.SetPayload(new Payload(Enclosing_Instance.payloadMultiField2));
+                            nextToken.SetPayload(new _Payload(Enclosing_Instance.payloadMultiField2));
 						}
 						numSeen++;
 					}
 				}
-				return result;
+				return nextToken;
 			}
 		}
 		
@@ -143,17 +153,17 @@
 			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
 			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
-			IndexWriter writer = new IndexWriter(directory, analyzer, true);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
 			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);
+				Field noPayloadField = new Field(PayloadHelper.NO_PAYLOAD_FIELD, English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED);
+				//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));
+				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+				doc.Add(new Field("multiField", English.IntToEnglish(i) + "  " + English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
 				writer.AddDocument(doc);
 			}
 			writer.Optimize();
@@ -180,7 +190,7 @@
 				ScoreDoc doc = hits.scoreDocs[i];
 				Assert.IsTrue(doc.score == 1, doc.score + " does not equal: " + 1);
 			}
-			CheckHits.CheckExplanations(query, "field", searcher, true);
+			CheckHits.CheckExplanations(query, PayloadHelper.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));
@@ -194,7 +204,7 @@
 		[Test]
 		public virtual void  TestMultipleMatchesPerDoc()
 		{
-			BoostingTermQuery query = new BoostingTermQuery(new Term("multiField", "seventy"));
+			BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.MULTI_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);
@@ -238,7 +248,7 @@
 		[Test]
 		public virtual void  TestNoMatch()
 		{
-			BoostingTermQuery query = new BoostingTermQuery(new Term("field", "junk"));
+			BoostingTermQuery query = new BoostingTermQuery(new Term(PayloadHelper.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);
@@ -247,8 +257,8 @@
 		[Test]
 		public virtual void  TestNoPayload()
 		{
-			BoostingTermQuery q1 = new BoostingTermQuery(new Term("noPayLoad", "zero"));
-			BoostingTermQuery q2 = new BoostingTermQuery(new Term("noPayLoad", "foo"));
+            BoostingTermQuery q1 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "zero"));
+            BoostingTermQuery q2 = new BoostingTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "foo"));
 			BooleanClause c1 = new BooleanClause(q1, BooleanClause.Occur.MUST);
 			BooleanClause c2 = new BooleanClause(q2, BooleanClause.Occur.MUST_NOT);
 			BooleanQuery query = new BooleanQuery();
@@ -256,10 +266,10 @@
 			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);
+			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);
+            CheckHits.CheckHitCollector(query, PayloadHelper.NO_PAYLOAD_FIELD, searcher, results);
 		}
 		
 		// must be static for weight serialization tests 

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/QueryUtils.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/QueryUtils.cs Wed Jul 29 18:04:12 2009
@@ -21,9 +21,6 @@
 
 namespace Lucene.Net.Search
 {
-	
-	/// <author>  yonik
-	/// </author>
 	public class QueryUtils
 	{
 		[Serializable]

Modified: 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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/RemoteCachingWrapperFilterHelper.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/RemoteCachingWrapperFilterHelper.cs Wed Jul 29 18:04:12 2009
@@ -27,8 +27,6 @@
 	/// <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
 	{
@@ -44,26 +42,26 @@
 		{
 			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);
-		}
-	}
+
+        public override DocIdSet GetDocIdSet(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.GetDocIdSet(reader);
+        }
+    }
 }
\ No newline at end of file

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=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/SingleDocTestFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/SingleDocTestFilter.cs Wed Jul 29 18:04:12 2009
@@ -18,8 +18,9 @@
 using System;
 
 using IndexReader = Lucene.Net.Index.IndexReader;
+using DocIdBitSet = Lucene.Net.Util.DocIdBitSet;
 
-namespace Lucene.Net.search
+namespace Lucene.Net.Search
 {
 	
 	[Serializable]
@@ -31,18 +32,31 @@
 		{
 			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);
 
-			for (int increment = 0; doc >= bits.Length; increment =+ 64)
-			{
-				bits.Length += increment;
-			}
-			bits.Set(doc, true);
-			
-			return bits;
-		}
+        public override DocIdSet GetDocIdSet(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 new DocIdBitSet(bits);
+        }
+        [System.Obsolete()]
+        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;
+        }
 	}
 }
\ 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=798995&r1=798994&r2=798995&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 Wed Jul 29 18:04:12 2009
@@ -56,12 +56,12 @@
 		{
 			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			//writer.infoStream = System.out;
 			for (int i = 0; i < 1000; i++)
 			{
 				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.TOKENIZED));
+				doc.Add(new Field("field", English.IntToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
 				writer.AddDocument(doc);
 			}
 			

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=798995&r1=798994&r2=798995&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 Wed Jul 29 18:04:12 2009
@@ -56,11 +56,11 @@
 		{
 			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			for (int i = 0; i < docFields.Length; i++)
 			{
 				Document doc = new Document();
-				doc.Add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
+				doc.Add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
 				writer.AddDocument(doc);
 			}
 			writer.Close();

Added: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestPayloadSpans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestPayloadSpans.cs?rev=798995&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestPayloadSpans.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestPayloadSpans.cs Wed Jul 29 18:04:12 2009
@@ -0,0 +1,403 @@
+/**
+ * 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 NUnit.Framework;
+
+using Analyzer = Lucene.Net.Analysis.Analyzer;
+using LowerCaseTokenizer = Lucene.Net.Analysis.LowerCaseTokenizer;
+using Token = Lucene.Net.Analysis.Token;
+using TokenFilter = Lucene.Net.Analysis.TokenFilter;
+using TokenStream = Lucene.Net.Analysis.TokenStream;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
+using IndexReader = Lucene.Net.Index.IndexReader;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using Payload = Lucene.Net.Index.Payload;
+using Term = Lucene.Net.Index.Term;
+using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Similarity = Lucene.Net.Search.Similarity;
+using TermQuery = Lucene.Net.Search.TermQuery;
+using PayloadHelper = Lucene.Net.Search.Payloads.PayloadHelper;
+using PayloadSpanUtil = Lucene.Net.Search.Payloads.PayloadSpanUtil;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+
+namespace Lucene.Net.Search.Spans
+{
+    [TestFixture]
+    public class TestPayloadSpans
+    {
+        private readonly static bool DEBUG = false;
+        private IndexSearcher searcher;
+        private Similarity similarity = new DefaultSimilarity();
+        protected IndexReader indexReader;
+
+        [SetUp]
+        protected void SetUp()
+        {
+            PayloadHelper helper = new PayloadHelper();
+            searcher = helper.SetUp(similarity, 1000);
+            indexReader = searcher.GetIndexReader();
+        }
+
+        [TearDown]
+        protected void TearDown()
+        {
+
+        }
+
+        [Test]
+        public void TestSpanTermQuery()
+        {
+            SpanTermQuery stq;
+            PayloadSpans spans;
+            stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "seventy"));
+            spans = stq.GetPayloadSpans(indexReader);
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 100, 1, 1, 1);
+
+            stq = new SpanTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "seventy"));
+            spans = stq.GetPayloadSpans(indexReader);
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 100, 0, 0, 0);
+        }
+        [Test]
+        public void TestSpanFirst()
+        {
+
+            SpanQuery match;
+            SpanFirstQuery sfq;
+            match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+            sfq = new SpanFirstQuery(match, 2);
+            PayloadSpans spans = sfq.GetPayloadSpans(indexReader);
+            CheckSpans(spans, 109, 1, 1, 1);
+            //Test more complicated subclause
+            SpanQuery[] clauses = new SpanQuery[2];
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "hundred"));
+            match = new SpanNearQuery(clauses, 0, true);
+            sfq = new SpanFirstQuery(match, 2);
+            CheckSpans(sfq.GetPayloadSpans(indexReader), 100, 2, 1, 1);
+
+            match = new SpanNearQuery(clauses, 0, false);
+            sfq = new SpanFirstQuery(match, 2);
+            CheckSpans(sfq.GetPayloadSpans(indexReader), 100, 2, 1, 1);
+
+        }
+
+        [Test]
+        public void TestNestedSpans()
+        {
+            SpanTermQuery stq;
+            PayloadSpans spans;
+            IndexSearcher searcher = GetSearcher();
+            stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "mark"));
+            spans = stq.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 0, null);
+
+
+            SpanQuery[] clauses = new SpanQuery[3];
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
+            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
+            SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 12, false);
+
+            spans = spanNearQuery.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 2, new int[] { 3, 3 });
+
+
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
+            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
+
+            spanNearQuery = new SpanNearQuery(clauses, 6, true);
+
+
+            spans = spanNearQuery.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 1, new int[] { 3 });
+
+            clauses = new SpanQuery[2];
+
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "xx"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "rr"));
+
+            spanNearQuery = new SpanNearQuery(clauses, 6, true);
+
+
+            SpanQuery[] clauses2 = new SpanQuery[2];
+
+            clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
+            clauses2[1] = spanNearQuery;
+
+            SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses2, 6, false);
+
+            spans = nestedSpanNearQuery.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 2, new int[] { 3, 3 });
+        }
+
+        public void TestFirstClauseWithoutPayload()
+        {
+            PayloadSpans spans;
+            IndexSearcher searcher = GetSearcher();
+
+            SpanQuery[] clauses = new SpanQuery[3];
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "nopayload"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "qq"));
+            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "ss"));
+
+            SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 6, true);
+
+            SpanQuery[] clauses2 = new SpanQuery[2];
+
+            clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "pp"));
+            clauses2[1] = spanNearQuery;
+
+            SpanNearQuery snq = new SpanNearQuery(clauses2, 6, false);
+
+            SpanQuery[] clauses3 = new SpanQuery[2];
+
+            clauses3[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "np"));
+            clauses3[1] = snq;
+
+            SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
+
+            spans = nestedSpanNearQuery.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 1, new int[] { 3 });
+        }
+
+        public void TestHeavilyNestedSpanQuery()
+        {
+            PayloadSpans spans;
+            IndexSearcher searcher = GetSearcher();
+
+            SpanQuery[] clauses = new SpanQuery[3];
+            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "two"));
+            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));
+
+            SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 5, true);
+
+            clauses = new SpanQuery[3];
+            clauses[0] = spanNearQuery;
+            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "five"));
+            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "six"));
+
+            SpanNearQuery spanNearQuery2 = new SpanNearQuery(clauses, 6, true);
+
+            SpanQuery[] clauses2 = new SpanQuery[2];
+            clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "eleven"));
+            clauses2[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "ten"));
+            SpanNearQuery spanNearQuery3 = new SpanNearQuery(clauses2, 2, false);
+
+            SpanQuery[] clauses3 = new SpanQuery[3];
+            clauses3[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "nine"));
+            clauses3[1] = spanNearQuery2;
+            clauses3[2] = spanNearQuery3;
+
+            SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);
+
+            spans = nestedSpanNearQuery.GetPayloadSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            CheckSpans(spans, 2, new int[] { 8, 8 });
+        }
+
+        public void TestPayloadSpanUtil()
+        {
+            RAMDirectory directory = new RAMDirectory();
+            PayloadAnalyzer analyzer = new PayloadAnalyzer();
+            string[] docs = new string[] { };
+            IndexWriter writer = new IndexWriter(directory, analyzer, true);
+            writer.SetSimilarity(similarity);
+            Document doc = new Document();
+            doc.Add(new Field(PayloadHelper.FIELD, "xx rr yy mm  pp", Field.Store.YES, Field.Index.ANALYZED));
+            writer.AddDocument(doc);
+
+            writer.Close();
+
+            IndexSearcher searcher = new IndexSearcher(directory);
+
+            IndexReader reader = searcher.GetIndexReader();
+            PayloadSpanUtil psu = new PayloadSpanUtil(reader);
+
+            System.Collections.Generic.ICollection<byte[]> payloads = psu.GetPayloadsForQuery(new TermQuery(new Term(PayloadHelper.FIELD, "rr")));
+            if (DEBUG)
+                System.Console.WriteLine("Num payloads:" + payloads.Count);
+            System.Collections.Generic.IEnumerator<byte[]> it = payloads.GetEnumerator();
+            while (it.MoveNext())
+            {
+                byte[] bytes = it.Current;
+                if (DEBUG)
+                    System.Console.WriteLine(System.Text.Encoding.Default.GetString(bytes));
+            }
+
+        }
+
+        private void CheckSpans(PayloadSpans spans, int expectedNumSpans, int expectedNumPayloads,
+                                int expectedPayloadLength, int expectedFirstByte)
+        {
+            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+            //each position match should have a span associated with it, since there is just one underlying term query, there should
+            //only be one entry in the span
+            int seen = 0;
+            while (spans.Next() == true)
+            {
+                //if we expect payloads, then isPayloadAvailable should be true
+                if (expectedNumPayloads > 0)
+                {
+                    Assert.IsTrue(spans.IsPayloadAvailable() == true, "isPayloadAvailable is not returning the correct value: " + spans.IsPayloadAvailable()
+                            + " and it should be: " + (expectedNumPayloads > 0));
+                }
+                else
+                {
+                    Assert.IsTrue(spans.IsPayloadAvailable() == false, "isPayloadAvailable should be false");
+                }
+                //See payload helper, for the PayloadHelper.FIELD field, there is a single byte payload at every token
+                if (spans.IsPayloadAvailable())
+                {
+                    System.Collections.Generic.ICollection<byte[]> payload = spans.GetPayload();
+                    Assert.IsTrue(payload.Count == expectedNumPayloads, "payload Size: " + payload.Count + " is not: " + expectedNumPayloads);
+                    for (System.Collections.Generic.IEnumerator<byte[]> iterator = payload.GetEnumerator(); iterator.MoveNext(); )
+                    {
+                        byte[] thePayload = iterator.Current;
+                        Assert.IsTrue(thePayload.Length == expectedPayloadLength, "payload[0] Size: " + thePayload.Length + " is not: " + expectedPayloadLength);
+                        Assert.IsTrue(thePayload[0] == expectedFirstByte, thePayload[0] + " does not equal: " + expectedFirstByte);
+
+                    }
+
+                }
+                seen++;
+            }
+            Assert.IsTrue(seen == expectedNumSpans, seen + " does not equal: " + expectedNumSpans);
+        }
+
+        private IndexSearcher GetSearcher()
+        {
+            RAMDirectory directory = new RAMDirectory();
+            PayloadAnalyzer analyzer = new PayloadAnalyzer();
+            string[] docs = new string[] { "xx rr yy mm  pp", "xx yy mm rr pp", "nopayload qq ss pp np", "one two three four five six seven eight nine ten eleven", "nine one two three four five six seven eight eleven ten" };
+            IndexWriter writer = new IndexWriter(directory, analyzer, true);
+
+            writer.SetSimilarity(similarity);
+
+            Document doc = null;
+            for (int i = 0; i < docs.Length; i++)
+            {
+                doc = new Document();
+                string docText = docs[i];
+                doc.Add(new Field(PayloadHelper.FIELD, docText, Field.Store.YES, Field.Index.ANALYZED));
+                writer.AddDocument(doc);
+            }
+
+            writer.Close();
+
+            IndexSearcher searcher = new IndexSearcher(directory);
+            return searcher;
+        }
+
+        private void CheckSpans(PayloadSpans spans, int numSpans, int[] numPayloads)
+        {
+            int cnt = 0;
+
+            while (spans.Next() == true)
+            {
+                if (DEBUG)
+                    System.Console.WriteLine("\nSpans Dump --");
+                if (spans.IsPayloadAvailable())
+                {
+                    System.Collections.Generic.ICollection<byte[]> payload = spans.GetPayload();
+                    if (DEBUG)
+                        System.Console.WriteLine("payloads for span:" + payload.Count);
+                    System.Collections.Generic.IEnumerator<byte[]> it = payload.GetEnumerator();
+                    while (it.MoveNext())
+                    {
+                        byte[] bytes = it.Current;
+                        if (DEBUG)
+                            System.Console.WriteLine("doc:" + spans.Doc() + " s:" + spans.Start() + " e:" + spans.End() + " "
+                              + System.Text.Encoding.Default.GetString(bytes));
+                    }
+
+                    Assert.AreEqual(numPayloads[cnt], payload.Count);
+                }
+                else
+                {
+                    Assert.IsFalse(numPayloads.Length > 0 && numPayloads[cnt] > 0, "Expected spans:" + numPayloads[cnt] + " found: 0");
+                }
+                cnt++;
+            }
+
+            Assert.AreEqual(numSpans, cnt);
+        }
+
+        class PayloadAnalyzer : Analyzer
+        {
+            override public TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
+            {
+                TokenStream result = new LowerCaseTokenizer(reader);
+                result = new PayloadFilter(result, fieldName);
+                return result;
+            }
+        }
+
+        class PayloadFilter : TokenFilter
+        {
+            string fieldName;
+            //int numSeen = 0;
+            System.Collections.Generic.Dictionary<string, string> entities = new System.Collections.Generic.Dictionary<string, string>();
+            System.Collections.Generic.Dictionary<string, string> nopayload = new System.Collections.Generic.Dictionary<string, string>();
+            int pos;
+
+            public PayloadFilter(TokenStream input, string fieldName)
+                : base(input)
+            {
+                this.fieldName = fieldName;
+                pos = 0;
+                entities["xx"] = "xx";
+                entities["one"] = "one";
+                nopayload["nopayload"] = "nopayload";
+                nopayload["np"] = "np";
+
+            }
+
+            override public Token Next()
+            {
+                Token result = input.Next();
+                if (result != null)
+                {
+                    string token = new string(result.TermBuffer(), 0, result.TermLength());
+
+                    if (!nopayload.ContainsKey(token))
+                    {
+                        if (entities.ContainsKey(token))
+                        {
+                            result.SetPayload(new Lucene.Net.Index.Payload(System.Text.Encoding.Default.GetBytes(token + ":Entity:" + pos)));
+                        }
+                        else
+                        {
+                            result.SetPayload(new Lucene.Net.Index.Payload(System.Text.Encoding.Default.GetBytes(token + ":Noise:" + pos)));
+                        }
+                    }
+                    pos += result.GetPositionIncrement();
+                }
+                return result;
+            }
+        }
+    }
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestSpans.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpans.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpans.cs Wed Jul 29 18:04:12 2009
@@ -19,261 +19,479 @@
 
 using NUnit.Framework;
 
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Query = Lucene.Net.Search.Query;
+using CheckHits = Lucene.Net.Search.CheckHits;
+using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
+using Similarity = Lucene.Net.Search.Similarity;
+using Scorer = Lucene.Net.Search.Scorer;
+using TermQuery = Lucene.Net.Search.TermQuery;
+using Searcher = Lucene.Net.Search.Searcher;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Directory = Lucene.Net.Store.Directory;
+using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
 using IndexWriter = Lucene.Net.Index.IndexWriter;
+using IndexReader = Lucene.Net.Index.IndexReader;
 using Term = Lucene.Net.Index.Term;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
-using CheckHits = Lucene.Net.Search.CheckHits;
-using IndexSearcher = Lucene.Net.Search.IndexSearcher;
-using Query = Lucene.Net.Search.Query;
+using Document = Lucene.Net.Documents.Document;
+using Field = Lucene.Net.Documents.Field;
 using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 namespace Lucene.Net.Search.Spans
 {
-	[TestFixture]
-	public class TestSpans : LuceneTestCase
-	{
-		private IndexSearcher searcher;
-		
-		public const System.String field = "field";
-		
-		[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++)
-			{
-				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-				doc.Add(new Field(field, docFields[i], Field.Store.YES, Field.Index.TOKENIZED));
-				writer.AddDocument(doc);
-			}
-			writer.Close();
-			searcher = new IndexSearcher(directory);
-			//System.out.println("set up " + getName());
-		}
-		
-		private System.String[] docFields = new System.String[]{"w1 w2 w3 w4 w5", "w1 w3 w2 w3", "w1 xx w2 yy w3", "w1 w3 xx w2 yy w3", "u2 u2 u1", "u2 xx u2 u1", "u2 u2 xx u1", "u2 xx u2 yy u1", "u2 xx u1 u2", "u2 u1 xx u2", "u1 u2 xx u2", "t1 t2 t1 t3 t2 t3"};
-		
-		public virtual SpanTermQuery MakeSpanTermQuery(System.String text)
-		{
-			return new SpanTermQuery(new Term(field, text));
-		}
-		
-		private void  CheckHits(Query query, int[] results)
-		{
-			Lucene.Net.Search.CheckHits.CheckHits_Renamed(query, field, searcher, results);
-		}
-		
-		private void  OrderedSlopTest3SQ(SpanQuery q1, SpanQuery q2, SpanQuery q3, int slop, int[] expectedDocs)
-		{
-			bool ordered = true;
-			SpanNearQuery snq = new SpanNearQuery(new SpanQuery[]{q1, q2, q3}, slop, ordered);
-			CheckHits(snq, expectedDocs);
-		}
-		
-		public virtual void  OrderedSlopTest3(int slop, int[] expectedDocs)
-		{
-			OrderedSlopTest3SQ(MakeSpanTermQuery("w1"), MakeSpanTermQuery("w2"), MakeSpanTermQuery("w3"), slop, expectedDocs);
-		}
-		
-		public virtual void  OrderedSlopTest3Equal(int slop, int[] expectedDocs)
-		{
-			OrderedSlopTest3SQ(MakeSpanTermQuery("w1"), MakeSpanTermQuery("w3"), MakeSpanTermQuery("w3"), slop, expectedDocs);
-		}
-		
-		public virtual void  OrderedSlopTest1Equal(int slop, int[] expectedDocs)
-		{
-			OrderedSlopTest3SQ(MakeSpanTermQuery("u2"), MakeSpanTermQuery("u2"), MakeSpanTermQuery("u1"), slop, expectedDocs);
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrdered01()
-		{
-			OrderedSlopTest3(0, new int[]{0});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrdered02()
-		{
-			OrderedSlopTest3(1, new int[]{0, 1});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrdered03()
-		{
-			OrderedSlopTest3(2, new int[]{0, 1, 2});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrdered04()
-		{
-			OrderedSlopTest3(3, new int[]{0, 1, 2, 3});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrdered05()
-		{
-			OrderedSlopTest3(4, new int[]{0, 1, 2, 3});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual01()
-		{
-			OrderedSlopTest3Equal(0, new int[]{});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual02()
-		{
-			OrderedSlopTest3Equal(1, new int[]{1});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual03()
-		{
-			OrderedSlopTest3Equal(2, new int[]{1});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual04()
-		{
-			OrderedSlopTest3Equal(3, new int[]{1, 3});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual11()
-		{
-			OrderedSlopTest1Equal(0, new int[]{4});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual12()
-		{
-			OrderedSlopTest1Equal(0, new int[]{4});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual13()
-		{
-			OrderedSlopTest1Equal(1, new int[]{4, 5, 6});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual14()
-		{
-			OrderedSlopTest1Equal(2, new int[]{4, 5, 6, 7});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedEqual15()
-		{
-			OrderedSlopTest1Equal(3, new int[]{4, 5, 6, 7});
-		}
-		
-		[Test]
-		public virtual void  TestSpanNearOrderedOverlap()
-		{
-			bool ordered = true;
-			int slop = 1;
-			SpanNearQuery snq = new SpanNearQuery(new SpanQuery[]{MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2"), MakeSpanTermQuery("t3")}, slop, ordered);
-			Spans spans = snq.GetSpans(searcher.GetIndexReader());
-			
-			Assert.IsTrue(spans.Next(), "first range");
-			Assert.AreEqual(11, spans.Doc(), "first doc");
-			Assert.AreEqual(0, spans.Start(), "first start");
-			Assert.AreEqual(4, spans.End(), "first end");
-			
-			Assert.IsTrue(spans.Next(), "second range");
-			Assert.AreEqual(11, spans.Doc(), "second doc");
-			Assert.AreEqual(2, spans.Start(), "second start");
-			Assert.AreEqual(6, spans.End(), "second end");
-			
-			Assert.IsFalse(spans.Next(), "third range");
-		}
-		
-		
-		private Spans OrSpans(System.String[] terms)
-		{
-			SpanQuery[] sqa = new SpanQuery[terms.Length];
-			for (int i = 0; i < terms.Length; i++)
-			{
-				sqa[i] = MakeSpanTermQuery(terms[i]);
-			}
-			return (new SpanOrQuery(sqa)).GetSpans(searcher.GetIndexReader());
-		}
-		
-		private void  TstNextSpans(Spans spans, int doc, int start, int end)
-		{
-			Assert.IsTrue(spans.Next(), "next");
-			Assert.AreEqual(doc, spans.Doc(), "doc");
-			Assert.AreEqual(start, spans.Start(), "start");
-			Assert.AreEqual(end, spans.End(), "end");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrEmpty()
-		{
-			Spans spans = OrSpans(new System.String[0]);
-			Assert.IsFalse(spans.Next(), "empty next");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrSingle()
-		{
-			Spans spans = OrSpans(new System.String[]{"w5"});
-			TstNextSpans(spans, 0, 4, 5);
-			Assert.IsFalse(spans.Next(), "final next");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrDouble()
-		{
-			Spans spans = OrSpans(new System.String[]{"w5", "yy"});
-			TstNextSpans(spans, 0, 4, 5);
-			TstNextSpans(spans, 2, 3, 4);
-			TstNextSpans(spans, 3, 4, 5);
-			TstNextSpans(spans, 7, 3, 4);
-			Assert.IsFalse(spans.Next(), "final next");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrDoubleSkip()
-		{
-			Spans spans = OrSpans(new System.String[]{"w5", "yy"});
-			Assert.IsTrue(spans.SkipTo(3), "initial skipTo");
-			Assert.AreEqual(3, spans.Doc(), "doc");
-			Assert.AreEqual(4, spans.Start(), "start");
-			Assert.AreEqual(5, spans.End(), "end");
-			TstNextSpans(spans, 7, 3, 4);
-			Assert.IsFalse(spans.Next(), "final next");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrUnused()
-		{
-			Spans spans = OrSpans(new System.String[]{"w5", "unusedTerm", "yy"});
-			TstNextSpans(spans, 0, 4, 5);
-			TstNextSpans(spans, 2, 3, 4);
-			TstNextSpans(spans, 3, 4, 5);
-			TstNextSpans(spans, 7, 3, 4);
-			Assert.IsFalse(spans.Next(), "final next");
-		}
-		
-		[Test]
-		public virtual void  TestSpanOrTripleSameDoc()
-		{
-			Spans spans = OrSpans(new System.String[]{"t1", "t2", "t3"});
-			TstNextSpans(spans, 11, 0, 1);
-			TstNextSpans(spans, 11, 1, 2);
-			TstNextSpans(spans, 11, 2, 3);
-			TstNextSpans(spans, 11, 3, 4);
-			TstNextSpans(spans, 11, 4, 5);
-			TstNextSpans(spans, 11, 5, 6);
-			Assert.IsFalse(spans.Next(), "final next");
-		}
-	}
+    [TestFixture]
+    public class TestSpans : LuceneTestCase
+    {
+        private IndexSearcher searcher;
+
+        public const System.String field = "field";
+
+        [SetUp]
+        public override void SetUp()
+        {
+            base.SetUp();
+            RAMDirectory directory = new RAMDirectory();
+            IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
+            for (int i = 0; i < docFields.Length; i++)
+            {
+                Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
+                doc.Add(new Field(field, docFields[i], Field.Store.YES, Field.Index.ANALYZED));
+                writer.AddDocument(doc);
+            }
+            writer.Close();
+            searcher = new IndexSearcher(directory);
+            //System.out.println("set up " + getName());
+        }
+
+        private System.String[] docFields = new System.String[] { "w1 w2 w3 w4 w5", "w1 w3 w2 w3", "w1 xx w2 yy w3", "w1 w3 xx w2 yy w3", "u2 u2 u1", "u2 xx u2 u1", "u2 u2 xx u1", "u2 xx u2 yy u1", "u2 xx u1 u2", "u2 u1 xx u2", "u1 u2 xx u2", "t1 t2 t1 t3 t2 t3" };
+
+        public virtual SpanTermQuery MakeSpanTermQuery(System.String text)
+        {
+            return new SpanTermQuery(new Term(field, text));
+        }
+
+        private void CheckHits(Query query, int[] results)
+        {
+            Lucene.Net.Search.CheckHits.CheckHits_Renamed(query, field, searcher, results);
+        }
+
+        private void OrderedSlopTest3SQ(SpanQuery q1, SpanQuery q2, SpanQuery q3, int slop, int[] expectedDocs)
+        {
+            bool ordered = true;
+            SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { q1, q2, q3 }, slop, ordered);
+            CheckHits(snq, expectedDocs);
+        }
+
+        public virtual void OrderedSlopTest3(int slop, int[] expectedDocs)
+        {
+            OrderedSlopTest3SQ(MakeSpanTermQuery("w1"), MakeSpanTermQuery("w2"), MakeSpanTermQuery("w3"), slop, expectedDocs);
+        }
+
+        public virtual void OrderedSlopTest3Equal(int slop, int[] expectedDocs)
+        {
+            OrderedSlopTest3SQ(MakeSpanTermQuery("w1"), MakeSpanTermQuery("w3"), MakeSpanTermQuery("w3"), slop, expectedDocs);
+        }
+
+        public virtual void OrderedSlopTest1Equal(int slop, int[] expectedDocs)
+        {
+            OrderedSlopTest3SQ(MakeSpanTermQuery("u2"), MakeSpanTermQuery("u2"), MakeSpanTermQuery("u1"), slop, expectedDocs);
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrdered01()
+        {
+            OrderedSlopTest3(0, new int[] { 0 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrdered02()
+        {
+            OrderedSlopTest3(1, new int[] { 0, 1 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrdered03()
+        {
+            OrderedSlopTest3(2, new int[] { 0, 1, 2 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrdered04()
+        {
+            OrderedSlopTest3(3, new int[] { 0, 1, 2, 3 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrdered05()
+        {
+            OrderedSlopTest3(4, new int[] { 0, 1, 2, 3 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual01()
+        {
+            OrderedSlopTest3Equal(0, new int[] { });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual02()
+        {
+            OrderedSlopTest3Equal(1, new int[] { 1 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual03()
+        {
+            OrderedSlopTest3Equal(2, new int[] { 1 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual04()
+        {
+            OrderedSlopTest3Equal(3, new int[] { 1, 3 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual11()
+        {
+            OrderedSlopTest1Equal(0, new int[] { 4 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual12()
+        {
+            OrderedSlopTest1Equal(0, new int[] { 4 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual13()
+        {
+            OrderedSlopTest1Equal(1, new int[] { 4, 5, 6 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual14()
+        {
+            OrderedSlopTest1Equal(2, new int[] { 4, 5, 6, 7 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedEqual15()
+        {
+            OrderedSlopTest1Equal(3, new int[] { 4, 5, 6, 7 });
+        }
+
+        [Test]
+        public virtual void TestSpanNearOrderedOverlap()
+        {
+            bool ordered = true;
+            int slop = 1;
+            SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2"), MakeSpanTermQuery("t3") }, slop, ordered);
+            Spans spans = snq.GetSpans(searcher.GetIndexReader());
+
+            Assert.IsTrue(spans.Next(), "first range");
+            Assert.AreEqual(11, spans.Doc(), "first doc");
+            Assert.AreEqual(0, spans.Start(), "first start");
+            Assert.AreEqual(4, spans.End(), "first end");
+
+            Assert.IsTrue(spans.Next(), "second range");
+            Assert.AreEqual(11, spans.Doc(), "second doc");
+            Assert.AreEqual(2, spans.Start(), "second start");
+            Assert.AreEqual(6, spans.End(), "second end");
+
+            Assert.IsFalse(spans.Next(), "third range");
+        }
+
+        [Test]
+        public void TestSpanNearUnOrdered()
+        {
+
+            //See http://www.gossamer-threads.com/lists/lucene/java-dev/52270 for discussion about this test
+            SpanNearQuery snq;
+            snq = new SpanNearQuery(
+                                      new SpanQuery[] {
+                                MakeSpanTermQuery("u1"),
+                                MakeSpanTermQuery("u2") },
+                                      0,
+                                      false);
+            Spans spans = snq.GetSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(4, spans.Doc(), "doc");
+            Assert.AreEqual(1, spans.Start(), "start");
+            Assert.AreEqual(3, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(5, spans.Doc(), "doc");
+            Assert.AreEqual(2, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(8, spans.Doc(), "doc");
+            Assert.AreEqual(2, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(9, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(2, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(10, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(2, spans.End(), "end");
+            Assert.IsTrue(spans.Next() == false, "Has next and it shouldn't: " + spans.Doc());
+
+            SpanNearQuery u1u2 = new SpanNearQuery(new SpanQuery[]{MakeSpanTermQuery("u1"),
+                                MakeSpanTermQuery("u2")}, 0, false);
+            snq = new SpanNearQuery(
+                                      new SpanQuery[] {
+                                u1u2,
+                                MakeSpanTermQuery("u2")
+                              },
+                                      1,
+                                      false);
+            spans = snq.GetSpans(searcher.GetIndexReader());
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(4, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(3, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            //unordered spans can be subsets
+            Assert.AreEqual(4, spans.Doc(), "doc");
+            Assert.AreEqual(1, spans.Start(), "start");
+            Assert.AreEqual(3, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(5, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(5, spans.Doc(), "doc");
+            Assert.AreEqual(2, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(8, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(8, spans.Doc(), "doc");
+            Assert.AreEqual(2, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(9, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(2, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(9, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(4, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next(), "Does not have next and it should");
+            Assert.AreEqual(10, spans.Doc(), "doc");
+            Assert.AreEqual(0, spans.Start(), "start");
+            Assert.AreEqual(2, spans.End(), "end");
+
+            Assert.IsTrue(spans.Next() == false, "Has next and it shouldn't");
+        }
+
+        private Spans OrSpans(System.String[] terms)
+        {
+            SpanQuery[] sqa = new SpanQuery[terms.Length];
+            for (int i = 0; i < terms.Length; i++)
+            {
+                sqa[i] = MakeSpanTermQuery(terms[i]);
+            }
+            return (new SpanOrQuery(sqa)).GetSpans(searcher.GetIndexReader());
+        }
+
+        private void TstNextSpans(Spans spans, int doc, int start, int end)
+        {
+            Assert.IsTrue(spans.Next(), "next");
+            Assert.AreEqual(doc, spans.Doc(), "doc");
+            Assert.AreEqual(start, spans.Start(), "start");
+            Assert.AreEqual(end, spans.End(), "end");
+        }
+
+        [Test]
+        public virtual void TestSpanOrEmpty()
+        {
+            Spans spans = OrSpans(new System.String[0]);
+            Assert.IsFalse(spans.Next(), "empty next");
+        }
+
+        [Test]
+        public virtual void TestSpanOrSingle()
+        {
+            Spans spans = OrSpans(new System.String[] { "w5" });
+            TstNextSpans(spans, 0, 4, 5);
+            Assert.IsFalse(spans.Next(), "final next");
+        }
+
+        [Test]
+        public virtual void TestSpanOrDouble()
+        {
+            Spans spans = OrSpans(new System.String[] { "w5", "yy" });
+            TstNextSpans(spans, 0, 4, 5);
+            TstNextSpans(spans, 2, 3, 4);
+            TstNextSpans(spans, 3, 4, 5);
+            TstNextSpans(spans, 7, 3, 4);
+            Assert.IsFalse(spans.Next(), "final next");
+        }
+
+        [Test]
+        public virtual void TestSpanOrDoubleSkip()
+        {
+            Spans spans = OrSpans(new System.String[] { "w5", "yy" });
+            Assert.IsTrue(spans.SkipTo(3), "initial skipTo");
+            Assert.AreEqual(3, spans.Doc(), "doc");
+            Assert.AreEqual(4, spans.Start(), "start");
+            Assert.AreEqual(5, spans.End(), "end");
+            TstNextSpans(spans, 7, 3, 4);
+            Assert.IsFalse(spans.Next(), "final next");
+        }
+
+        [Test]
+        public virtual void TestSpanOrUnused()
+        {
+            Spans spans = OrSpans(new System.String[] { "w5", "unusedTerm", "yy" });
+            TstNextSpans(spans, 0, 4, 5);
+            TstNextSpans(spans, 2, 3, 4);
+            TstNextSpans(spans, 3, 4, 5);
+            TstNextSpans(spans, 7, 3, 4);
+            Assert.IsFalse(spans.Next(), "final next");
+        }
+
+        [Test]
+        public virtual void TestSpanOrTripleSameDoc()
+        {
+            Spans spans = OrSpans(new System.String[] { "t1", "t2", "t3" });
+            TstNextSpans(spans, 11, 0, 1);
+            TstNextSpans(spans, 11, 1, 2);
+            TstNextSpans(spans, 11, 2, 3);
+            TstNextSpans(spans, 11, 3, 4);
+            TstNextSpans(spans, 11, 4, 5);
+            TstNextSpans(spans, 11, 5, 6);
+            Assert.IsFalse(spans.Next(), "final next");
+        }
+
+        class AnonymousSimilarity : DefaultSimilarity
+        {
+            override public float SloppyFreq(int distance)
+            {
+                return 0.0f;
+            }
+        }
+
+        class AnonymousSpanNearQuery : SpanNearQuery
+        {
+            private Similarity sim;
+
+            public AnonymousSpanNearQuery(SpanQuery[] clauses, int slop, bool inOrder, Similarity sim)
+                : base(clauses, slop, inOrder)
+            {
+                this.sim = sim;
+            }
+
+            override public Similarity GetSimilarity(Searcher s)
+            {
+                return sim;
+            }
+        }
+
+        [Test]
+        public void TestSpanScorerZeroSloppyFreq()
+        {
+            bool ordered = true;
+            int slop = 1;
+
+            Similarity sim = new AnonymousSimilarity();
+
+            SpanNearQuery snq = new AnonymousSpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2") }, slop, ordered, sim);
+
+            Scorer spanScorer = snq.Weight(searcher).Scorer(searcher.GetIndexReader());
+
+            Assert.IsTrue(spanScorer.Next(), "first doc");
+            Assert.AreEqual(spanScorer.Doc(), 11, "first doc number");
+            float score = spanScorer.Score();
+            Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score);
+            Assert.IsTrue(!spanScorer.Next(), "no second doc");
+        }
+
+
+
+        // LUCENE-1404
+        private void AddDoc(IndexWriter writer, String id, String text)
+        {
+            Document doc = new Document();
+            doc.Add(new Field("id", id, Field.Store.YES, Field.Index.UN_TOKENIZED));
+            doc.Add(new Field("text", text, Field.Store.YES, Field.Index.TOKENIZED));
+            writer.AddDocument(doc);
+        }
+
+        // LUCENE-1404
+        private int HitCount(Searcher searcher, String word)
+        {
+            return searcher.Search(new TermQuery(new Term("text", word)), 10).totalHits;
+        }
+
+        // LUCENE-1404
+        private SpanQuery CreateSpan(String value)
+        {
+            return new SpanTermQuery(new Term("text", value));
+        }
+
+        // LUCENE-1404
+        private SpanQuery CreateSpan(int slop, bool ordered, SpanQuery[] clauses)
+        {
+            return new SpanNearQuery(clauses, slop, ordered);
+        }
+
+        // LUCENE-1404
+        private SpanQuery CreateSpan(int slop, bool ordered, String term1, String term2)
+        {
+            return CreateSpan(slop, ordered, new SpanQuery[] { CreateSpan(term1), CreateSpan(term2) });
+        }
+
+        // LUCENE-1404
+        [Test]
+        public void TestNPESpanQuery()
+        {
+            Directory dir = new MockRAMDirectory();
+            IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(new String[0]), IndexWriter.MaxFieldLength.LIMITED);
+
+            // Add documents
+            AddDoc(writer, "1", "the big dogs went running to the market");
+            AddDoc(writer, "2", "the cat chased the mouse, then the cat ate the mouse quickly");
+
+            // Commit
+            writer.Close();
+
+            // Get searcher
+            IndexReader reader = IndexReader.Open(dir);
+            IndexSearcher searcher = new IndexSearcher(reader);
+
+            // Control (make sure docs indexed)
+            Assert.AreEqual(2, HitCount(searcher, "the"));
+            Assert.AreEqual(1, HitCount(searcher, "cat"));
+            Assert.AreEqual(1, HitCount(searcher, "dogs"));
+            Assert.AreEqual(0, HitCount(searcher, "rabbit"));
+
+            // This throws exception (it shouldn't)
+            Assert.AreEqual(1,
+                         searcher.Search(CreateSpan(0, true,
+                                                    new SpanQuery[] {CreateSpan(4, false, "chased", "cat"),
+                                                             CreateSpan("ate")}), 10).totalHits);
+            reader.Close();
+            dir.Close();
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestSpansAdvanced.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced.cs Wed Jul 29 18:04:12 2009
@@ -62,7 +62,7 @@
 			
 			// create test index
 			mDirectory = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			AddDocument(writer, "1", "I think it should work.");
 			AddDocument(writer, "2", "I think it should work.");
 			AddDocument(writer, "3", "I think it should work.");
@@ -94,8 +94,8 @@
 		{
 			
 			Lucene.Net.Documents.Document document = new Lucene.Net.Documents.Document();
-			document.Add(new Field(FIELD_ID, id, Field.Store.YES, Field.Index.UN_TOKENIZED));
-			document.Add(new Field(FIELD_TEXT, text, Field.Store.YES, Field.Index.TOKENIZED));
+			document.Add(new Field(FIELD_ID, id, Field.Store.YES, Field.Index.NOT_ANALYZED));
+			document.Add(new Field(FIELD_TEXT, text, Field.Store.YES, Field.Index.ANALYZED));
 			writer.AddDocument(document);
 		}
 		

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced2.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestSpansAdvanced2.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced2.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpansAdvanced2.cs Wed Jul 29 18:04:12 2009
@@ -47,10 +47,10 @@
 			base.SetUp();
 			
 			// create test index
-			IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), false);
+			IndexWriter writer = new IndexWriter(mDirectory, new StandardAnalyzer(), false, IndexWriter.MaxFieldLength.LIMITED);
 			AddDocument(writer, "A", "Should we, could we, would we?");
-			AddDocument(writer, "B", "it should.  Should it?");
-			AddDocument(writer, "C", "it shouldn't.");
+			AddDocument(writer, "B", "It should.  Should it?");
+			AddDocument(writer, "C", "It shouldn't.");
 			AddDocument(writer, "D", "Should we, should we, should we.");
 			writer.Close();
 			

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBoolean2.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBoolean2.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestBoolean2.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBoolean2.cs Wed Jul 29 18:04:12 2009
@@ -73,11 +73,11 @@
 		{
 			base.SetUp();
 			RAMDirectory directory = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			for (int i = 0; i < docFields.Length; i++)
 			{
 				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-				doc.Add(new Field(field, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
+				doc.Add(new Field(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
 				writer.AddDocument(doc);
 			}
 			writer.Close();
@@ -100,11 +100,11 @@
 			{
 				Query query1 = MakeQuery(queryText);
 				BooleanQuery.SetAllowDocsOutOfOrder(true);
-				Hits hits1 = searcher.Search(query1);
+				ScoreDoc[] hits1 = searcher.Search(query1, null, 1000).scoreDocs;
 				
 				Query query2 = MakeQuery(queryText); // there should be no need to parse again...
 				BooleanQuery.SetAllowDocsOutOfOrder(false);
-				Hits hits2 = searcher.Search(query2);
+                ScoreDoc[] hits2 = searcher.Search(query2, null, 1000).scoreDocs;
 				
 				CheckHits.CheckHitsQuery(query2, hits1, hits2, expDocNrs);
 			}
@@ -221,16 +221,12 @@
 					BooleanQuery.SetAllowDocsOutOfOrder(false);
 					
 					QueryUtils.Check(q1, searcher);
-					
-					Hits hits1 = searcher.Search(q1, sort);
-					if (hits1.Length() > 0)
-						hits1.Id(hits1.Length() - 1);
+
+                    ScoreDoc[] hits1 = searcher.Search(q1, null, 1000, sort).scoreDocs;
 					
 					BooleanQuery.SetAllowDocsOutOfOrder(true);
-					Hits hits2 = searcher.Search(q1, sort);
-					if (hits2.Length() > 0)
-						hits2.Id(hits1.Length() - 1);
-					tot += hits2.Length();
+                    ScoreDoc[] hits2 = searcher.Search(q1, null, 1000, sort).scoreDocs;
+					tot += hits2.Length;
 					CheckHits.CheckEqual(q1, hits1, hits2);
 				}
 			}

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBooleanMinShouldMatch.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanMinShouldMatch.cs Wed Jul 29 18:04:12 2009
@@ -89,16 +89,16 @@
 			System.String[] data = new System.String[]{"A 1 2 3 4 5 6", "Z       4 5 6", null, "B   2   4 5 6", "Y     3   5 6", null, "C     3     6", "X       4 5 6"};
 			
 			index = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(index, new WhitespaceAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(index, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			for (int i = 0; i < data.Length; i++)
 			{
 				Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-				doc.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("id",String.valueOf(i)));
-				doc.Add(new Field("all", "all", Field.Store.YES, Field.Index.UN_TOKENIZED)); //Field.Keyword("all","all"));
+				doc.Add(new Field("id", System.Convert.ToString(i), Field.Store.YES, Field.Index.NOT_ANALYZED)); //Field.Keyword("id",String.valueOf(i)));
+				doc.Add(new Field("all", "all", Field.Store.YES, Field.Index.NOT_ANALYZED)); //Field.Keyword("all","all"));
 				if (null != data[i])
 				{
-					doc.Add(new Field("data", data[i], Field.Store.YES, Field.Index.TOKENIZED)); //Field.Text("data",data[i]));
+					doc.Add(new Field("data", data[i], Field.Store.YES, Field.Index.ANALYZED)); //Field.Text("data",data[i]));
 				}
 				writer.AddDocument(doc);
 			}
@@ -114,12 +114,12 @@
 		
 		public virtual void  VerifyNrHits(Query q, int expected)
 		{
-			Hits h = s.Search(q);
-			if (expected != h.Length())
+			ScoreDoc[] h = s.Search(q, null, 1000).scoreDocs;
+			if (expected != h.Length)
 			{
-				PrintHits("TestBooleanMinShouldMatch", h);  // PrintHits(TestCase.GetName(), h);    // {{Aroush-1.9}} 'GetName()' gives us the name of the test in JUnit, how is it done in NUnit?
+				PrintHits("TestBooleanMinShouldMatch", h, s);  // PrintHits(TestCase.GetName(), h);    // {{Aroush-1.9}} 'GetName()' gives us the name of the test in JUnit, how is it done in NUnit?
 			}
-			Assert.AreEqual(expected, h.Length(), "result count");
+			Assert.AreEqual(expected, h.Length, "result count");
 			QueryUtils.Check(q, s);
 		}
 		
@@ -342,8 +342,21 @@
 			
 			VerifyNrHits(q, 0);
 		}
-		
-		[Test]
+
+        [Test]
+        public virtual void TestNoOptionalButMin2()
+        {
+
+            /* one required, no optional */
+            BooleanQuery q = new BooleanQuery();
+            q.Add(new TermQuery(new Term("all", "all")), BooleanClause.Occur.MUST); //true,  false);
+
+            q.SetMinimumNumberShouldMatch(1); // 1 of 0 optional 
+
+            VerifyNrHits(q, 0);
+        }
+
+        [Test]
 		public virtual void  TestRandomQueries()
 		{
 			System.Random rnd = new System.Random((System.Int32) 0);
@@ -416,15 +429,15 @@
 		
 		
 		
-		protected internal virtual void  PrintHits(System.String test, Hits h)
+		protected internal virtual void  PrintHits(System.String test, ScoreDoc[] h, Searcher searcher)
 		{
 			
 			System.Console.Error.WriteLine("------- " + test + " -------");
 			
-			for (int i = 0; i < h.Length(); i++)
+			for (int i = 0; i < h.Length; i++)
 			{
-				Lucene.Net.Documents.Document d = h.Doc(i);
-				float score = h.Score(i);
+				Lucene.Net.Documents.Document d = searcher.Doc(h[i].doc);
+                float score = h[i].score;
 				System.Console.Error.WriteLine("#" + i + ": {0.000000}" + score + " - " + d.Get("id") + " - " + d.Get("data"));
 			}
 		}

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanOr.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBooleanOr.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanOr.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanOr.cs Wed Jul 29 18:04:12 2009
@@ -33,8 +33,6 @@
 	/// <summary> Created on 2005. 2. 9.
 	/// <br>Adapted to Lucene testcase by Paul Elschot.
 	/// </summary>
-	/// <author>  appler@gmail.com
-	/// </author>
 	[TestFixture]
 	public class TestBooleanOr : LuceneTestCase
 	{
@@ -52,8 +50,8 @@
 		private int Search(Query q)
 		{
 			QueryUtils.Check(q, searcher);
-			return searcher.Search(q).Length();
-		}
+            return searcher.Search(q, null, 1000).totalHits;
+        }
 		
 		[Test]
 		public virtual void  TestElements()
@@ -150,12 +148,12 @@
 			RAMDirectory rd = new RAMDirectory();
 			
 			//
-			IndexWriter writer = new IndexWriter(rd, new StandardAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(rd, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			
 			//
 			Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
-			d.Add(new Field(FIELD_T, "Optimize not deleting all files", Field.Store.YES, Field.Index.TOKENIZED));
-			d.Add(new Field(FIELD_C, "Deleted When I run an optimize in our production environment.", Field.Store.YES, Field.Index.TOKENIZED));
+			d.Add(new Field(FIELD_T, "Optimize not deleting all files", Field.Store.YES, Field.Index.ANALYZED));
+			d.Add(new Field(FIELD_C, "Deleted When I run an optimize in our production environment.", Field.Store.YES, Field.Index.ANALYZED));
 			
 			//
 			writer.AddDocument(d);

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanPrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBooleanPrefixQuery.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanPrefixQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanPrefixQuery.cs Wed Jul 29 18:04:12 2009
@@ -65,11 +65,11 @@
 			Query rw2 = null;
 			try
 			{
-				IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+				IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 				for (int i = 0; i < categories.Length; 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));
+					doc.Add(new Field("category", categories[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
 					writer.AddDocument(doc);
 				}
 				writer.Close();

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestBooleanScorer.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestBooleanScorer.cs Wed Jul 29 18:04:12 2009
@@ -52,26 +52,26 @@
 			
 			try
 			{
-				IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
+				IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 				for (int i = 0; i < values.Length; i++)
 				{
 					Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
-					doc.Add(new Field(FIELD, values[i], Field.Store.YES, Field.Index.UN_TOKENIZED));
+					doc.Add(new Field(FIELD, values[i], Field.Store.YES, Field.Index.NOT_ANALYZED));
 					writer.AddDocument(doc);
 				}
 				writer.Close();
 				
-				BooleanQuery booleanQuery1 = new BooleanQuery();
-				booleanQuery1.Add(new TermQuery(new Term(FIELD, "1")), BooleanClause.Occur.SHOULD);
-				booleanQuery1.Add(new TermQuery(new Term(FIELD, "2")), BooleanClause.Occur.SHOULD);
+				BooleanQuery boolQuery1 = new BooleanQuery();
+				boolQuery1.Add(new TermQuery(new Term(FIELD, "1")), BooleanClause.Occur.SHOULD);
+				boolQuery1.Add(new TermQuery(new Term(FIELD, "2")), BooleanClause.Occur.SHOULD);
 				
 				BooleanQuery query = new BooleanQuery();
-				query.Add(booleanQuery1, BooleanClause.Occur.MUST);
+				query.Add(boolQuery1, BooleanClause.Occur.MUST);
 				query.Add(new TermQuery(new Term(FIELD, "9")), BooleanClause.Occur.MUST_NOT);
 				
 				IndexSearcher indexSearcher = new IndexSearcher(directory);
-				Hits hits = indexSearcher.Search(query);
-				Assert.AreEqual(2, hits.Length(), "Number of matched documents");
+				ScoreDoc[] hits = indexSearcher.Search(query, null, 1000).scoreDocs;
+				Assert.AreEqual(2, hits.Length, "Number of matched documents");
 			}
 			catch (System.IO.IOException e)
 			{

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/TestCachingWrapperFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/TestCachingWrapperFilter.cs?rev=798995&r1=798994&r2=798995&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/TestCachingWrapperFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/TestCachingWrapperFilter.cs Wed Jul 29 18:04:12 2009
@@ -35,7 +35,7 @@
 		public virtual void  TestCachingWorks()
 		{
 			Directory dir = new RAMDirectory();
-			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true);
+			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
 			writer.Close();
 			
 			IndexReader reader = IndexReader.Open(dir);
@@ -44,12 +44,12 @@
 			CachingWrapperFilter cacher = new CachingWrapperFilter(filter);
 			
 			// first time, nested filter is called
-			cacher.Bits(reader);
+			cacher.GetDocIdSet(reader);
 			Assert.IsTrue(filter.WasCalled(), "first time");
 			
 			// second time, nested filter should not be called
 			filter.Clear();
-			cacher.Bits(reader);
+            cacher.GetDocIdSet(reader);
 			Assert.IsFalse(filter.WasCalled(), "second time");
 			
 			reader.Close();



Mime
View raw message