lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r671402 [4/5] - in /incubator/lucene.net/trunk/C#/src/Lucene.Net/Search: ./ Function/ Payload/ Spans/
Date Wed, 25 Jun 2008 02:51:26 GMT
Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/BoostingTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Payload/BoostingTermQuery.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/BoostingTermQuery.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/BoostingTermQuery.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+using Term = Lucene.Net.Index.Term;
+using TermPositions = Lucene.Net.Index.TermPositions;
+using Lucene.Net.Search;
+using Searchable = Lucene.Net.Search.Searchable;
+using SpanScorer = Lucene.Net.Search.Spans.SpanScorer;
+using SpanTermQuery = Lucene.Net.Search.Spans.SpanTermQuery;
+using SpanWeight = Lucene.Net.Search.Spans.SpanWeight;
+using TermSpans = Lucene.Net.Search.Spans.TermSpans;
+
+namespace Lucene.Net.Search.Payloads
+{
+	
+	/// <summary> The BoostingTermQuery is very similar to the {@link Lucene.Net.Search.Spans.SpanTermQuery} except
+	/// that it factors in the value of the payload located at each of the positions where the
+	/// {@link Lucene.Net.Index.Term} occurs.
+	/// <p>
+	/// In order to take advantage of this, you must override {@link Lucene.Net.Search.Similarity#ScorePayload(String, byte[],int,int)}
+	/// which returns 1 by default.
+	/// <p>
+	/// Payload scores are averaged across term occurrences in the document.  
+	/// 
+	/// </summary>
+	/// <seealso cref="Lucene.Net.Search.Similarity.ScorePayload(String, byte[], int, int)">
+	/// </seealso>
+	[Serializable]
+	public class BoostingTermQuery : SpanTermQuery
+	{
+		
+		
+		public BoostingTermQuery(Term term) : base(term)
+		{
+		}
+		
+		
+		protected internal override Weight CreateWeight(Searcher searcher)
+		{
+			return new BoostingTermWeight(this, this, searcher);
+		}
+		
+		[Serializable]
+		protected internal class BoostingTermWeight : SpanWeight, Weight
+		{
+			private void  InitBlock(BoostingTermQuery enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private BoostingTermQuery enclosingInstance;
+			public BoostingTermQuery Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			
+			
+			public BoostingTermWeight(BoostingTermQuery enclosingInstance, BoostingTermQuery query, Searcher searcher) : base(query, searcher)
+			{
+				InitBlock(enclosingInstance);
+			}
+			
+			
+			
+			
+			public override Scorer Scorer(IndexReader reader)
+			{
+				return new BoostingSpanScorer(this, (TermSpans) query.GetSpans(reader), this, similarity, reader.Norms(query.GetField()));
+			}
+			
+			internal class BoostingSpanScorer : SpanScorer
+			{
+				private void  InitBlock(BoostingTermWeight enclosingInstance)
+				{
+					this.enclosingInstance = enclosingInstance;
+				}
+				private BoostingTermWeight enclosingInstance;
+				public BoostingTermWeight Enclosing_Instance
+				{
+					get
+					{
+						return enclosingInstance;
+					}
+					
+				}
+				
+				//TODO: is this the best way to allocate this?
+				internal byte[] payload = new byte[256];
+				private TermPositions positions;
+				protected internal float payloadScore;
+				private int payloadsSeen;
+				
+				public BoostingSpanScorer(BoostingTermWeight enclosingInstance, TermSpans spans, Weight weight, Similarity similarity, byte[] norms) : base(spans, weight, similarity, norms)
+				{
+					InitBlock(enclosingInstance);
+					positions = spans.GetPositions();
+				}
+				
+				protected internal override bool SetFreqCurrentDoc()
+				{
+					if (!more)
+					{
+						return false;
+					}
+					doc = spans.Doc();
+					freq = 0.0f;
+					payloadScore = 0;
+					payloadsSeen = 0;
+					Similarity similarity1 = GetSimilarity();
+					while (more && doc == spans.Doc())
+					{
+						int matchLength = spans.End() - spans.Start();
+						
+						freq += similarity1.SloppyFreq(matchLength);
+						ProcessPayload(similarity1);
+						
+						more = spans.Next(); //this moves positions to the next match in this document
+					}
+					return more || (freq != 0);
+				}
+				
+				
+				protected internal virtual void  ProcessPayload(Similarity similarity)
+				{
+					if (positions.IsPayloadAvailable())
+					{
+						payload = positions.GetPayload(payload, 0);
+						payloadScore += similarity.ScorePayload(Enclosing_Instance.Enclosing_Instance.term.Field(), payload, 0, positions.GetPayloadLength());
+						payloadsSeen++;
+					}
+					else
+					{
+						//zero out the payload?
+					}
+				}
+				
+				public override float Score()
+				{
+					
+					return base.Score() * (payloadsSeen > 0 ? (payloadScore / payloadsSeen) : 1);
+				}
+				
+				
+				public override Explanation Explain(int doc)
+				{
+					Explanation result = new Explanation();
+					Explanation nonPayloadExpl = base.Explain(doc);
+					result.AddDetail(nonPayloadExpl);
+					//QUESTION: Is there a wau to avoid this skipTo call?  We need to know whether to load the payload or not
+					
+					Explanation payloadBoost = new Explanation();
+					result.AddDetail(payloadBoost);
+					/*
+					if (skipTo(doc) == true) {
+					processPayload();
+					}*/
+					
+					float avgPayloadScore = (payloadsSeen > 0 ? (payloadScore / payloadsSeen) : 1);
+					payloadBoost.SetValue(avgPayloadScore);
+					//GSI: I suppose we could toString the payload, but I don't think that would be a good idea 
+					payloadBoost.SetDescription("scorePayload(...)");
+					result.SetValue(nonPayloadExpl.GetValue() * avgPayloadScore);
+					result.SetDescription("btq, product of:");
+					return result;
+				}
+			}
+		}
+		
+		
+		public  override bool Equals(System.Object o)
+		{
+			if (!(o is BoostingTermQuery))
+				return false;
+			BoostingTermQuery other = (BoostingTermQuery) o;
+			return (this.GetBoost() == other.GetBoost()) && this.term.Equals(other.term);
+		}
+		
+		public override int GetHashCode()   // {{Aroush-2.3.1}} Do we need this methods?
+		{
+			return base.GetHashCode();
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Payload/Package.html?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/Package.html (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Payload/Package.html Tue Jun 24 19:51:24 2008
@@ -0,0 +1,36 @@
+<HTML>
+ <!--
+/**
+ * Copyright 2005 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.
+ */
+
+ --><HEAD>
+    <TITLE>org.apache.lucene.search.payloads</TITLE>
+</HEAD>
+<BODY>
+<DIV>The payloads package provides Query mechanisms for finding and using payloads.
+
+  The following Query implementations are provided:
+</DIV>
+<div>
+  <ol>
+    <li><a href = "BoostingTermQuery.html">BoostingTermQuery</a> -- Boost a term's score based on the value of the payload located at that term</li>
+  </ol>
+</div>
+<DIV>&nbsp;</DIV>
+<DIV align="center">
+</DIV>
+</BODY>
+</HTML>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhrasePositions.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhrasePositions.cs Tue Jun 24 19:51:24 2008
@@ -22,6 +22,7 @@
 namespace Lucene.Net.Search
 {
 	
+	/// <summary> Position of a term in a document that takes into account the term offset within the phrase. </summary>
 	sealed class PhrasePositions
 	{
 		internal int doc; // current doc
@@ -30,6 +31,7 @@
 		internal int offset; // position in phrase
 		internal TermPositions tp; // stream of positions
 		internal PhrasePositions next; // used to make lists
+		internal bool repeats; // there's other pp for same term (e.g. query="1st word 2nd word"~1) 
 		
 		internal PhrasePositions(TermPositions t, int o)
 		{
@@ -71,6 +73,11 @@
 			NextPosition();
 		}
 		
+		/// <summary> Go to next location of this term current document, and set 
+		/// <code>position</code> as <code>location - offset</code>, so that a 
+		/// matching exact phrase is easily identified when all PhrasePositions 
+		/// have exactly the same <code>position</code>.
+		/// </summary>
 		internal bool NextPosition()
 		{
 			if (count-- > 0)

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseQueue.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseQueue.cs Tue Jun 24 19:51:24 2008
@@ -34,7 +34,12 @@
 			PhrasePositions pp1 = (PhrasePositions) o1;
 			PhrasePositions pp2 = (PhrasePositions) o2;
 			if (pp1.doc == pp2.doc)
-				return pp1.position < pp2.position;
+				if (pp1.position == pp2.position)
+					// same doc and pp.position, so decide by actual term positions. 
+					// rely on: pp.position == tp.position - offset. 
+					return pp1.offset < pp2.offset;
+				else
+					return pp1.position < pp2.position;
 			else
 				return pp1.doc < pp2.doc;
 		}

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PhraseScorer.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PhraseScorer.cs Tue Jun 24 19:51:24 2008
@@ -22,6 +22,16 @@
 namespace Lucene.Net.Search
 {
 	
+	/// <summary>Expert: Scoring functionality for phrase queries.
+	/// <br>A document is considered matching if it contains the phrase-query terms  
+	/// at "valid" positons. What "valid positions" are
+	/// depends on the type of the phrase query: for an exact phrase query terms are required 
+	/// to appear in adjacent locations, while for a sloppy phrase query some distance between 
+	/// the terms is allowed. The abstract method {@link #PhraseFreq()} of extending classes
+	/// is invoked for each document containing all the phrase query terms, in order to 
+	/// compute the frequency of the phrase query in that document. A non zero frequency
+	/// means a match. 
+	/// </summary>
 	abstract class PhraseScorer : Scorer
 	{
 		private Weight weight;
@@ -33,19 +43,23 @@
 		protected internal PhraseQueue pq;
 		protected internal PhrasePositions first, last;
 		
-		private float freq;
+		private float freq; //prhase frequency in current doc as computed by phraseFreq().
 		
 		
-		internal PhraseScorer(Weight weight, TermPositions[] tps, int[] positions, Similarity similarity, byte[] norms) : base(similarity)
+        internal PhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, byte[] norms):base(similarity)
 		{
 			this.norms = norms;
 			this.weight = weight;
 			this.value_Renamed = weight.GetValue();
 			
-			// convert tps to a list
+			// convert tps to a list of phrase positions.
+			// note: phrase-position differs from term-position in that its position
+			// reflects the phrase offset: pp.pos = tp.pos - offset.
+			// this allows to easily identify a matching (exact) phrase 
+			// when all PhrasePositions have exactly the same position.
 			for (int i = 0; i < tps.Length; i++)
 			{
-				PhrasePositions pp = new PhrasePositions(tps[i], positions[i]);
+				PhrasePositions pp = new PhrasePositions(tps[i], offsets[i]);
 				if (last != null)
 				{
 					// add next to end of list
@@ -114,6 +128,7 @@
 		
 		public override bool SkipTo(int target)
 		{
+			firstTime = false;
 			for (PhrasePositions pp = first; more && pp != null; pp = pp.next)
 			{
 				more = pp.SkipTo(target);
@@ -123,6 +138,13 @@
 			return DoNext();
 		}
 		
+		/// <summary> For a document containing all the phrase query terms, compute the
+		/// frequency of the phrase in that document. 
+		/// A non zero frequency means a match.
+		/// <br>Note, that containing all phrase terms does not guarantee a match - they have to be found in matching locations.  
+		/// </summary>
+		/// <returns> frequency of the phrase in current doc, 0 if not found. 
+		/// </returns>
 		protected internal abstract float PhraseFreq();
 		
 		private void  Init()
@@ -175,7 +197,7 @@
 			{
 			}
 			
-			float phraseFreq = (Doc() == doc)?freq:0.0f;
+			float phraseFreq = (Doc() == doc) ? freq : 0.0f;
 			tfExplanation.SetValue(GetSimilarity().Tf(phraseFreq));
 			tfExplanation.SetDescription("tf(phraseFreq=" + phraseFreq + ")");
 			

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PrefixFilter.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixFilter.cs Tue Jun 24 19:51:24 2008
@@ -25,8 +25,7 @@
 namespace Lucene.Net.Search
 {
 	
-	/// <author>  yonik
-	/// </author>
+	/// <summary> </summary>
 	/// <version>  $Id$
 	/// </version>
 	[Serializable]
@@ -73,7 +72,7 @@
 		
 		public override System.Collections.BitArray Bits(IndexReader reader)
 		{
-			System.Collections.BitArray bitSet = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
+			System.Collections.BitArray bitSet = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
 			new AnonymousClassPrefixGenerator(bitSet, this, prefix).Generate(reader);
 			return bitSet;
 		}
@@ -122,6 +121,7 @@
 				{
 					Term term = enumerator.Term();
 					if (term != null && term.Text().StartsWith(prefixText) && (System.Object) term.Field() == (System.Object) prefixField)
+					// interned comparison
 					{
 						termDocs.Seek(term);
 						while (termDocs.Next())

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/PrefixQuery.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/PrefixQuery.cs Tue Jun 24 19:51:24 2008
@@ -61,6 +61,7 @@
 #else
                     if (term != null && term.Text().StartsWith(prefixText) && term.Field() == prefixField)
 #endif
+					// interned comparison 
                     {
 						TermQuery tq = new TermQuery(term); // found a match
 						tq.SetBoost(GetBoost()); // set the boost

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/QueryFilter.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryFilter.cs Tue Jun 24 19:51:24 2008
@@ -27,102 +27,30 @@
 	/// query.  Results are cached, so that searches after the first on the same
 	/// index using this filter are much faster.
 	/// 
-	/// <p> This could be used, for example, with a {@link RangeQuery} on a suitably
-	/// formatted date field to implement date filtering.  One could re-use a single
-	/// QueryFilter that matches, e.g., only documents modified within the last
-	/// week.  The QueryFilter and RangeQuery would only need to be reconstructed
-	/// once per day.
-	/// 
 	/// </summary>
-	/// <version>  $Id: QueryFilter.java 472959 2006-11-09 16:21:50Z yonik $
+	/// <version>  $Id: QueryFilter.java 528298 2007-04-13 00:59:28Z hossman $
 	/// </version>
+	/// <deprecated> use a CachingWrapperFilter with QueryWrapperFilter
+	/// </deprecated>
 	[Serializable]
-	public class QueryFilter : Filter
+	public class QueryFilter:CachingWrapperFilter
 	{
-		private class AnonymousClassHitCollector : HitCollector
-		{
-			public AnonymousClassHitCollector(System.Collections.BitArray bits, QueryFilter enclosingInstance)
-			{
-				InitBlock(bits, enclosingInstance);
-			}
-			private void  InitBlock(System.Collections.BitArray bits, QueryFilter enclosingInstance)
-			{
-				this.bits = bits;
-				this.enclosingInstance = enclosingInstance;
-			}
-			private System.Collections.BitArray bits;
-			private QueryFilter enclosingInstance;
-			public QueryFilter Enclosing_Instance
-			{
-				get
-				{
-					return enclosingInstance;
-				}
-				
-			}
-			public override void  Collect(int doc, float score)
-			{
-				bits.Set(doc, true); // set bit for hit
-			}
-		}
-		private Query query;
-		[NonSerialized]
-		private System.Collections.Hashtable cache = null;
 		
 		/// <summary>Constructs a filter which only matches documents matching
 		/// <code>query</code>.
 		/// </summary>
-		public QueryFilter(Query query)
-		{
-			this.query = query;
-		}
-		
-		public override System.Collections.BitArray Bits(IndexReader reader)
-		{
-			
-			if (cache == null)
-			{
-				cache = new System.Collections.Hashtable();
-			}
-			
-			lock (cache.SyncRoot)
-			{
-				// check cache
-				System.Collections.BitArray cached = (System.Collections.BitArray) cache[reader];
-				if (cached != null)
-				{
-					return cached;
-				}
-			}
-			
-			System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0?reader.MaxDoc() / 64:reader.MaxDoc() / 64 + 1) * 64);
-			
-			new IndexSearcher(reader).Search(query, new AnonymousClassHitCollector(bits, this));
-			
-			lock (cache.SyncRoot)
-			{
-				// update cache
-				cache[reader] = bits;
-			}
-			
-			return bits;
-		}
-		
-		public override System.String ToString()
+		public QueryFilter(Query query):base(new QueryWrapperFilter(query))
 		{
-			return "QueryFilter(" + query + ")";
 		}
 		
 		public  override bool Equals(System.Object o)
 		{
-			if (!(o is QueryFilter))
-				return false;
-			return this.query.Equals(((QueryFilter) o).query);
+			return base.Equals((QueryFilter) o);
 		}
 		
 		public override int GetHashCode()
 		{
-			return query.GetHashCode() ^ (unchecked((int) 0x923F64B9L));     // {{Aroush-1.9}} Is this OK?!
+			return base.GetHashCode() ^ unchecked((int) 0x923F64B9);
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/QueryTermVector.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryTermVector.cs Tue Jun 24 19:51:24 2008
@@ -144,7 +144,7 @@
 		public virtual int IndexOf(System.String term)
 		{
 			int res = System.Array.BinarySearch(terms, term);
-			return res >= 0?res:- 1;
+			return res >= 0 ? res : - 1;
 		}
 		
 		public virtual int[] IndexesOf(System.String[] terms, int start, int len)

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryWrapperFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/QueryWrapperFilter.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryWrapperFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/QueryWrapperFilter.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary> Constrains search results to only match those which also match a provided
+	/// query.  
+	/// 
+	/// <p> This could be used, for example, with a {@link RangeQuery} on a suitably
+	/// formatted date field to implement date filtering.  One could re-use a single
+	/// QueryFilter that matches, e.g., only documents modified within the last
+	/// week.  The QueryFilter and RangeQuery would only need to be reconstructed
+	/// once per day.
+	/// 
+	/// </summary>
+	/// <version>  $Id:$
+	/// </version>
+	[Serializable]
+	public class QueryWrapperFilter : Filter
+	{
+		private class AnonymousClassHitCollector:HitCollector
+		{
+			public AnonymousClassHitCollector(System.Collections.BitArray bits, QueryWrapperFilter enclosingInstance)
+			{
+				InitBlock(bits, enclosingInstance);
+			}
+			private void  InitBlock(System.Collections.BitArray bits, QueryWrapperFilter enclosingInstance)
+			{
+				this.bits = bits;
+				this.enclosingInstance = enclosingInstance;
+			}
+			private System.Collections.BitArray bits;
+			private QueryWrapperFilter enclosingInstance;
+			public QueryWrapperFilter Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			public override void  Collect(int doc, float score)
+			{
+				bits.Set(doc, true);
+			}
+		}
+		private Query query;
+		
+		/// <summary>Constructs a filter which only matches documents matching
+		/// <code>query</code>.
+		/// </summary>
+		public QueryWrapperFilter(Query query)
+		{
+			this.query = query;
+		}
+		
+		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);
+			
+			new IndexSearcher(reader).Search(query, new AnonymousClassHitCollector(bits, this));
+			return bits;
+		}
+		
+		public override System.String ToString()
+		{
+			return "QueryWrapperFilter(" + query + ")";
+		}
+		
+		public  override bool Equals(System.Object o)
+		{
+			if (!(o is QueryWrapperFilter))
+				return false;
+			return this.query.Equals(((QueryWrapperFilter) o).query);
+		}
+		
+		public override int GetHashCode()
+		{
+			return query.GetHashCode() ^ unchecked((int) 0x923F64B9);
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RangeFilter.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeFilter.cs Tue Jun 24 19:51:24 2008
@@ -101,8 +101,8 @@
 		/// </summary>
 		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);
-			TermEnum enumerator = (null != lowerTerm?reader.Terms(new Term(fieldName, lowerTerm)):reader.Terms(new Term(fieldName, "")));
+			System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
+			TermEnum enumerator = (null != lowerTerm ? reader.Terms(new Term(fieldName, lowerTerm)) : reader.Terms(new Term(fieldName, "")));
 			
 			try
 			{
@@ -173,7 +173,7 @@
 			System.Text.StringBuilder buffer = new System.Text.StringBuilder();
 			buffer.Append(fieldName);
 			buffer.Append(":");
-			buffer.Append(includeLower?"[":"{");
+			buffer.Append(includeLower ? "[" : "{");
 			if (null != lowerTerm)
 			{
 				buffer.Append(lowerTerm);

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RangeQuery.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RangeQuery.cs Tue Jun 24 19:51:24 2008
@@ -41,7 +41,7 @@
 	/// 
 	/// 
 	/// </seealso>
-	/// <version>  $Id: RangeQuery.java 475435 2006-11-15 21:26:09Z mharwood $
+	/// <version>  $Id: RangeQuery.java 520891 2007-03-21 13:58:47Z yonik $
 	/// </version>
 	[Serializable]
 	public class RangeQuery : Query
@@ -102,6 +102,7 @@
 					Term term = enumerator.Term();
 					if (term != null && term.Field() == testField)
 					{
+						// interned comparison
 						if (!checkLower || String.CompareOrdinal(term.Text(), lowerTerm.Text()) > 0)
 						{
 							checkLower = false;
@@ -189,9 +190,9 @@
 			if (this.inclusive != other.inclusive)
 				return false;
 			// one of lowerTerm and upperTerm can be null
-			if (this.lowerTerm != null?!this.lowerTerm.Equals(other.lowerTerm):other.lowerTerm != null)
+			if (this.lowerTerm != null ? !this.lowerTerm.Equals(other.lowerTerm) : other.lowerTerm != null)
 				return false;
-			if (this.upperTerm != null?!this.upperTerm.Equals(other.upperTerm):other.upperTerm != null)
+			if (this.upperTerm != null ? !this.upperTerm.Equals(other.upperTerm) : other.upperTerm != null)
 				return false;
 			return true;
 		}

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteCachingWrapperFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RemoteCachingWrapperFilter.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteCachingWrapperFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteCachingWrapperFilter.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary> Provides caching of {@link Filter}s themselves on the remote end of an RMI connection.
+	/// The cache is keyed on Filter's hashCode(), so if it sees the same filter twice
+	/// it will reuse the original version.
+	/// <p/>
+	/// NOTE: This does NOT cache the Filter bits, but rather the Filter itself.
+	/// Thus, this works hand-in-hand with {@link CachingWrapperFilter} to keep both
+	/// file Filter cache and the Filter bits on the remote end, close to the searcher.
+	/// <p/>
+	/// Usage:
+	/// <p/>
+	/// To cache a result you must do something like 
+	/// RemoteCachingWrapperFilter f = new RemoteCachingWrapperFilter(new CachingWrapperFilter(myFilter));
+	/// <p/>
+	/// </summary>
+	/// <author>  Matt Ericson
+	/// </author>
+	[Serializable]
+	public class RemoteCachingWrapperFilter : Filter
+	{
+		protected internal Filter filter;
+		
+		public RemoteCachingWrapperFilter(Filter filter)
+		{
+			this.filter = filter;
+		}
+		
+		/// <summary> Uses the {@link FilterManager} to keep the cache for a filter on the 
+		/// searcher side of a remote connection.
+		/// </summary>
+		/// <param name="reader">the index reader for the Filter
+		/// </param>
+		/// <returns> the bitset
+		/// </returns>
+		public override System.Collections.BitArray Bits(IndexReader reader)
+		{
+			Filter cachedFilter = FilterManager.GetInstance().GetFilter(filter);
+			return cachedFilter.Bits(reader);
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/RemoteSearchable.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/RemoteSearchable.cs Tue Jun 24 19:51:24 2008
@@ -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.
@@ -18,6 +18,8 @@
 using System;
 
 using Document = Lucene.Net.Documents.Document;
+using FieldSelector = Lucene.Net.Documents.FieldSelector;
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
 using Term = Lucene.Net.Index.Term;
 
 namespace Lucene.Net.Search
@@ -83,6 +85,11 @@
 			return local.Doc(i);
 		}
 		
+		public virtual Document Doc(int i, FieldSelector fieldSelector)
+		{
+			return local.Doc(i, fieldSelector);
+		}
+		
 		public virtual Query Rewrite(Query original)
 		{
 			return local.Rewrite(original);
@@ -99,8 +106,8 @@
 		[STAThread]
 		public static void  Main(System.String[] args)
 		{
-			System.Runtime.Remoting.RemotingConfiguration.Configure("Lucene.Net.Search.RemoteSearchable.config");
-			System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Http.HttpChannel(1099));
+			System.Runtime.Remoting.RemotingConfiguration.Configure("Lucene.Net.Search.RemoteSearchable.config", false);
+			System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Http.HttpChannel(1099), false);
 			System.String indexName = null;
 			
 			if (args != null && args.Length == 1)
@@ -122,7 +129,7 @@
 			RemoteSearchable impl = new RemoteSearchable(local);
 			
 			// bind the implementation to "Searchable"
-			System.Runtime.Remoting.RemotingServices.Marshal(impl, "tcp://localhost:1099/Searchable");
+			System.Runtime.Remoting.RemotingServices.Marshal(impl, "localhost/Searchable");
 			System.Console.ReadLine();
 		}
 	}

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ReqOptSumScorer.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ReqOptSumScorer.cs Tue Jun 24 19:51:24 2008
@@ -90,7 +90,7 @@
 				return reqScore;
 			}
 			// assert (optScorer != null) && (optScorer.doc() >= curDoc);
-			return (optScorer.Doc() == curDoc)?reqScore + optScorer.Score():reqScore;
+			return (optScorer.Doc() == curDoc) ? reqScore + optScorer.Score() : reqScore;
 		}
 		
 		/// <summary>Explain the score of a document.</summary>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/ScoreDocComparator.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/ScoreDocComparator.cs Tue Jun 24 19:51:24 2008
@@ -30,7 +30,7 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: ScoreDocComparator.java 472959 2006-11-09 16:21:50Z yonik $
+	/// <version>  $Id: ScoreDocComparator.java 518518 2007-03-15 08:48:00Z buschmi $
 	/// </version>
 	public struct ScoreDocComparator_Fields
 	{
@@ -85,7 +85,6 @@
 	public interface ScoreDocComparator
 	{
 		
-		
 		/// <summary> Compares two ScoreDoc objects and returns a result indicating their
 		/// sort order.
 		/// </summary>
@@ -93,16 +92,18 @@
 		/// </param>
 		/// <param name="j">Second ScoreDoc
 		/// </param>
-		/// <returns> <code>-1</code> if <code>i</code> should come before <code>j</code><br><code>1</code> if <code>i</code> should come after <code>j</code><br><code>0</code> if they are equal
+		/// <returns> a negative integer if <code>i</code> should come before <code>j</code><br>
+		/// a positive integer if <code>i</code> should come after <code>j</code><br>
+		/// <code>0</code> if they are equal
 		/// </returns>
 		/// <seealso cref="java.util.Comparator">
 		/// </seealso>
 		int Compare(ScoreDoc i, ScoreDoc j);
 		
-		
 		/// <summary> Returns the value used to sort the given document.  The
 		/// object returned must implement the java.io.Serializable
-		/// interface.  This is used by multisearchers to determine how to collate results from their searchers.
+		/// interface.  This is used by multisearchers to determine how
+		/// to collate results from their searchers.
 		/// </summary>
 		/// <seealso cref="FieldDoc">
 		/// </seealso>
@@ -112,10 +113,13 @@
 		/// </returns>
 		System.IComparable SortValue(ScoreDoc i);
 		
-		
-		/// <summary> Returns the type of sort.  Should return <code>SortField.SCORE</code>, <code>SortField.DOC</code>, <code>SortField.STRING</code>, <code>SortField.INTEGER</code>, 
-		/// <code>SortField.FLOAT</code> or <code>SortField.CUSTOM</code>.  It is not valid to return <code>SortField.AUTO</code>.
-		/// This is used by multisearchers to determine how to collate results from their searchers.
+		/// <summary> Returns the type of sort.  Should return <code>SortField.SCORE</code>,
+		/// <code>SortField.DOC</code>, <code>SortField.STRING</code>,
+		/// <code>SortField.INTEGER</code>, <code>SortField.FLOAT</code> or
+		/// <code>SortField.CUSTOM</code>.  It is not valid to return
+		/// <code>SortField.AUTO</code>.
+		/// This is used by multisearchers to determine how to collate results
+		/// from their searchers.
 		/// </summary>
 		/// <returns> One of the constants in SortField.
 		/// </returns>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Scorer.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Scorer.cs Tue Jun 24 19:51:24 2008
@@ -20,11 +20,20 @@
 namespace Lucene.Net.Search
 {
 	
-	/// <summary>Expert: Common scoring functionality for different types of queries.
-	/// <br>A <code>Scorer</code> either iterates over documents matching a query,
-	/// or provides an explanation of the score for a query for a given document.
-	/// <br>Document scores are computed using a given <code>Similarity</code> implementation.
+	/// <summary> Expert: Common scoring functionality for different types of queries.
+	/// 
+	/// <p>
+	/// A <code>Scorer</code> either iterates over documents matching a
+	/// query in increasing order of doc Id, or provides an explanation of
+	/// the score for a query for a given document.
+	/// </p>
+	/// <p>
+	/// Document scores are computed using a given <code>Similarity</code>
+	/// implementation.
+	/// </p>
 	/// </summary>
+	/// <seealso cref="BooleanQuery.setAllowDocsOutOfOrder">
+	/// </seealso>
 	public abstract class Scorer
 	{
 		private Similarity similarity;
@@ -78,10 +87,21 @@
 			return true;
 		}
 		
-		/// <summary>Advances to the next document matching the query.</summary>
+		/// <summary> Advances to the document matching this Scorer with the lowest doc Id
+		/// greater than the current value of {@link #Doc()} (or to the matching
+		/// document with the lowest doc Id if next has never been called on
+		/// this Scorer).
+		/// 
+		/// <p>
+		/// When this method is used the {@link #Explain(int)} method should not
+		/// be used.
+		/// </p>
+		/// 
+		/// </summary>
 		/// <returns> true iff there is another document matching the query.
-		/// <br>When this method is used the {@link #Explain(int)} method should not be used.
 		/// </returns>
+		/// <seealso cref="BooleanQuery.setAllowDocsOutOfOrder">
+		/// </seealso>
 		public abstract bool Next();
 		
 		/// <summary>Returns the current document number matching the query.
@@ -95,23 +115,38 @@
 		/// </summary>
 		public abstract float Score();
 		
-		/// <summary>Skips to the first match beyond the current whose document number is
+		/// <summary> Skips to the document matching this Scorer with the lowest doc Id
 		/// greater than or equal to a given target.
-		/// <br>When this method is used the {@link #Explain(int)} method should not be used.
-		/// </summary>
-		/// <param name="target">The target document number.
-		/// </param>
-		/// <returns> true iff there is such a match.
-		/// <p>Behaves as if written: <pre>
+		/// 
+		/// <p>
+		/// The behavior of this method is undefined if the target specified is
+		/// less than or equal to the current value of {@link #Doc()}.
+		/// <p>
+		/// Behaves as if written:
+		/// <pre>
 		/// boolean skipTo(int target) {
 		/// do {
-		/// if (!Next())
+		/// if (!next())
 		/// return false;
 		/// } while (target > doc());
 		/// return true;
 		/// }
-		/// </pre>Most implementations are considerably more efficient than that.
+		/// </pre>
+		/// Most implementations are considerably more efficient than that.
+		/// </p>
+		/// 
+		/// <p>
+		/// When this method is used the {@link #Explain(int)} method should not
+		/// be used.
+		/// </p>
+		/// 
+		/// </summary>
+		/// <param name="target">The target document number.
+		/// </param>
+		/// <returns> true iff there is such a match.
 		/// </returns>
+		/// <seealso cref="BooleanQuery.setAllowDocsOutOfOrder">
+		/// </seealso>
 		public abstract bool SkipTo(int target);
 		
 		/// <summary>Returns an explanation of the score for a document.

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searchable.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs Tue Jun 24 19:51:24 2008
@@ -18,6 +18,8 @@
 using System;
 
 using Document = Lucene.Net.Documents.Document;
+using FieldSelector = Lucene.Net.Documents.FieldSelector;
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
 using IndexReader = Lucene.Net.Index.IndexReader;
 using Term = Lucene.Net.Index.Term;
 
@@ -69,7 +71,7 @@
         /// <summary>Expert: Returns the number of documents containing <code>term</code>.
         /// Called by search code to compute term weights.
         /// </summary>
-        /// <seealso cref="IndexReader#docFreq(Term)">
+		/// <seealso cref="IndexReader.DocFreq(Term)">
         /// </seealso>
         int DocFreq(Term term);
 		
@@ -82,7 +84,7 @@
         /// <summary>Expert: Returns one greater than the largest possible document number.
         /// Called by search code to compute term weights.
         /// </summary>
-        /// <seealso cref="IndexReader#maxDoc()">
+		/// <seealso cref="IndexReader.MaxDoc()">
         /// </seealso>
         int MaxDoc();
 		
@@ -97,13 +99,46 @@
         /// <throws>  BooleanQuery.TooManyClauses </throws>
         TopDocs Search(Weight weight, Filter filter, int n);
 		
-        /// <summary>Expert: Returns the stored fields of document <code>i</code>.
-        /// Called by {@link HitCollector} implementations.
-        /// </summary>
-        /// <seealso cref="IndexReader#document(int)">
-        /// </seealso>
+		/// <summary>Expert: Returns the stored fields of document <code>i</code>.
+		/// Called by {@link HitCollector} implementations.
+		/// </summary>
+		/// <seealso cref="IndexReader.Document(int)">
+		/// </seealso>
+		/// <throws>  CorruptIndexException if the index is corrupt </throws>
+		/// <throws>  IOException if there is a low-level IO error </throws>
         Document Doc(int i);
 		
+		/// <summary> Get the {@link Lucene.Net.Documents.Document} at the <code>n</code><sup>th</sup> position. The {@link Lucene.Net.Documents.FieldSelector}
+		/// may be used to determine what {@link Lucene.Net.Documents.Field}s to load and how they should be loaded.
+		/// 
+		/// <b>NOTE:</b> If the underlying Reader (more specifically, the underlying <code>FieldsReader</code>) is closed before the lazy {@link Lucene.Net.Documents.Field} is
+		/// loaded an exception may be thrown.  If you want the value of a lazy {@link Lucene.Net.Documents.Field} to be available after closing you must
+		/// explicitly load it or fetch the Document again with a new loader.
+		/// 
+		/// 
+		/// </summary>
+		/// <param name="n">Get the document at the <code>n</code><sup>th</sup> position
+		/// </param>
+		/// <param name="fieldSelector">The {@link Lucene.Net.Documents.FieldSelector} to use to determine what Fields should be loaded on the Document.  May be null, in which case all Fields will be loaded.
+		/// </param>
+		/// <returns> The stored fields of the {@link Lucene.Net.Documents.Document} at the nth position
+		/// </returns>
+		/// <throws>  CorruptIndexException if the index is corrupt </throws>
+		/// <throws>  IOException if there is a low-level IO error </throws>
+		/// <summary> 
+		/// </summary>
+		/// <seealso cref="IndexReader.Document(int, FieldSelector)">
+		/// </seealso>
+		/// <seealso cref="Lucene.Net.Documents.Fieldable">
+		/// </seealso>
+		/// <seealso cref="Lucene.Net.Documents.FieldSelector">
+		/// </seealso>
+		/// <seealso cref="Lucene.Net.Documents.SetBasedFieldSelector">
+		/// </seealso>
+		/// <seealso cref="Lucene.Net.Documents.LoadFirstFieldSelector">
+		/// </seealso>
+		Document Doc(int n, FieldSelector fieldSelector);
+		
         /// <summary>Expert: called to re-write queries into primitive queries.</summary>
         /// <throws>  BooleanQuery.TooManyClauses </throws>
         Query Rewrite(Query query);

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searcher.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searcher.cs Tue Jun 24 19:51:24 2008
@@ -17,8 +17,9 @@
 
 using System;
 
-using Term = Lucene.Net.Index.Term;
 using Document = Lucene.Net.Documents.Document;
+using CorruptIndexException = Lucene.Net.Index.CorruptIndexException;
+using Term = Lucene.Net.Index.Term;
 
 namespace Lucene.Net.Search
 {
@@ -212,5 +213,6 @@
 		abstract public Explanation Explain(Weight weight, int doc);
 		abstract public TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
 		/* End patch for GCJ bug #15411. */
+		public abstract Lucene.Net.Documents.Document Doc(int param1, Lucene.Net.Documents.FieldSelector param2);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Similarity.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Similarity.cs Tue Jun 24 19:51:24 2008
@@ -17,8 +17,6 @@
 
 using System;
 
-using IndexReader = Lucene.Net.Index.IndexReader;
-using IndexWriter = Lucene.Net.Index.IndexWriter;
 using Term = Lucene.Net.Index.Term;
 using SmallFloat = Lucene.Net.Util.SmallFloat;
 
@@ -350,9 +348,11 @@
 		/// method usually return smaller values when <code>numTokens</code> is large,
 		/// and larger values when <code>numTokens</code> is small.
 		/// 
-		/// <p>That these values are computed under {@link
-		/// IndexWriter#AddDocument(Lucene.Net.Documents.Document)} and stored then using
-		/// {@link #EncodeNorm(float)}.  Thus they have limited precision, and documents
+		/// <p>That these values are computed under 
+		/// {@link Lucene.Net.Index.IndexWriter#AddDocument(Lucene.Net.Documents.Document)} 
+		/// and stored then using
+		/// {@link #EncodeNorm(float)}.  
+		/// Thus they have limited precision, and documents
 		/// must be re-indexed if this method is altered.
 		/// 
 		/// </summary>
@@ -364,7 +364,7 @@
 		/// <returns> a normalization factor for hits on this field of this document
 		/// 
 		/// </returns>
-		/// <seealso cref="Lucene.Net.Documents.Field#SetBoost(float)">
+		/// <seealso cref="Lucene.Net.Documents.Field.SetBoost(float)">
 		/// </seealso>
 		public abstract float LengthNorm(System.String fieldName, int numTokens);
 		
@@ -436,7 +436,7 @@
 		/// when it is large.
 		/// 
 		/// </summary>
-		/// <seealso cref="PhraseQuery#SetSlop(int)">
+		/// <seealso cref="PhraseQuery.SetSlop(int)">
 		/// </seealso>
 		/// <param name="distance">the edit distance of this sloppy phrase match
 		/// </param>
@@ -541,6 +541,30 @@
 		/// <returns> a score factor based on term overlap with the query
 		/// </returns>
 		public abstract float Coord(int overlap, int maxOverlap);
+		
+		
+		/// <summary> Calculate a scoring factor based on the data in the payload.  Overriding implementations
+		/// are responsible for interpreting what is in the payload.  Lucene makes no assumptions about
+		/// what is in the byte array.
+		/// <p>
+		/// The default implementation returns 1.
+		/// 
+		/// </summary>
+		/// <param name="fieldName">The fieldName of the term this payload belongs to
+		/// </param>
+		/// <param name="payload">The payload byte array to be scored
+		/// </param>
+		/// <param name="offset">The offset into the payload array
+		/// </param>
+		/// <param name="length">The length in the array
+		/// </param>
+		/// <returns> An implementation dependent float to be used as a scoring factor 
+		/// </returns>
+		public virtual float ScorePayload(System.String fieldName, byte[] payload, int offset, int length)
+		{
+			//Do nothing
+			return 1;
+		}
 		static Similarity()
 		{
 			{

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SloppyPhraseScorer.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SloppyPhraseScorer.cs Tue Jun 24 19:51:24 2008
@@ -24,40 +24,79 @@
 	
 	sealed class SloppyPhraseScorer : PhraseScorer
 	{
+		private class AnonymousClassComparator : System.Collections.IComparer
+		{
+			public AnonymousClassComparator(SloppyPhraseScorer enclosingInstance)
+			{
+				InitBlock(enclosingInstance);
+			}
+			private void  InitBlock(SloppyPhraseScorer enclosingInstance)
+			{
+				this.enclosingInstance = enclosingInstance;
+			}
+			private SloppyPhraseScorer enclosingInstance;
+			public SloppyPhraseScorer Enclosing_Instance
+			{
+				get
+				{
+					return enclosingInstance;
+				}
+				
+			}
+			public int Compare(System.Object x, System.Object y)
+			{
+				return ((PhrasePositions) y).offset - ((PhrasePositions) x).offset;
+			}
+		}
 		private int slop;
+		private PhrasePositions[] repeats;
+		private bool checkedRepeats;
 		
-		internal SloppyPhraseScorer(Weight weight, TermPositions[] tps, int[] positions, Similarity similarity, int slop, byte[] norms) : base(weight, tps, positions, similarity, norms)
+		internal SloppyPhraseScorer(Weight weight, TermPositions[] tps, int[] offsets, Similarity similarity, int slop, byte[] norms) : base(weight, tps, offsets, similarity, norms)
 		{
 			this.slop = slop;
 		}
 		
+		/// <summary> Score a candidate doc for all slop-valid position-combinations (matches) 
+		/// encountered while traversing/hopping the PhrasePositions.
+		/// <br> The score contribution of a match depends on the distance: 
+		/// <br> - highest score for distance=0 (exact match).
+		/// <br> - score gets lower as distance gets higher.
+		/// <br>Example: for query "a b"~2, a document "x a b a y" can be scored twice: 
+		/// once for "a b" (distance=0), and once for "b a" (distance=2).
+		/// <br>Pssibly not all valid combinations are encountered, because for efficiency  
+		/// we always propagate the least PhrasePosition. This allows to base on 
+		/// PriorityQueue and move forward faster. 
+		/// As result, for example, document "a b c b a"
+		/// would score differently for queries "a b c"~4 and "c b a"~4, although 
+		/// they really are equivalent. 
+		/// Similarly, for doc "a b c b a f g", query "c b"~2 
+		/// would get same score as "g f"~2, although "c b"~2 could be matched twice.
+		/// We may want to fix this in the future (currently not, for performance reasons).
+		/// </summary>
 		protected internal override float PhraseFreq()
 		{
-			pq.Clear();
-			int end = 0;
-			for (PhrasePositions pp = first; pp != null; pp = pp.next)
-			{
-				pp.FirstPosition();
-				if (pp.position > end)
-					end = pp.position;
-				pq.Put(pp); // build pq from list
-			}
+			int end = InitPhrasePositions();
 			
 			float freq = 0.0f;
-			bool done = false;
-			do 
+			bool done = (end < 0);
+			while (!done)
 			{
 				PhrasePositions pp = (PhrasePositions) pq.Pop();
 				int start = pp.position;
 				int next = ((PhrasePositions) pq.Top()).position;
-				for (int pos = start; pos <= next; pos = pp.position)
+				
+				bool tpsDiffer = true;
+				for (int pos = start; pos <= next || !tpsDiffer; pos = pp.position)
 				{
-					start = pos; // advance pp to min window
+					if (pos <= next && tpsDiffer)
+						start = pos; // advance pp to min window
 					if (!pp.NextPosition())
 					{
 						done = true; // ran out of a term -- done
 						break;
 					}
+					tpsDiffer = !pp.repeats || TermPositionsDiffer(pp);
 				}
 				
 				int matchLength = end - start;
@@ -68,9 +107,127 @@
 					end = pp.position;
 				pq.Put(pp); // restore pq
 			}
-			while (!done);
 			
 			return freq;
 		}
+		
+		
+		/// <summary> Init PhrasePositions in place.
+		/// There is a one time initializatin for this scorer:
+		/// <br>- Put in repeats[] each pp that has another pp with same position in the doc.
+		/// <br>- Also mark each such pp by pp.repeats = true.
+		/// <br>Later can consult with repeats[] in termPositionsDiffer(pp), making that check efficient.
+		/// In particular, this allows to score queries with no repetiotions with no overhead due to this computation.
+		/// <br>- Example 1 - query with no repetitions: "ho my"~2
+		/// <br>- Example 2 - query with repetitions: "ho my my"~2
+		/// <br>- Example 3 - query with repetitions: "my ho my"~2
+		/// <br>Init per doc w/repeats in query, includes propagating some repeating pp's to avoid false phrase detection.  
+		/// </summary>
+		/// <returns> end (max position), or -1 if any term ran out (i.e. done) 
+		/// </returns>
+		/// <throws>  IOException  </throws>
+		private int InitPhrasePositions()
+		{
+			int end = 0;
+			
+			// no repeats at all (most common case is also the simplest one)
+			if (checkedRepeats && repeats == null)
+			{
+				// build queue from list
+				pq.Clear();
+				for (PhrasePositions pp = first; pp != null; pp = pp.next)
+				{
+					pp.FirstPosition();
+					if (pp.position > end)
+						end = pp.position;
+					pq.Put(pp); // build pq from list
+				}
+				return end;
+			}
+			
+			// position the pp's
+			for (PhrasePositions pp = first; pp != null; pp = pp.next)
+				pp.FirstPosition();
+			
+			// one time initializatin for this scorer
+			if (!checkedRepeats)
+			{
+				checkedRepeats = true;
+				// check for repeats
+				System.Collections.Hashtable m = null;
+				for (PhrasePositions pp = first; pp != null; pp = pp.next)
+				{
+					int tpPos = pp.position + pp.offset;
+					for (PhrasePositions pp2 = pp.next; pp2 != null; pp2 = pp2.next)
+					{
+						int tpPos2 = pp2.position + pp2.offset;
+						if (tpPos2 == tpPos)
+						{
+							if (m == null)
+							{
+								m = new System.Collections.Hashtable();
+							}
+							pp.repeats = true;
+							pp2.repeats = true;
+							m[pp] = null;
+							m[pp2] = null;
+						}
+					}
+				}
+				if (m != null)
+				{
+					repeats = (PhrasePositions[]) (new System.Collections.ArrayList(m.Keys).ToArray(typeof(PhrasePositions)));
+				}
+			}
+			
+			// with repeats must advance some repeating pp's so they all start with differing tp's       
+			if (repeats != null)
+			{
+				// must propagate higher offsets first (otherwise might miss matches).
+				System.Array.Sort(repeats, new AnonymousClassComparator(this));
+				// now advance them
+				for (int i = 0; i < repeats.Length; i++)
+				{
+					PhrasePositions pp = repeats[i];
+					while (!TermPositionsDiffer(pp))
+					{
+						if (!pp.NextPosition())
+							return - 1; // ran out of a term -- done  
+					}
+				}
+			}
+			
+			// build queue from list
+			pq.Clear();
+			for (PhrasePositions pp = first; pp != null; pp = pp.next)
+			{
+				if (pp.position > end)
+					end = pp.position;
+				pq.Put(pp); // build pq from list
+			}
+			
+			return end;
+		}
+		
+		// disalow two pp's to have the same tp position, so that same word twice 
+		// in query would go elswhere in the matched doc
+		private bool TermPositionsDiffer(PhrasePositions pp)
+		{
+			// efficiency note: a more efficient implemention could keep a map between repeating 
+			// pp's, so that if pp1a, pp1b, pp1c are repeats term1, and pp2a, pp2b are repeats 
+			// of term2, pp2a would only be checked against pp2b but not against pp1a, pp1b, pp1c. 
+			// However this would complicate code, for a rather rare case, so choice is to compromise here.
+			int tpPos = pp.position + pp.offset;
+			for (int i = 0; i < repeats.Length; i++)
+			{
+				PhrasePositions pp2 = repeats[i];
+				if (pp2 == pp)
+					continue;
+				int tpPos2 = pp2.position + pp2.offset;
+				if (tpPos2 == tpPos)
+					return false;
+			}
+			return true;
+		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Sort.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Sort.cs Tue Jun 24 19:51:24 2008
@@ -30,24 +30,30 @@
 	/// and does not need to be stored (unless you happen to want it back with the
 	/// rest of your document data).  In other words:
 	/// 
-	/// <p><code>document.add (new Fieldable ("byNumber", Integer.toString(x), Fieldable.Store.NO, Fieldable.Index.UN_TOKENIZED));</code></p>
+	/// <p><code>document.add (new Field ("byNumber", Integer.toString(x), Field.Store.NO, Field.Index.UN_TOKENIZED));</code></p>
 	/// 
 	/// 
 	/// <p><h3>Valid Types of Values</h3>
 	/// 
-	/// <p>There are three possible kinds of term values which may be put into
-	/// sorting fields: Integers, Floats, or Strings.  Unless
+	/// <p>There are four possible kinds of term values which may be put into
+	/// sorting fields: Integers, Longs, Floats, or Strings.  Unless
 	/// {@link SortField SortField} objects are specified, the type of value
 	/// in the field is determined by parsing the first term in the field.
 	/// 
 	/// <p>Integer term values should contain only digits and an optional
-	/// preceeding negative sign.  Values must be base 10 and in the range
+	/// preceding negative sign.  Values must be base 10 and in the range
 	/// <code>Integer.MIN_VALUE</code> and <code>Integer.MAX_VALUE</code> inclusive.
 	/// Documents which should appear first in the sort
 	/// should have low value integers, later documents high values
 	/// (i.e. the documents should be numbered <code>1..n</code> where
 	/// <code>1</code> is the first and <code>n</code> the last).
 	/// 
+	/// <p>Long term values should contain only digits and an optional
+	/// preceding negative sign.  Values must be base 10 and in the range
+	/// <code>Long.MIN_VALUE</code> and <code>Long.MAX_VALUE</code> inclusive.
+	/// Documents which should appear first in the sort
+	/// should have low value integers, later documents high values.
+	/// 
 	/// <p>Float term values should conform to values accepted by
 	/// {@link Float Float.valueOf(String)} (except that <code>NaN</code>
 	/// and <code>Infinity</code> are not supported).
@@ -93,7 +99,7 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: Sort.java 472959 2006-11-09 16:21:50Z yonik $
+	/// <version>  $Id: Sort.java 598376 2007-11-26 18:45:39Z dnaber $
 	/// </version>
 	[Serializable]
 	public class Sort

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortComparator.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparator.cs Tue Jun 24 19:51:24 2008
@@ -35,10 +35,9 @@
 	/// 
 	/// <p>Created: Apr 21, 2004 5:08:38 PM
 	/// 
+	/// 
 	/// </summary>
-	/// <author>   Tim Jones
-	/// </author>
-	/// <version>  $Id: SortComparator.java 150541 2004-09-29 15:09:02Z goller $
+	/// <version>  $Id: SortComparator.java 564236 2007-08-09 15:21:19Z gsingers $
 	/// </version>
 	/// <since>   1.4
 	/// </since>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortComparatorSource.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortComparatorSource.cs Tue Jun 24 19:51:24 2008
@@ -26,10 +26,9 @@
 	/// 
 	/// <p>Created: Apr 21, 2004 3:49:28 PM
 	/// 
+	/// 
 	/// </summary>
-	/// <author>   Tim Jones
-	/// </author>
-	/// <version>  $Id: SortComparatorSource.java 413201 2006-06-10 01:23:22Z gsingers $
+	/// <version>  $Id: SortComparatorSource.java 564236 2007-08-09 15:21:19Z gsingers $
 	/// </version>
 	/// <since>   1.4
 	/// </since>
@@ -39,7 +38,7 @@
 		/// <summary> Creates a comparator for the field in the given index.</summary>
 		/// <param name="reader">Index to create comparator for.
 		/// </param>
-		/// <param name="fieldname"> Fieldable to create comparator for.
+		/// <param name="fieldname"> Name of the field to create comparator for.
 		/// </param>
 		/// <returns> Comparator of ScoreDoc objects.
 		/// </returns>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SortField.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SortField.cs Tue Jun 24 19:51:24 2008
@@ -30,7 +30,7 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: SortField.java 472959 2006-11-09 16:21:50Z yonik $
+	/// <version>  $Id: SortField.java 598296 2007-11-26 14:52:01Z mikemccand $
 	/// </version>
 	/// <seealso cref="Sort">
 	/// </seealso>
@@ -70,6 +70,16 @@
 		/// </summary>
 		public const int FLOAT = 5;
 		
+		/// <summary>Sort using term values as encoded Longs.  Sort values are Long and
+		/// lower values are at the front. 
+		/// </summary>
+		public const int LONG = 6;
+		
+		/// <summary>Sort using term values as encoded Doubles.  Sort values are Double and
+		/// lower values are at the front. 
+		/// </summary>
+		public const int DOUBLE = 7;
+		
 		/// <summary>Sort using a custom Comparator.  Sort values are any Comparable and
 		/// sorting is done according to natural order. 
 		/// </summary>
@@ -216,7 +226,7 @@
 		/// <summary>Returns the type of contents in the field.</summary>
 		/// <returns> One of the constants SCORE, DOC, AUTO, STRING, INT or FLOAT.
 		/// </returns>
-		public virtual int GetType()
+		public new virtual int GetType()
 		{
 			return type;
 		}
@@ -259,17 +269,18 @@
 				
 				
 				case CUSTOM:
-					buffer.Append("<custom:\"" + field + "\": " + factory + ">");
+					buffer.Append("<custom:\"").Append(field).Append("\": ").Append(factory).Append('>');
 					break;
 				
 				
-				default:  buffer.Append("\"" + field + "\"");
+				default: 
+					buffer.Append('\"').Append(field).Append('\"');
 					break;
 				
 			}
 			
 			if (locale != null)
-				buffer.Append("(" + locale + ")");
+				buffer.Append('(').Append(locale).Append(')');
 			if (reverse)
 				buffer.Append('!');
 			

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SpanFilter.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilter.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary>Abstract base class providing a mechanism to restrict searches to a subset
+	/// of an index and also maintains and returns position information.
+	/// This is useful if you want to compare the positions from a SpanQuery with the positions of items in
+	/// a filter.  For instance, if you had a SpanFilter that marked all the occurrences of the word "foo" in documents,
+	/// and then you entered a new SpanQuery containing bar, you could not only filter by the word foo, but you could
+	/// then compare position information for post processing.
+	/// </summary>
+	[Serializable]
+	public abstract class SpanFilter:Filter
+	{
+		/// <summary>Returns a SpanFilterResult with true for documents which should be permitted in
+		/// search results, and false for those that should not and Spans for where the true docs match.
+		/// </summary>
+		/// <param name="reader">The {@link Lucene.Net.Index.IndexReader} to load position and bitset information from
+		/// </param>
+		/// <returns> A {@link SpanFilterResult}
+		/// </returns>
+		/// <throws>  java.io.IOException if there was an issue accessing the necessary information </throws>
+		/// <summary> 
+		/// </summary>
+		public abstract SpanFilterResult BitSpans(IndexReader reader);
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilterResult.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SpanFilterResult.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilterResult.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanFilterResult.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Lucene.Net.Search
+{
+	
+	
+	/// <summary>  The results of a SpanQueryFilter.  Wraps the BitSet and the position infomration from the SpanQuery
+	/// 
+	/// <p/>
+	/// NOTE: This API is still experimental and subject to change. 
+	/// 
+	/// 
+	/// </summary>
+	public class SpanFilterResult
+	{
+		private System.Collections.BitArray bits;
+		private System.Collections.IList positions; //Spans spans;
+		
+		/// <summary> </summary>
+		/// <param name="bits">The bits for the Filter
+		/// </param>
+		/// <param name="positions">A List of {@link Lucene.Net.Search.SpanFilterResult.PositionInfo} objects
+		/// </param>
+		public SpanFilterResult(System.Collections.BitArray bits, System.Collections.IList positions)
+		{
+			this.bits = bits;
+			this.positions = positions;
+		}
+		
+		/// <summary> The first entry in the array corresponds to the first "on" bit.
+		/// Entries are increasing by document order
+		/// </summary>
+		/// <returns> A List of PositionInfo objects
+		/// </returns>
+		public virtual System.Collections.IList GetPositions()
+		{
+			return positions;
+		}
+		
+		public virtual System.Collections.BitArray GetBits()
+		{
+			return bits;
+		}
+		
+		
+		
+		public class PositionInfo
+		{
+			private int doc;
+			private System.Collections.IList positions;
+			
+			
+			public PositionInfo(int doc)
+			{
+				this.doc = doc;
+				positions = new System.Collections.ArrayList();
+			}
+			
+			public virtual void  AddPosition(int start, int end)
+			{
+				positions.Add(new StartEnd(start, end));
+			}
+			
+			public virtual int GetDoc()
+			{
+				return doc;
+			}
+			
+			/// <summary> </summary>
+			/// <returns> A List of {@link Lucene.Net.Search.SpanFilterResult.StartEnd} objects
+			/// </returns>
+			public virtual System.Collections.IList GetPositions()
+			{
+				return positions;
+			}
+		}
+		
+		public class StartEnd
+		{
+			private int start;
+			private int end;
+			
+			
+			public StartEnd(int start, int end)
+			{
+				this.start = start;
+				this.end = end;
+			}
+			
+			/// <summary> </summary>
+			/// <returns> The end position of this match
+			/// </returns>
+			public virtual int GetEnd()
+			{
+				return end;
+			}
+			
+			/// <summary> The Start position</summary>
+			/// <returns> The start position of this match
+			/// </returns>
+			public virtual int GetStart()
+			{
+				return start;
+			}
+		}
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanQueryFilter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SpanQueryFilter.cs?rev=671402&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanQueryFilter.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SpanQueryFilter.cs Tue Jun 24 19:51:24 2008
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+using IndexReader = Lucene.Net.Index.IndexReader;
+using SpanQuery = Lucene.Net.Search.Spans.SpanQuery;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary> Constrains search results to only match those which also match a provided
+	/// query. Also provides position information about where each document matches
+	/// at the cost of extra space compared with the QueryWrapperFilter.
+	/// There is an added cost to this above what is stored in a {@link QueryWrapperFilter}.  Namely,
+	/// the position information for each matching document is stored.
+	/// <p/>
+	/// This filter does not cache.  See the {@link Lucene.Net.Search.CachingSpanFilter} for a wrapper that
+	/// caches.
+	/// 
+	/// 
+	/// </summary>
+	/// <version>  $Id:$
+	/// </version>
+	[Serializable]
+	public class SpanQueryFilter : SpanFilter
+	{
+		protected internal SpanQuery query;
+		
+		protected internal SpanQueryFilter()
+		{
+		}
+		
+		/// <summary>Constructs a filter which only matches documents matching
+		/// <code>query</code>.
+		/// </summary>
+		/// <param name="query">The {@link Lucene.Net.Search.Spans.SpanQuery} to use as the basis for the Filter.
+		/// </param>
+		public SpanQueryFilter(SpanQuery query)
+		{
+			this.query = query;
+		}
+		
+		public override System.Collections.BitArray Bits(IndexReader reader)
+		{
+			SpanFilterResult result = BitSpans(reader);
+			return result.GetBits();
+		}
+		
+		
+		public override SpanFilterResult BitSpans(IndexReader reader)
+		{
+			
+			System.Collections.BitArray bits = new System.Collections.BitArray((reader.MaxDoc() % 64 == 0 ? reader.MaxDoc() / 64 : reader.MaxDoc() / 64 + 1) * 64);
+			Lucene.Net.Search.Spans.Spans spans = query.GetSpans(reader);
+			System.Collections.IList tmp = new System.Collections.ArrayList(20);
+			int currentDoc = - 1;
+			SpanFilterResult.PositionInfo currentInfo = null;
+			while (spans.Next())
+			{
+				int doc = spans.Doc();
+				bits.Set(doc, true);
+				if (currentDoc != doc)
+				{
+					currentInfo = new SpanFilterResult.PositionInfo(doc);
+					tmp.Add(currentInfo);
+					currentDoc = doc;
+				}
+				currentInfo.AddPosition(spans.Start(), spans.End());
+			}
+			return new SpanFilterResult(bits, tmp);
+		}
+		
+		
+		public virtual SpanQuery GetQuery()
+		{
+			return query;
+		}
+		
+		public override System.String ToString()
+		{
+			return "QueryWrapperFilter(" + query + ")";
+		}
+		
+		public  override bool Equals(System.Object o)
+		{
+			return o is SpanQueryFilter && this.query.Equals(((SpanQueryFilter) o).query);
+		}
+		
+		public override int GetHashCode()
+		{
+			return query.GetHashCode() ^ unchecked((int) 0x923F64B9);
+		}
+	}
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansOrdered.cs Tue Jun 24 19:51:24 2008
@@ -218,9 +218,9 @@
 			{
 				
 				System.Diagnostics.Debug.Assert(subSpansByDoc [i].Doc() == maxDoc,
-					" NearSpansOrdered.toSameDoc() spans " + subSpansByDoc[0]
-								+ "\n at doc " + subSpansByDoc[i].Doc()
-								+ ", but should be at " + maxDoc);
+					" NearSpansOrdered.toSameDoc() spans " + subSpansByDoc[0]
+								+ "\n at doc " + subSpansByDoc[i].Doc()
+								+ ", but should be at " + maxDoc);
 			}
 			inSameDoc = true;
 			return true;
@@ -241,7 +241,7 @@
 			int start1 = spans1.Start();
 			int start2 = spans2.Start();
 			/* Do not call DocSpansOrdered(int,int,int,int) to avoid invoking .end() : */
-			return (start1 == start2)?(spans1.End() < spans2.End()):(start1 < start2);
+			return (start1 == start2) ? (spans1.End() < spans2.End()) : (start1 < start2);
 		}
 		
 		/// <summary>Like {@link #DocSpansOrdered(Spans,Spans)}, but use the spans
@@ -342,7 +342,7 @@
 		
 		public override System.String ToString()
 		{
-			return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime?"START":(more?(Doc() + ":" + Start() + "-" + End()):"END"));
+			return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime ? "START" : (more ? (Doc() + ":" + Start() + "-" + End()) : "END"));
 		}
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpansUnordered.cs Tue Jun 24 19:51:24 2008
@@ -294,7 +294,7 @@
 		
 		public override System.String ToString()
 		{
-			return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime?"START":(more?(Doc() + ":" + Start() + "-" + End()):"END"));
+			return GetType().FullName + "(" + query.ToString() + ")@" + (firstTime ? "START" : (more ? (Doc() + ":" + Start() + "-" + End()) : "END"));
 		}
 		
 		private void  InitList(bool next)

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/Package.html?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Package.html Tue Jun 24 19:51:24 2008
@@ -1,76 +1,76 @@
-<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head></head>
-<body>
-The calculus of spans.
-
-<p>A span is a <code>&lt;doc,startPosition,endPosition&gt;</code> tuple.</p>
-
-<p>The following span query operators are implemented:
-
-<ul>
-
-<li>A <a href="SpanTermQuery.html">SpanTermQuery</a> matches all spans
-containing a particular <a href="../../index/Term.html">Term</a>.</li>
-
-<li> A <a href="SpanNearQuery.html">SpanNearQuery</a> matches spans
-which occur near one another, and can be used to implement things like
-phrase search (when constructed from <a
-href="SpanTermQuery.html">SpanTermQueries</a>) and inter-phrase
-proximity (when constructed from other <a
-href="SpanNearQuery.html">SpanNearQueries</a>).</li>
-
-<li>A <a href="SpanOrQuery.html">SpanOrQuery</a> merges spans from a
-number of other <a href="SpanQuery.html">SpanQueries</a>.</li>
-
-<li>A <a href="SpanNotQuery.html">SpanNotQuery</a> removes spans
-matching one <a href="SpanQuery.html">SpanQuery</a> which overlap
-another.  This can be used, e.g., to implement within-paragraph
-search.</li>
-
-<li>A <a href="SpanFirstQuery.html">SpanFirstQuery</a> matches spans
-matching <code>q</code> whose end position is less than
-<code>n</code>.  This can be used to constrain matches to the first
-part of the document.</li>
-
-</ul>
-
-In all cases, output spans are minimally inclusive.  In other words, a
-span formed by matching a span in x and y starts at the lesser of the
-two starts and ends at the greater of the two ends.
-</p>
-
-<p>For example, a span query which matches "John Kerry" within ten
-words of "George Bush" within the first 100 words of the document
-could be constructed with:
-<pre>
-SpanQuery john   = new SpanTermQuery(new Term("content", "john"));
-SpanQuery kerry  = new SpanTermQuery(new Term("content", "kerry"));
-SpanQuery george = new SpanTermQuery(new Term("content", "george"));
-SpanQuery bush   = new SpanTermQuery(new Term("content", "bush"));
-
-SpanQuery johnKerry =
-   new SpanNearQuery(new SpanQuery[] {john, kerry}, 0, true);
-
-SpanQuery georgeBush =
-   new SpanNearQuery(new SpanQuery[] {george, bush}, 0, true);
-
-SpanQuery johnKerryNearGeorgeBush =
-   new SpanNearQuery(new SpanQuery[] {johnKerry, georgeBush}, 10, false);
-
-SpanQuery johnKerryNearGeorgeBushAtStart =
-   new SpanFirstQuery(johnKerryNearGeorgeBush, 100);
-</pre>
-
-<p>Span queries may be freely intermixed with other Lucene queries.
-So, for example, the above query can be restricted to documents which
-also use the word "iraq" with:
-
-<pre>
-Query query = new BooleanQuery();
-query.add(johnKerryNearGeorgeBushAtStart, true, false);
-query.add(new TermQuery("content", "iraq"), true, false);
-</pre>
-
-</body>
-</html>
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head></head>
+<body>
+The calculus of spans.
+
+<p>A span is a <code>&lt;doc,startPosition,endPosition&gt;</code> tuple.</p>
+
+<p>The following span query operators are implemented:
+
+<ul>
+
+<li>A <a href = "SpanTermQuery.html">SpanTermQuery</a> matches all spans
+containing a particular <a href = "index/Term.html">Term</a>.</li>
+
+<li> A <a href = "SpanNearQuery.html">SpanNearQuery</a> matches spans
+which occur near one another, and can be used to implement things like
+phrase search (when constructed from <a
+href="SpanTermQuery.html">SpanTermQueries</a>) and inter-phrase
+proximity (when constructed from other <a
+href="SpanNearQuery.html">SpanNearQueries</a>).</li>
+
+<li>A <a href = "SpanOrQuery.html">SpanOrQuery</a> merges spans from a
+number of other <a href = "SpanQuery.html">SpanQueries</a>.</li>
+
+<li>A <a href = "SpanNotQuery.html">SpanNotQuery</a> removes spans
+matching one <a href = "SpanQuery.html">SpanQuery</a> which overlap
+another.  This can be used, e.g., to implement within-paragraph
+search.</li>
+
+<li>A <a href = "SpanFirstQuery.html">SpanFirstQuery</a> matches spans
+matching <code>q</code> whose end position is less than
+<code>n</code>.  This can be used to constrain matches to the first
+part of the document.</li>
+
+</ul>
+
+In all cases, output spans are minimally inclusive.  In other words, a
+span formed by matching a span in x and y starts at the lesser of the
+two starts and ends at the greater of the two ends.
+</p>
+
+<p>For example, a span query which matches "John Kerry" within ten
+words of "George Bush" within the first 100 words of the document
+could be constructed with:
+<pre>
+SpanQuery john   = new SpanTermQuery(new Term("content", "john"));
+SpanQuery kerry  = new SpanTermQuery(new Term("content", "kerry"));
+SpanQuery george = new SpanTermQuery(new Term("content", "george"));
+SpanQuery bush   = new SpanTermQuery(new Term("content", "bush"));
+
+SpanQuery johnKerry =
+   new SpanNearQuery(new SpanQuery[] {john, kerry}, 0, true);
+
+SpanQuery georgeBush =
+   new SpanNearQuery(new SpanQuery[] {george, bush}, 0, true);
+
+SpanQuery johnKerryNearGeorgeBush =
+   new SpanNearQuery(new SpanQuery[] {johnKerry, georgeBush}, 10, false);
+
+SpanQuery johnKerryNearGeorgeBushAtStart =
+   new SpanFirstQuery(johnKerryNearGeorgeBush, 100);
+</pre>
+
+<p>Span queries may be freely intermixed with other Lucene queries.
+So, for example, the above query can be restricted to documents which
+also use the word "iraq" with:
+
+<pre>
+Query query = new BooleanQuery();
+query.add(johnKerryNearGeorgeBushAtStart, true, false);
+query.add(new TermQuery("content", "iraq"), true, false);
+</pre>
+
+</body>
+</html>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanScorer.cs?rev=671402&r1=671401&r2=671402&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanScorer.cs Tue Jun 24 19:51:24 2008
@@ -17,29 +17,29 @@
 
 using System;
 
-using Weight = Lucene.Net.Search.Weight;
-using Scorer = Lucene.Net.Search.Scorer;
 using Explanation = Lucene.Net.Search.Explanation;
+using Scorer = Lucene.Net.Search.Scorer;
 using Similarity = Lucene.Net.Search.Similarity;
+using Weight = Lucene.Net.Search.Weight;
 
 namespace Lucene.Net.Search.Spans
 {
 	
-	
+	/// <summary> Public for extension only.</summary>
 	class SpanScorer : Scorer
 	{
-		private Spans spans;
-		private Weight weight;
-		private byte[] norms;
-		private float value_Renamed;
+		protected internal Spans spans;
+		protected internal Weight weight;
+		protected internal byte[] norms;
+		protected internal float value_Renamed;
 		
-		private bool firstTime = true;
-		private bool more = true;
+		protected internal bool firstTime = true;
+		protected internal bool more = true;
 		
-		private int doc;
-		private float freq;
+		protected internal int doc;
+		protected internal float freq;
 		
-		internal SpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms) : base(similarity)
+		protected internal SpanScorer(Spans spans, Weight weight, Similarity similarity, byte[] norms) : base(similarity)
 		{
 			this.spans = spans;
 			this.norms = norms;
@@ -77,7 +77,7 @@
 			return SetFreqCurrentDoc();
 		}
 		
-		private bool SetFreqCurrentDoc()
+		protected internal virtual bool SetFreqCurrentDoc()
 		{
 			if (!more)
 			{



Mime
View raw message