lucene-lucene-net-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r832486 [18/29] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Document/ Lucene.Net/Index/ Lucene.Net/Search/ Lucene...
Date Tue, 03 Nov 2009 18:06:38 GMT
Modified: 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=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestPayloadSpans.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestPayloadSpans.cs Tue Nov  3 18:06:27 2009
@@ -1,12 +1,13 @@
-/**
- * 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
- *
+/* 
+ * 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.
@@ -14,390 +15,609 @@
  * limitations under the License.
  */
 
+using System;
+
 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 PayloadAttribute = Lucene.Net.Analysis.Tokenattributes.PayloadAttribute;
+using PositionIncrementAttribute = Lucene.Net.Analysis.Tokenattributes.PositionIncrementAttribute;
+using TermAttribute = Lucene.Net.Analysis.Tokenattributes.TermAttribute;
 using Document = Lucene.Net.Documents.Document;
 using Field = Lucene.Net.Documents.Field;
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
 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 LockObtainFailedException = Lucene.Net.Store.LockObtainFailedException;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 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 TopDocs = Lucene.Net.Search.TopDocs;
 using PayloadHelper = Lucene.Net.Search.Payloads.PayloadHelper;
 using PayloadSpanUtil = Lucene.Net.Search.Payloads.PayloadSpanUtil;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using LuceneTestCase = Lucene.Net.Util.LuceneTestCase;
 
 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);
-
-        }
+	public class TestPayloadSpans:LuceneTestCase
+	{
+		private const bool DEBUG = true;
+		private IndexSearcher searcher;
+		private Similarity similarity = new DefaultSimilarity();
+		protected internal IndexReader indexReader;
+		
+		public TestPayloadSpans(System.String s):base(s)
+		{
+		}
+		
+		[SetUp]
+		public override void  SetUp()
+		{
+			base.SetUp();
+			PayloadHelper helper = new PayloadHelper();
+			searcher = helper.SetUp(similarity, 1000);
+			indexReader = searcher.GetIndexReader();
+		}
+		
+		[Test]
+		public virtual void  TestSpanTermQuery()
+		{
+			SpanTermQuery stq;
+			Spans spans;
+			stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "seventy"));
+			spans = stq.GetSpans(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.GetSpans(indexReader);
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			CheckSpans(spans, 100, 0, 0, 0);
+		}
+		
+		[Test]
+		public virtual void  TestSpanFirst()
+		{
+			
+			SpanQuery match;
+			SpanFirstQuery sfq;
+			match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+			sfq = new SpanFirstQuery(match, 2);
+			Spans spans = sfq.GetSpans(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.GetSpans(indexReader), 100, 2, 1, 1);
+			
+			match = new SpanNearQuery(clauses, 0, false);
+			sfq = new SpanFirstQuery(match, 2);
+			CheckSpans(sfq.GetSpans(indexReader), 100, 2, 1, 1);
+		}
+		
+		[Test]
+		public virtual void  TestSpanNot()
+		{
+			SpanQuery[] clauses = new SpanQuery[2];
+			clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
+			clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));
+			SpanQuery spq = new SpanNearQuery(clauses, 5, true);
+			SpanNotQuery snq = new SpanNotQuery(spq, new SpanTermQuery(new Term(PayloadHelper.FIELD, "two")));
+			CheckSpans(snq.GetSpans(GetSpanNotSearcher().GetIndexReader()), 1, new int[]{2});
+		}
+		
+		public virtual IndexSearcher GetSpanNotSearcher()
+		{
+			RAMDirectory directory = new RAMDirectory();
+			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
+			IndexWriter writer = new IndexWriter(directory, analyzer, true);
+			writer.SetSimilarity(similarity);
+			
+			Document doc = new Document();
+			doc.Add(new Field(PayloadHelper.FIELD, "one two three one four three", Field.Store.YES, Field.Index.ANALYZED));
+			writer.AddDocument(doc);
+			
+			writer.Close();
+			
+			IndexSearcher searcher = new IndexSearcher(directory);
+			searcher.SetSimilarity(similarity);
+			return searcher;
+		}
+		
+		[Test]
+		public virtual void  TestNestedSpans()
+		{
+			SpanTermQuery stq;
+			Spans spans;
+			IndexSearcher searcher = GetSearcher();
+			stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "mark"));
+			spans = stq.GetSpans(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.GetSpans(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.GetSpans(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);
+			
+			// xx within 6 of rr
+			
+			SpanQuery[] clauses2 = new SpanQuery[2];
+			
+			clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "yy"));
+			clauses2[1] = spanNearQuery;
+			
+			SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses2, 6, false);
+			
+			// yy within 6 of xx within 6 of rr
+			
+			spans = nestedSpanNearQuery.GetSpans(searcher.GetIndexReader());
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			CheckSpans(spans, 2, new int[]{3, 3});
+		}
+		
+		[Test]
+		public virtual void  TestFirstClauseWithoutPayload()
+		{
+			Spans 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.GetSpans(searcher.GetIndexReader());
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			CheckSpans(spans, 1, new int[]{3});
+		}
+		
+		[Test]
+		public virtual void  TestHeavilyNestedSpanQuery()
+		{
+			Spans 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.GetSpans(searcher.GetIndexReader());
+			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
+			CheckSpans(spans, 2, new int[]{8, 8});
+		}
+		
+		[Test]
+		public virtual void  TestShrinkToAfterShortestMatch()
+		{
+			RAMDirectory directory = new RAMDirectory();
+			IndexWriter writer = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
+			Document doc = new Document();
+			doc.Add(new Field("content", new System.IO.StreamReader("a b c d e f g h i j a k")));
+			writer.AddDocument(doc);
+			writer.Close();
+			
+			IndexSearcher is_Renamed = new IndexSearcher(directory);
+			
+			SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
+			SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
+			SpanQuery[] sqs = new SpanQuery[]{stq1, stq2};
+			SpanNearQuery snq = new SpanNearQuery(sqs, 1, true);
+			Spans spans = snq.GetSpans(is_Renamed.GetIndexReader());
+			
+			TopDocs topDocs = is_Renamed.Search(snq, 1);
+			System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
+			for (int i = 0; i < topDocs.scoreDocs.Length; i++)
+			{
+				while (spans.Next())
+				{
+					System.Collections.ICollection payloads = spans.GetPayload();
+					
+					for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext(); )
+					{
+						SupportClass.CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[]) it.Current)));
+					}
+				}
+			}
+			Assert.AreEqual(2, payloadSet.Count);
+			Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
+			Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
+		}
+		
+		[Test]
+		public virtual void  TestShrinkToAfterShortestMatch2()
+		{
+			RAMDirectory directory = new RAMDirectory();
+			IndexWriter writer = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
+			Document doc = new Document();
+			doc.Add(new Field("content", new System.IO.StreamReader("a b a d k f a h i k a k")));
+			writer.AddDocument(doc);
+			writer.Close();
+			
+			IndexSearcher is_Renamed = new IndexSearcher(directory);
+			
+			SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
+			SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
+			SpanQuery[] sqs = new SpanQuery[]{stq1, stq2};
+			SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
+			Spans spans = snq.GetSpans(is_Renamed.GetIndexReader());
+			
+			TopDocs topDocs = is_Renamed.Search(snq, 1);
+			System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
+			for (int i = 0; i < topDocs.scoreDocs.Length; i++)
+			{
+				while (spans.Next())
+				{
+					System.Collections.ICollection payloads = spans.GetPayload();
+					int cnt = 0;
+					for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext(); )
+					{
+						SupportClass.CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[]) it.Current)));
+					}
+				}
+			}
+			Assert.AreEqual(2, payloadSet.Count);
+			Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
+			Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
+		}
 
         [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;
-            }
-        }
-    }
+        public virtual void TestShrinkToAfterShortestMatch3()
+		{
+			RAMDirectory directory = new RAMDirectory();
+			IndexWriter writer = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
+			Document doc = new Document();
+			doc.Add(new Field("content", new System.IO.StreamReader("j k a l f k k p a t a k l k t a")));
+			writer.AddDocument(doc);
+			writer.Close();
+			
+			IndexSearcher is_Renamed = new IndexSearcher(directory);
+			
+			SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
+			SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));
+			SpanQuery[] sqs = new SpanQuery[]{stq1, stq2};
+			SpanNearQuery snq = new SpanNearQuery(sqs, 0, true);
+			Spans spans = snq.GetSpans(is_Renamed.GetIndexReader());
+			
+			TopDocs topDocs = is_Renamed.Search(snq, 1);
+			System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
+			for (int i = 0; i < topDocs.scoreDocs.Length; i++)
+			{
+				while (spans.Next())
+				{
+					System.Collections.ICollection payloads = spans.GetPayload();
+					
+					for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext(); )
+					{
+						SupportClass.CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[]) it.Current)));
+					}
+				}
+			}
+			Assert.AreEqual(2, payloadSet.Count);
+			if (DEBUG)
+			{
+				System.Collections.IEnumerator pit = payloadSet.GetEnumerator();
+				while (pit.MoveNext())
+				{
+					System.Console.Out.WriteLine("match:" + pit.Current);
+				}
+			}
+			Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
+			Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
+		}
+		
+		[Test]
+		public virtual void  TestPayloadSpanUtil()
+		{
+			RAMDirectory directory = new RAMDirectory();
+			PayloadAnalyzer analyzer = new PayloadAnalyzer(this);
+			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.Out.WriteLine("Num payloads:" + payloads.Count);
+			System.Collections.IEnumerator it = payloads.GetEnumerator();
+			while (it.MoveNext())
+			{
+				byte[] bytes = (byte[]) it.Current;
+				if (DEBUG)
+					System.Console.Out.WriteLine(new System.String(System.Text.UTF8Encoding.UTF8.GetChars(bytes)));
+			}
+		}
+		
+		private void  CheckSpans(Spans 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.ICollection payload = spans.GetPayload();
+					Assert.IsTrue(payload.Count == expectedNumPayloads, "payload Size: " + payload.Count + " is not: " + expectedNumPayloads);
+					for (System.Collections.IEnumerator iterator = payload.GetEnumerator(); iterator.MoveNext(); )
+					{
+						byte[] thePayload = (byte[]) 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(this);
+			System.String[] docs = new System.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();
+				System.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(Spans spans, int numSpans, int[] numPayloads)
+		{
+			int cnt = 0;
+			
+			while (spans.Next() == true)
+			{
+				if (DEBUG)
+					System.Console.Out.WriteLine("\nSpans Dump --");
+				if (spans.IsPayloadAvailable())
+				{
+					System.Collections.ICollection payload = spans.GetPayload();
+					if (DEBUG)
+						System.Console.Out.WriteLine("payloads for span:" + payload.Count);
+					System.Collections.IEnumerator it = payload.GetEnumerator();
+					while (it.MoveNext())
+					{
+						byte[] bytes = (byte[]) it.Current;
+						if (DEBUG)
+							System.Console.Out.WriteLine("doc:" + spans.Doc() + " s:" + spans.Start() + " e:" + spans.End() + " " + new System.String(System.Text.UTF8Encoding.UTF8.GetChars(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);
+		}
+		
+		internal class PayloadAnalyzer:Analyzer
+		{
+			public PayloadAnalyzer(TestPayloadSpans enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(TestPayloadSpans enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestPayloadSpans enclosingInstance;
+			public TestPayloadSpans 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;
+			}
+		}
+		
+		internal class PayloadFilter:TokenFilter
+		{
+			private void  InitBlock(TestPayloadSpans enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestPayloadSpans enclosingInstance;
+			public TestPayloadSpans Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			internal System.String fieldName;
+			internal int numSeen = 0;
+			internal System.Collections.Hashtable entities = new System.Collections.Hashtable();
+			internal System.Collections.Hashtable nopayload = new System.Collections.Hashtable();
+			internal int pos;
+			internal PayloadAttribute payloadAtt;
+			internal TermAttribute termAtt;
+			internal PositionIncrementAttribute posIncrAtt;
+			
+			public PayloadFilter(TestPayloadSpans enclosingInstance, TokenStream input, System.String fieldName):base(input)
+			{
+				InitBlock(enclosingInstance);
+				this.fieldName = fieldName;
+				pos = 0;
+				SupportClass.CollectionsHelper.AddIfNotContains(entities, "xx");
+				SupportClass.CollectionsHelper.AddIfNotContains(entities, "one");
+				SupportClass.CollectionsHelper.AddIfNotContains(nopayload, "nopayload");
+				SupportClass.CollectionsHelper.AddIfNotContains(nopayload, "np");
+				termAtt = (TermAttribute) AddAttribute(typeof(TermAttribute));
+				posIncrAtt = (PositionIncrementAttribute) AddAttribute(typeof(PositionIncrementAttribute));
+				payloadAtt = (PayloadAttribute) AddAttribute(typeof(PayloadAttribute));
+			}
+			
+			public override bool IncrementToken()
+			{
+				if (input.IncrementToken())
+				{
+					System.String token = new System.String(termAtt.TermBuffer(), 0, termAtt.TermLength());
+					
+					if (!nopayload.Contains(token))
+					{
+						if (entities.Contains(token))
+						{
+							payloadAtt.SetPayload(new Payload(System.Text.UTF8Encoding.UTF8.GetBytes(token + ":Entity:" + pos)));
+						}
+						else
+						{
+							payloadAtt.SetPayload(new Payload(System.Text.UTF8Encoding.UTF8.GetBytes(token + ":Noise:" + pos)));
+						}
+					}
+					pos += posIncrAtt.GetPositionIncrement();
+					return true;
+				}
+				return false;
+			}
+		}
+		
+		public class TestPayloadAnalyzer:Analyzer
+		{
+			public TestPayloadAnalyzer(TestPayloadSpans enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(TestPayloadSpans enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestPayloadSpans enclosingInstance;
+			public TestPayloadSpans 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;
+			}
+		}
+	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanations.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestSpanExplanations.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanations.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanations.cs Tue Nov  3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,34 +19,33 @@
 
 using NUnit.Framework;
 
-using Lucene.Net.Search;
-using Searchable = Lucene.Net.Search.Searchable;
-using RAMDirectory = Lucene.Net.Store.RAMDirectory;
-using IndexWriter = Lucene.Net.Index.IndexWriter;
-using IndexReader = Lucene.Net.Index.IndexReader;
-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 IndexReader = Lucene.Net.Index.IndexReader;
+using IndexWriter = Lucene.Net.Index.IndexWriter;
+using Term = Lucene.Net.Index.Term;
 using ParseException = Lucene.Net.QueryParsers.ParseException;
+using QueryParser = Lucene.Net.QueryParsers.QueryParser;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
+using Lucene.Net.Search;
 
 namespace Lucene.Net.Search.Spans
 {
 	
 	/// <summary> TestExplanations subclass focusing on span queries</summary>
-	[TestFixture]
-	public class TestSpanExplanations : TestExplanations
+    [TestFixture]
+	public class TestSpanExplanations:TestExplanations
 	{
 		
 		/* simple SpanTermQueries */
+		
 		[Test]
 		public virtual void  TestST1()
 		{
 			SpanQuery q = St("w1");
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestST2()
 		{
@@ -54,14 +53,12 @@
 			q.SetBoost(1000);
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestST4()
 		{
 			SpanQuery q = St("xx");
 			Qtest(q, new int[]{2, 3});
 		}
-
 		[Test]
 		public virtual void  TestST5()
 		{
@@ -78,7 +75,6 @@
 			SpanQuery q = Sf(("w1"), 1);
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSF2()
 		{
@@ -86,21 +82,18 @@
 			q.SetBoost(1000);
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSF4()
 		{
 			SpanQuery q = Sf(("xx"), 2);
 			Qtest(q, new int[]{2});
 		}
-
 		[Test]
 		public virtual void  TestSF5()
 		{
 			SpanQuery q = Sf(("yy"), 2);
 			Qtest(q, new int[]{});
 		}
-
 		[Test]
 		public virtual void  TestSF6()
 		{
@@ -117,21 +110,18 @@
 			SpanQuery q = Sor("w1", "QQ");
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSO2()
 		{
 			SpanQuery q = Sor("w1", "w3", "zz");
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSO3()
 		{
 			SpanQuery q = Sor("w5", "QQ", "yy");
 			Qtest(q, new int[]{0, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSO4()
 		{
@@ -149,28 +139,24 @@
 			SpanQuery q = Snear("w1", "QQ", 100, true);
 			Qtest(q, new int[]{});
 		}
-
 		[Test]
 		public virtual void  TestSNear2()
 		{
 			SpanQuery q = Snear("w1", "xx", 100, true);
 			Qtest(q, new int[]{2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNear3()
 		{
 			SpanQuery q = Snear("w1", "xx", 0, true);
 			Qtest(q, new int[]{2});
 		}
-
 		[Test]
 		public virtual void  TestSNear4()
 		{
 			SpanQuery q = Snear("w1", "xx", 1, true);
 			Qtest(q, new int[]{2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNear5()
 		{
@@ -184,35 +170,30 @@
 			SpanQuery q = Snear("w1", "w2", "QQ", 100, true);
 			Qtest(q, new int[]{});
 		}
-
 		[Test]
 		public virtual void  TestSNear7()
 		{
 			SpanQuery q = Snear("w1", "xx", "w2", 100, true);
 			Qtest(q, new int[]{2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNear8()
 		{
 			SpanQuery q = Snear("w1", "xx", "w2", 0, true);
 			Qtest(q, new int[]{2});
 		}
-
 		[Test]
 		public virtual void  TestSNear9()
 		{
 			SpanQuery q = Snear("w1", "xx", "w2", 1, true);
 			Qtest(q, new int[]{2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNear10()
 		{
 			SpanQuery q = Snear("xx", "w1", "w2", 0, false);
 			Qtest(q, new int[]{2});
 		}
-
 		[Test]
 		public virtual void  TestSNear11()
 		{
@@ -229,7 +210,6 @@
 			SpanQuery q = Snot(Sf("w1", 10), St("QQ"));
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNot2()
 		{
@@ -237,14 +217,12 @@
 			q.SetBoost(1000);
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNot4()
 		{
 			SpanQuery q = Snot(Sf("w1", 10), St("xx"));
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNot5()
 		{
@@ -252,7 +230,6 @@
 			q.SetBoost(1000);
 			Qtest(q, new int[]{0, 1, 2, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNot7()
 		{
@@ -261,7 +238,6 @@
 			SpanQuery q = Snot(f, St("xx"));
 			Qtest(q, new int[]{0, 1, 3});
 		}
-
 		[Test]
 		public virtual void  TestSNot10()
 		{

Modified: incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanationsOfNonMatches.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Test/Search/Spans/TestSpanExplanationsOfNonMatches.cs?rev=832486&r1=832485&r2=832486&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanationsOfNonMatches.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Test/Search/Spans/TestSpanExplanationsOfNonMatches.cs Tue Nov  3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -15,20 +15,20 @@
  * limitations under the License.
  */
 
-using NUnit.Framework;
-
 using System;
 
-using Query = Lucene.Net.Search.Query;
+using NUnit.Framework;
+
 using CheckHits = Lucene.Net.Search.CheckHits;
+using Query = Lucene.Net.Search.Query;
 
 namespace Lucene.Net.Search.Spans
 {
 	
 	
 	/// <summary> subclass of TestSimpleExplanations that verifies non matches.</summary>
-	[TestFixture]
-	public class TestSpanExplanationsOfNonMatches : TestSpanExplanations
+    [TestFixture]
+	public class TestSpanExplanationsOfNonMatches:TestSpanExplanations
 	{
 		
 		/// <summary> Overrides superclass to ignore matches and focus on non-matches

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=832486&r1=832485&r2=832486&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 Tue Nov  3 18:06:27 2009
@@ -1,4 +1,4 @@
-/*
+/* 
  * 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.
@@ -19,479 +19,515 @@
 
 using NUnit.Framework;
 
-using IndexSearcher = Lucene.Net.Search.IndexSearcher;
-using Query = Lucene.Net.Search.Query;
+using WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
+using StandardAnalyzer = Lucene.Net.Analysis.Standard.StandardAnalyzer;
+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 Term = Lucene.Net.Index.Term;
+using Directory = Lucene.Net.Store.Directory;
+using MockRAMDirectory = Lucene.Net.Store.MockRAMDirectory;
+using RAMDirectory = Lucene.Net.Store.RAMDirectory;
 using CheckHits = Lucene.Net.Search.CheckHits;
 using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
-using Similarity = Lucene.Net.Search.Similarity;
+using DocIdSetIterator = Lucene.Net.Search.DocIdSetIterator;
+using IndexSearcher = Lucene.Net.Search.IndexSearcher;
+using Query = Lucene.Net.Search.Query;
 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 WhitespaceAnalyzer = Lucene.Net.Analysis.WhitespaceAnalyzer;
-using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
+using Similarity = Lucene.Net.Search.Similarity;
+using TermQuery = Lucene.Net.Search.TermQuery;
 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, 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();
-        }
-    }
+	public class TestSpans:LuceneTestCase
+	{
+		[Serializable]
+		private class AnonymousClassDefaultSimilarity:DefaultSimilarity
+		{
+			public AnonymousClassDefaultSimilarity(TestSpans enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(TestSpans enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private TestSpans enclosingInstance;
+			public TestSpans Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			public override float SloppyFreq(int distance)
+			{
+				return 0.0f;
+			}
+		}
+		private class AnonymousClassSpanNearQuery:SpanNearQuery
+		{
+			private void  InitBlock(Lucene.Net.Search.Similarity sim, TestSpans enclosingInstance)
+			{
+				this.sim = sim;
+				this.enclosingInstance = enclosingInstance;
+			}
+			private Lucene.Net.Search.Similarity sim;
+			private TestSpans enclosingInstance;
+			public TestSpans Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			internal AnonymousClassSpanNearQuery(Lucene.Net.Search.Similarity sim, TestSpans enclosingInstance, Lucene.Net.Search.Spans.SpanQuery[] Param1, int Param2, bool Param3):base(Param1, Param2, Param3)
+			{
+				InitBlock(sim, enclosingInstance);
+			}
+			public override Similarity GetSimilarity(Searcher s)
+			{
+				return sim;
+			}
+		}
+		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++)
+			{
+				Document doc = new Document();
+				doc.Add(new Field(field, docFields[i], Field.Store.YES, Field.Index.ANALYZED));
+				writer.AddDocument(doc);
+			}
+			writer.Close();
+			searcher = new IndexSearcher(directory);
+		}
+		
+		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_Method(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 virtual 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");
+			
+			SpanOrQuery a = new SpanOrQuery(new SpanQuery[0]);
+			SpanOrQuery b = new SpanOrQuery(new SpanQuery[0]);
+			Assert.IsTrue(a.Equals(b), "empty should equal");
+		}
+		
+		[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  TestSpanOrMovesForward()
+		{
+			Spans spans = OrSpans(new System.String[]{"w1", "xx"});
+			
+			spans.Next();
+			int doc = spans.Doc();
+			Assert.AreEqual(0, doc);
+			
+			spans.SkipTo(0);
+			doc = spans.Doc();
+			
+			// LUCENE-1583:
+			// according to Spans, a skipTo to the same doc or less
+			// should still call next() on the underlying Spans
+			Assert.AreEqual(1, doc);
+		}
+		
+		[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");
+		}
+		
+		[Test]
+		public virtual void  TestSpanScorerZeroSloppyFreq()
+		{
+			bool ordered = true;
+			int slop = 1;
+			
+			Similarity sim = new AnonymousClassDefaultSimilarity(this);
+			
+			SpanNearQuery snq = new AnonymousClassSpanNearQuery(sim, this, new SpanQuery[]{MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2")}, slop, ordered);
+			
+			Scorer spanScorer = snq.Weight(searcher).Scorer(searcher.GetIndexReader(), true, false);
+			
+			Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc");
+			Assert.AreEqual(spanScorer.DocID(), 11, "first doc number");
+			float score = spanScorer.Score();
+			Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score);
+			Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc");
+		}
+		
+		// LUCENE-1404
+		private void  AddDoc(IndexWriter writer, System.String id, System.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, System.String word)
+		{
+			return searcher.Search(new TermQuery(new Term("text", word)), 10).totalHits;
+		}
+		
+		// LUCENE-1404
+		private SpanQuery CreateSpan(System.String value_Renamed)
+		{
+			return new SpanTermQuery(new Term("text", value_Renamed));
+		}
+		
+		// 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, System.String term1, System.String term2)
+		{
+			return CreateSpan(slop, ordered, new SpanQuery[]{CreateSpan(term1), CreateSpan(term2)});
+		}
+		
+		// LUCENE-1404
+		[Test]
+		public virtual void  TestNPESpanQuery()
+		{
+			Directory dir = new MockRAMDirectory();
+			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(new System.Collections.Hashtable(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



Mime
View raw message