lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r411501 [21/30] - in /incubator/lucene.net/trunk/C#/src: ./ Demo/DeleteFiles/ Demo/DemoLib/ Demo/DemoLib/HTML/ Demo/IndexFiles/ Demo/IndexHtml/ Demo/SearchFiles/ Lucene.Net/ Lucene.Net/Analysis/ Lucene.Net/Analysis/Standard/ Lucene.Net/Docu...
Date Sun, 04 Jun 2006 02:41:25 GMT
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Searchable.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Searchable.cs?rev=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,17 +13,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using Document = Lucene.Net.Documents.Document;
 using IndexReader = Lucene.Net.Index.IndexReader;
 using Term = Lucene.Net.Index.Term;
+
 namespace Lucene.Net.Search
 {
 	
 	/// <summary>The interface for search implementations.
 	/// 
-	/// <p>Implementations provide search over a single index, over multiple
+	/// <p>Searchable is the abstract network protocol for searching. 
+	/// Implementations provide search over a single index, over multiple
 	/// indices, and over indices on remote servers.
+	/// 
+	/// <p>Queries, filters and sort criteria are designed to be compact so that
+	/// they may be efficiently passed to a remote index, with only the top-scoring
+	/// hits being returned, rather than every non-zero scoring hit.
 	/// </summary>
 	
     public interface Searchable
@@ -32,6 +39,7 @@
         /// 
         /// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero
         /// scoring document.
+        /// <br>HitCollector-based access to remote indexes is discouraged.
         /// 
         /// <p>Applications should only use this if they need <i>all</i> of the
         /// matching documents.  The high-level search API ({@link
@@ -45,8 +53,19 @@
         /// </param>
         /// <param name="results">to receive hits
         /// </param>
+        /// <throws>  BooleanQuery.TooManyClauses </throws>
+        /// <summary> 
+        /// </summary>
+        /// <deprecated>
+        /// </deprecated>
         void  Search(Query query, Filter filter, HitCollector results);
-		
+
+        /// <summary>Expert: Low-level search implementation.
+        /// Identical to {@link #Search(Query, Filter, HitCollector)}, but takes
+        /// a Weight instead of a query.
+        /// </summary>
+        void  Search(Weight weight, Filter filter, HitCollector results);
+
         /// <summary>Frees resources associated with this Searcher.
         /// Be careful not to call this method while you are still using objects
         /// like {@link Hits}.
@@ -56,14 +75,20 @@
         /// <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);
 		
+        /// <summary>Expert: For each term in the terms array, calculates the number of
+        /// documents containing <code>term</code>. Returns an array with these
+        /// document frequencies. Used to minimize number of remote calls.
+        /// </summary>
+        int[] DocFreqs(Term[] terms);
+		
         /// <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();
 		
@@ -75,16 +100,28 @@
         /// <p>Applications should usually call {@link Searcher#Search(Query)} or
         /// {@link Searcher#Search(Query,Filter)} instead.
         /// </summary>
+        /// <throws>  BooleanQuery.TooManyClauses </throws>
+        /// <summary> 
+        /// </summary>
+        /// <deprecated>
+        /// </deprecated>
         TopDocs Search(Query query, Filter filter, int n);
 		
+        /// <summary>Expert: Low-level search implementation.
+        /// Identical to {@link #Search(Query, Filter, int)}, but takes
+        /// a Weight instead of a query.
+        /// </summary>
+        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 cref="IndexReader#document(int)">
         /// </seealso>
         Document Doc(int i);
 		
-        /// <summary>Expert: called to re-write queries into primitive queries. </summary>
+        /// <summary>Expert: called to re-write queries into primitive queries.</summary>
+        /// <throws>  BooleanQuery.TooManyClauses </throws>
         Query Rewrite(Query query);
 		
         /// <summary>Returns an Explanation that describes how <code>doc</code> scored against
@@ -95,8 +132,14 @@
         /// Computing an explanation is as expensive as executing the query over the
         /// entire index.
         /// </summary>
+        /// <throws>  BooleanQuery.TooManyClauses </throws>
         Explanation Explain(Query query, int doc);
 		
+        /// <summary> Identical to {@link #Search(Query, Filter, HitCollector)}, but takes
+        /// a Weight instead of a query.
+        /// </summary>
+        Explanation Explain(Weight weight, int doc);
+		
         /// <summary>Expert: Low-level search implementation with arbitrary sorting.  Finds
         /// the top <code>n</code> hits for <code>query</code>, applying
         /// <code>filter</code> if non-null, and sorting the hits by the criteria in
@@ -105,6 +148,17 @@
         /// <p>Applications should usually call {@link
         /// Searcher#Search(Query,Filter,Sort)} instead.
         /// </summary>
+        /// <throws>  BooleanQuery.TooManyClauses </throws>
+        /// <summary> 
+        /// </summary>
+        /// <deprecated>
+        /// </deprecated>
         TopFieldDocs Search(Query query, Filter filter, int n, Sort sort);
+		
+        /// <summary>Expert: Low-level search implementation.
+        /// Identical to {@link #Search(Query, Filter, int, Sort)}, but takes
+        /// a Weight instead of a query.
+        /// </summary>
+        TopFieldDocs Search(Weight weight, Filter filter, int n, Sort sort);
     }
 }

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,12 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+using Document = Lucene.Net.Documents.Document;
+using Term = Lucene.Net.Index.Term;
+
 namespace Lucene.Net.Search
 {
 	
 	/// <summary>An abstract base class for search implementations.
-	/// Implements some common utility methods.
+	/// Implements the main search methods.
+	/// 
+	/// <p>Note that you can only access Hits from a Searcher as long as it is
+	/// not yet closed, otherwise an IOException will be thrown. 
 	/// </summary>
 	public abstract class Searcher : Lucene.Net.Search.Searchable
 	{
@@ -30,15 +37,18 @@
 		{
 			similarity = Similarity.GetDefault();
 		}
+		
 		/// <summary>Returns the documents matching <code>query</code>. </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
 		public Hits Search(Query query)
 		{
 			return Search(query, (Filter) null);
 		}
 		
 		/// <summary>Returns the documents matching <code>query</code> and
-		/// <code>filter</code>. 
+		/// <code>filter</code>.
 		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
 		public virtual Hits Search(Query query, Filter filter)
 		{
 			return new Hits(this, query, filter);
@@ -47,6 +57,7 @@
 		/// <summary>Returns documents matching <code>query</code> sorted by
 		/// <code>sort</code>.
 		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
 		public virtual Hits Search(Query query, Sort sort)
 		{
 			return new Hits(this, query, null, sort);
@@ -55,11 +66,26 @@
 		/// <summary>Returns documents matching <code>query</code> and <code>filter</code>,
 		/// sorted by <code>sort</code>.
 		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
 		public virtual Hits Search(Query query, Filter filter, Sort sort)
 		{
 			return new Hits(this, query, filter, sort);
 		}
 		
+		/// <summary>Expert: Low-level search implementation with arbitrary sorting.  Finds
+		/// the top <code>n</code> hits for <code>query</code>, applying
+		/// <code>filter</code> if non-null, and sorting the hits by the criteria in
+		/// <code>sort</code>.
+		/// 
+		/// <p>Applications should usually call {@link
+		/// Searcher#Search(Query,Filter,Sort)} instead.
+		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
+		public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sort sort)
+		{
+			return Search(CreateWeight(query), filter, n, sort);
+		}
+		
 		/// <summary>Lower-level search API.
 		/// 
 		/// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero
@@ -73,18 +99,70 @@
 		/// In other words, the score will not necessarily be a float whose value is
 		/// between 0 and 1.
 		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
 		public virtual void  Search(Query query, HitCollector results)
 		{
 			Search(query, (Filter) null, results);
 		}
 		
+		/// <summary>Lower-level search API.
+		/// 
+		/// <p>{@link HitCollector#Collect(int,float)} is called for every non-zero
+		/// scoring document.
+		/// <br>HitCollector-based access to remote indexes is discouraged.
+		/// 
+		/// <p>Applications should only use this if they need <i>all</i> of the
+		/// matching documents.  The high-level search API ({@link
+		/// Searcher#Search(Query)}) is usually more efficient, as it skips
+		/// non-high-scoring hits.
+		/// 
+		/// </summary>
+		/// <param name="query">to match documents
+		/// </param>
+		/// <param name="filter">if non-null, a bitset used to eliminate some documents
+		/// </param>
+		/// <param name="results">to receive hits
+		/// </param>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
+		public virtual void  Search(Query query, Filter filter, HitCollector results)
+		{
+			Search(CreateWeight(query), filter, results);
+		}
+		
+		/// <summary>Expert: Low-level search implementation.  Finds the top <code>n</code>
+		/// hits for <code>query</code>, applying <code>filter</code> if non-null.
+		/// 
+		/// <p>Called by {@link Hits}.
+		/// 
+		/// <p>Applications should usually call {@link Searcher#Search(Query)} or
+		/// {@link Searcher#Search(Query,Filter)} instead.
+		/// </summary>
+		/// <throws>  BooleanQuery.TooManyClauses </throws>
+		public virtual TopDocs Search(Query query, Filter filter, int n)
+		{
+			return Search(CreateWeight(query), filter, n);
+		}
+		
+		/// <summary>Returns an Explanation that describes how <code>doc</code> scored against
+		/// <code>query</code>.
+		/// 
+		/// <p>This is intended to be used in developing Similarity implementations,
+		/// and, for good performance, should not be displayed with every hit.
+		/// Computing an explanation is as expensive as executing the query over the
+		/// entire index.
+		/// </summary>
+		public virtual Explanation Explain(Query query, int doc)
+		{
+			return Explain(CreateWeight(query), doc);
+		}
+		
 		/// <summary>The Similarity implementation used by this searcher. </summary>
 		private Similarity similarity;
 		
 		/// <summary>Expert: Set the Similarity implementation used by this Searcher.
 		/// 
 		/// </summary>
-		/// <seealso cref="Similarity#SetDefault(Similarity)">
+		/// <seealso cref="Similarity.SetDefault(Similarity)">
 		/// </seealso>
 		public virtual void  SetSimilarity(Similarity similarity)
 		{
@@ -99,14 +177,38 @@
 		{
 			return this.similarity;
 		}
-		public abstract void  Close();
-		public abstract Lucene.Net.Search.Explanation Explain(Lucene.Net.Search.Query param1, int param2);
-		public abstract Lucene.Net.Search.TopFieldDocs Search(Lucene.Net.Search.Query param1, Lucene.Net.Search.Filter param2, int param3, Lucene.Net.Search.Sort param4);
-		public abstract void  Search(Lucene.Net.Search.Query param1, Lucene.Net.Search.Filter param2, Lucene.Net.Search.HitCollector param3);
-		public abstract int DocFreq(Lucene.Net.Index.Term param1);
-		public abstract int MaxDoc();
-		public abstract Lucene.Net.Search.Query Rewrite(Lucene.Net.Search.Query param1);
-		public abstract Lucene.Net.Documents.Document Doc(int param1);
-		public abstract Lucene.Net.Search.TopDocs Search(Lucene.Net.Search.Query param1, Lucene.Net.Search.Filter param2, int param3);
+		
+		/// <summary> creates a weight for <code>query</code></summary>
+		/// <returns> new weight
+		/// </returns>
+		protected internal virtual Weight CreateWeight(Query query)
+		{
+			return query.Weight(this);
+		}
+		
+		// inherit javadoc
+		public virtual int[] DocFreqs(Term[] terms)
+		{
+			int[] result = new int[terms.Length];
+			for (int i = 0; i < terms.Length; i++)
+			{
+				result[i] = DocFreq(terms[i]);
+			}
+			return result;
+		}
+		
+		/* The following abstract methods were added as a workaround for GCJ bug #15411.
+		* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15411
+		*/
+		abstract public void  Search(Weight weight, Filter filter, HitCollector results);
+		abstract public void  Close();
+		abstract public int DocFreq(Term term);
+		abstract public int MaxDoc();
+		abstract public TopDocs Search(Weight weight, Filter filter, int n);
+		abstract public Document Doc(int i);
+		abstract public Query Rewrite(Query query);
+		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. */
 	}
 }

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,15 +13,17 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 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 SmallFloat = Lucene.Net.Util.SmallFloat;
+
 namespace Lucene.Net.Search
 {
 	
-	
 	/// <summary>Expert: Scoring API.
 	/// <p>Subclasses implement search scoring.
 	/// 
@@ -34,14 +36,15 @@
 	/// <td valign="middle" align="center">
 	/// <big><big><big><big><big>&Sigma;</big></big></big></big></big></td>
 	/// <td valign="middle"><small>
-	/// {@link #Tf(int) tf}(t in d) *
-	/// {@link #Idf(Term,Searcher) idf}(t) *
-	/// {@link Field#getBoost getBoost}(t.Field in d) *
-	/// {@link #LengthNorm(String,int) lengthNorm}(t.Field in d)
+	/// ( {@link #Tf(int) tf}(t in d) *
+	/// {@link #Idf(Term,Searcher) idf}(t)^2 *
+	/// {@link Query#getBoost getBoost}(t in q) *
+	/// {@link Field#getBoost getBoost}(t.field in d) *
+	/// {@link #LengthNorm(String,int) lengthNorm}(t.field in d) )
 	/// </small></td>
 	/// <td valign="middle" rowspan="2">&nbsp;*
 	/// {@link #Coord(int,int) coord}(q,d) *
-	/// {@link #QueryNorm(float) queryNorm}(q)
+	/// {@link #QueryNorm(float) queryNorm}(sumOfSqaredWeights)
 	/// </td>
 	/// </tr>
 	/// <tr>
@@ -51,13 +54,36 @@
 	/// </tr>
 	/// </table>
 	/// 
+	/// <p> where
+	/// 
+	/// <table cellpadding="0" cellspacing="0" border="0">
+	/// <tr>
+	/// <td valign="middle" align="right" rowspan="2">sumOfSqaredWeights =<br></td>
+	/// <td valign="middle" align="center">
+	/// <big><big><big><big><big>&Sigma;</big></big></big></big></big></td>
+	/// <td valign="middle"><small>
+	/// ( {@link #Idf(Term,Searcher) idf}(t) *
+	/// {@link Query#getBoost getBoost}(t in q) )^2
+	/// </small></td>
+	/// </tr>
+	/// <tr>
+	/// <td valign="top" align="right">
+	/// <small>t in q</small>
+	/// </td>
+	/// </tr>
+	/// </table>
+	/// 
+	/// <p> Note that the above formula is motivated by the cosine-distance or dot-product
+	/// between document and query vector, which is implemented by {@link DefaultSimilarity}.
+	/// 
 	/// </summary>
-	/// <seealso cref="#SetDefault(Similarity)">
+	/// <seealso cref="SetDefault(Similarity)">
 	/// </seealso>
-	/// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
+	/// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
 	/// </seealso>
-	/// <seealso cref="Searcher#SetSimilarity(Similarity)">
+	/// <seealso cref="Searcher.SetSimilarity(Similarity)">
 	/// </seealso>
+	[Serializable]
 	public abstract class Similarity
 	{
 		/// <summary>The Similarity implementation used by default. </summary>
@@ -67,9 +93,9 @@
 		/// code.
 		/// 
 		/// </summary>
-		/// <seealso cref="Searcher#SetSimilarity(Similarity)">
+		/// <seealso cref="Searcher.SetSimilarity(Similarity)">
 		/// </seealso>
-		/// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
+		/// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
 		/// </seealso>
 		public static void  SetDefault(Similarity similarity)
 		{
@@ -82,9 +108,9 @@
 		/// <p>This is initially an instance of {@link DefaultSimilarity}.
 		/// 
 		/// </summary>
-		/// <seealso cref="Searcher#SetSimilarity(Similarity)">
+		/// <seealso cref="Searcher.SetSimilarity(Similarity)">
 		/// </seealso>
-		/// <seealso cref="IndexWriter#SetSimilarity(Similarity)">
+		/// <seealso cref="IndexWriter.SetSimilarity(Similarity)">
 		/// </seealso>
 		public static Similarity GetDefault()
 		{
@@ -95,37 +121,45 @@
 		private static readonly float[] NORM_TABLE = new float[256];
 		
 		/// <summary>Decodes a normalization factor stored in an index.</summary>
-		/// <seealso cref="#EncodeNorm(float)">
+		/// <seealso cref="EncodeNorm(float)">
 		/// </seealso>
 		public static float DecodeNorm(byte b)
 		{
-			return NORM_TABLE[b & 0xFF];
+			return NORM_TABLE[b & 0xFF]; // & 0xFF maps negative bytes to positive above 127
 		}
 		
-		/// <summary>Computes the normalization value for a Field given the total number of
-		/// terms contained in a Field.  These values, together with Field boosts, are
-		/// stored in an index and multipled into scores for hits on each Field by the
+		/// <summary>Returns a table for decoding normalization bytes.</summary>
+		/// <seealso cref="EncodeNorm(float)">
+		/// </seealso>
+		public static float[] GetNormDecoder()
+		{
+			return NORM_TABLE;
+		}
+		
+		/// <summary>Computes the normalization value for a field given the total number of
+		/// terms contained in a field.  These values, together with field boosts, are
+		/// stored in an index and multipled into scores for hits on each field by the
 		/// search code.
 		/// 
-		/// <p>Matches in longer fields are less precise, so implemenations of this
+		/// <p>Matches in longer fields are less precise, so implementations of this
 		/// 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(Document)} and stored then using
-		/// {#encodeNorm(float)}.  Thus they have limited precision, and documents
+		/// IndexWriter#AddDocument(Lucene.Net.document.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>
-		/// <param name="fieldName">the name of the Field
+		/// <param name="fieldName">the name of the field
 		/// </param>
 		/// <param name="numTokens">the total number of tokens contained in fields named
 		/// <i>fieldName</i> of <i>doc</i>.
 		/// </param>
-		/// <returns> a normalization factor for hits on this Field of this document
+		/// <returns> a normalization factor for hits on this field of this document
 		/// 
 		/// </returns>
-		/// <seealso cref="Field#SetBoost(float)">
+		/// <seealso cref="Field.SetBoost(float)">
 		/// </seealso>
 		public abstract float LengthNorm(System.String fieldName, int numTokens);
 		
@@ -145,7 +179,8 @@
 		
 		/// <summary>Encodes a normalization factor for storage in an index.
 		/// 
-		/// <p>The encoding uses a five-bit exponent and three-bit mantissa, thus
+		/// <p>The encoding uses a three-bit mantissa, a five-bit exponent, and
+		/// the zero-exponent point at 15, thus
 		/// representing values from around 7x10^9 to 2x10^-9 with about one
 		/// significant decimal digit of accuracy.  Zero is also represented.
 		/// Negative numbers are rounded up to zero.  Values too large to represent
@@ -154,53 +189,13 @@
 		/// value.
 		/// 
 		/// </summary>
-		/// <seealso cref="Field#SetBoost(float)">
+		/// <seealso cref="Field.SetBoost(float)">
+		/// </seealso>
+		/// <seealso cref="SmallFloat">
 		/// </seealso>
 		public static byte EncodeNorm(float f)
 		{
-			return FloatToByte(f);
-		}
-		
-		private static float ByteToFloat(byte b)
-		{
-			if (b == 0)
-			// zero is a special case
-				return 0.0f;
-			int mantissa = b & 7;
-			int exponent = (b >> 3) & 31;
-			int bits = ((exponent + (63 - 15)) << 24) | (mantissa << 21);
-            return BitConverter.ToSingle(BitConverter.GetBytes(bits), 0);
-		}
-		
-		private static byte FloatToByte(float f)
-		{
-			if (f < 0.0f)
-			// round negatives up to zero
-				f = 0.0f;
-			
-			if (f == 0.0f)
-			// zero is a special case
-				return 0;
-			
-			int bits = BitConverter.ToInt32(BitConverter.GetBytes(f), 0); // parse float into parts
-			int mantissa = (bits & 0xffffff) >> 21;
-			int exponent = (((bits >> 24) & 0x7f) - 63) + 15;
-			
-			if (exponent > 31)
-			{
-				// overflow: use max value
-				exponent = 31;
-				mantissa = 7;
-			}
-			
-			if (exponent < 0)
-			{
-				// underflow: use min value
-				exponent = 0;
-				mantissa = 1;
-			}
-			
-			return (byte) ((exponent << 3) | mantissa); // pack into a byte
+			return (byte) SmallFloat.FloatToByte315(f);
 		}
 		
 		
@@ -236,7 +231,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>
@@ -250,7 +245,7 @@
 		/// form the initial score for a document.
 		/// 
 		/// <p>Terms and phrases repeated in a document indicate the topic of the
-		/// document, so implemenations of this method usually return larger values
+		/// document, so implementations of this method usually return larger values
 		/// when <code>freq</code> is large, and smaller values when <code>freq</code>
 		/// is small.
 		/// 
@@ -281,7 +276,7 @@
 		/// </returns>
 		public virtual float Idf(Term term, Searcher searcher)
 		{
-			return Idf(searcher.DocFreq(term), searcher.MaxDoc());
+			return Ldf(searcher.DocFreq(term), searcher.MaxDoc());
 		}
 		
 		/// <summary>Computes a score factor for a phrase.
@@ -313,7 +308,7 @@
 		/// then summed to form the initial score for a document.
 		/// 
 		/// <p>Terms that occur in fewer documents are better indicators of topic, so
-		/// implemenations of this method usually return larger values for rare terms,
+		/// implementations of this method usually return larger values for rare terms,
 		/// and smaller values for common terms.
 		/// 
 		/// </summary>
@@ -323,13 +318,13 @@
 		/// </param>
 		/// <returns> a score factor based on the term's document frequency
 		/// </returns>
-		public abstract float Idf(int docFreq, int numDocs);
+		public abstract float Ldf(int docFreq, int numDocs);
 		
 		/// <summary>Computes a score factor based on the fraction of all query terms that a
 		/// document contains.  This value is multiplied into scores.
 		/// 
 		/// <p>The presence of a large portion of the query terms indicates a better
-		/// match with the query, so implemenations of this method usually return
+		/// match with the query, so implementations of this method usually return
 		/// larger values when the ratio between these parameters is large and smaller
 		/// values when the ratio between them is small.
 		/// 
@@ -345,7 +340,7 @@
 		{
 			{
 				for (int i = 0; i < 256; i++)
-					NORM_TABLE[i] = ByteToFloat((byte) i);
+					NORM_TABLE[i] = SmallFloat.Byte315ToFloat((byte) i);
 			}
 		}
 	}

Added: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SimilarityDelegator.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/SimilarityDelegator.cs?rev=411501&view=auto
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SimilarityDelegator.cs (added)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/SimilarityDelegator.cs Sat Jun  3 19:41:13 2006
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+using System;
+
+namespace Lucene.Net.Search
+{
+	
+	/// <summary>Expert: Delegating scoring implementation.  Useful in {@link
+	/// Query#GetSimilarity(Searcher)} implementations, to override only certain
+	/// methods of a Searcher's Similiarty implementation.. 
+	/// </summary>
+	[Serializable]
+	public class SimilarityDelegator : Similarity
+	{
+		
+		private Similarity delegee;
+		
+		/// <summary>Construct a {@link Similarity} that delegates all methods to another.
+		/// 
+		/// </summary>
+		/// <param name="delegee">the Similarity implementation to delegate to
+		/// </param>
+		public SimilarityDelegator(Similarity delegee)
+		{
+			this.delegee = delegee;
+		}
+		
+		public override float LengthNorm(System.String fieldName, int numTerms)
+		{
+			return delegee.LengthNorm(fieldName, numTerms);
+		}
+		
+		public override float QueryNorm(float sumOfSquaredWeights)
+		{
+			return delegee.QueryNorm(sumOfSquaredWeights);
+		}
+		
+		public override float Tf(float freq)
+		{
+			return delegee.Tf(freq);
+		}
+		
+		public override float SloppyFreq(int distance)
+		{
+			return delegee.SloppyFreq(distance);
+		}
+		
+		public override float Ldf(int docFreq, int numDocs)
+		{
+			return delegee.Ldf(docFreq, numDocs);
+		}
+		
+		public override float Coord(int overlap, int maxOverlap)
+		{
+			return delegee.Coord(overlap, maxOverlap);
+		}
+	}
+}
\ No newline at end of file

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,12 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using TermPositions = Lucene.Net.Index.TermPositions;
+
 namespace Lucene.Net.Search
 {
 	
-	sealed class SloppyPhraseScorer:PhraseScorer
+	sealed class SloppyPhraseScorer : PhraseScorer
 	{
 		private int slop;
 		

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,7 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+
 namespace Lucene.Net.Search
 {
 	
@@ -21,21 +23,21 @@
 	/// <summary> Encapsulates sort criteria for returned hits.
 	/// 
 	/// <p>The fields used to determine sort order must be carefully chosen.
-	/// Documents must contain a single term in such a Field,
+	/// Documents must contain a single term in such a field,
 	/// and the value of the term should indicate the document's relative position in
-	/// a given sort order.  The Field must be indexed, but should not be tokenized,
+	/// a given sort order.  The field must be indexed, but should not be tokenized,
 	/// and does not need to be stored (unless you happen to want it back with the
 	/// rest of your document data).  In other words:
 	/// 
-	/// <dl><dd><code>document.add (new Field ("byNumber", Integer.ToString(x), false, true, false));</code>
-	/// </dd></dl>
+	/// <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
 	/// {@link SortField SortField} objects are specified, the type of value
-	/// in the Field is determined by parsing the first term in the Field.
+	/// 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
@@ -68,15 +70,15 @@
 	/// 
 	/// <p>Sorting uses of caches of term values maintained by the
 	/// internal HitQueue(s).  The cache is static and contains an integer
-	/// or float array of length <code>IndexReader.maxDoc()</code> for each Field
+	/// or float array of length <code>IndexReader.maxDoc()</code> for each field
 	/// name for which a sort is performed.  In other words, the size of the
 	/// cache in bytes is:
 	/// 
 	/// <p><code>4 * IndexReader.maxDoc() * (# of different fields actually used to sort)</code>
 	/// 
 	/// <p>For String fields, the cache is larger: in addition to the
-	/// above array, the value of every term in the Field is kept in memory.
-	/// If there are many unique terms in the Field, this could
+	/// above array, the value of every term in the field is kept in memory.
+	/// If there are many unique terms in the field, this could
 	/// be quite large.
 	/// 
 	/// <p>Note that the size of the cache is not affected by how many
@@ -96,15 +98,16 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: Sort.java,v 1.7 2004/04/05 17:23:38 ehatcher Exp $
+	/// <version>  $Id: Sort.java 150618 2004-10-18 22:36:54Z dnaber $
 	/// </version>
 	[Serializable]
 	public class Sort
 	{
 		
-		/// <summary>Represents sorting by computed relevance. Using this sort criteria
-		/// returns the same results as calling {@link Searcher#Search(Query) Searcher#search()}
-		/// without a sort criteria, only with slightly more overhead. 
+		/// <summary> Represents sorting by computed relevance. Using this sort criteria returns
+		/// the same results as calling
+		/// {@link Searcher#Search(Query) Searcher#search()}without a sort criteria,
+		/// only with slightly more overhead.
 		/// </summary>
 		public static readonly Sort RELEVANCE = new Sort();
 		
@@ -114,77 +117,71 @@
 		// internal representation of the sort criteria
 		internal SortField[] fields;
 		
-		
-		/// <summary>Sorts by computed relevance.  This is the same sort criteria as
-		/// calling {@link Searcher#Search(Query) Searcher#search()} without a sort criteria, only with
-		/// slightly more overhead. 
+		/// <summary> Sorts by computed relevance. This is the same sort criteria as calling
+		/// {@link Searcher#Search(Query) Searcher#search()}without a sort criteria,
+		/// only with slightly more overhead.
 		/// </summary>
 		public Sort() : this(new SortField[] {SortField.FIELD_SCORE, SortField.FIELD_DOC})
 		{
 		}
 		
-		
-		/// <summary>Sorts by the terms in <code>Field</code> then by index order (document
-		/// number). The type of value in <code>Field</code> is determined
+		/// <summary> Sorts by the terms in <code>field</code> then by index order (document
+		/// number). The type of value in <code>field</code> is determined
 		/// automatically.
+		/// 
 		/// </summary>
-		/// <seealso cref="SortField#AUTO">
+		/// <seealso cref="SortField.AUTO">
 		/// </seealso>
 		public Sort(System.String field)
 		{
 			SetSort(field, false);
 		}
 		
-		
-		/// <summary>Sorts possibly in reverse by the terms in <code>Field</code> then by
-		/// index order (document number). The type of value in <code>Field</code> is determined
-		/// automatically.
+		/// <summary> Sorts possibly in reverse by the terms in <code>field</code> then by
+		/// index order (document number). The type of value in <code>field</code> is
+		/// determined automatically.
+		/// 
 		/// </summary>
-		/// <seealso cref="SortField#AUTO">
+		/// <seealso cref="SortField.AUTO">
 		/// </seealso>
 		public Sort(System.String field, bool reverse)
 		{
 			SetSort(field, reverse);
 		}
 		
-		
-		/// <summary>Sorts in succession by the terms in each Field.
-		/// The type of value in <code>Field</code> is determined
-		/// automatically.
+		/// <summary> Sorts in succession by the terms in each field. The type of value in
+		/// <code>field</code> is determined automatically.
+		/// 
 		/// </summary>
-		/// <seealso cref="SortField#AUTO">
+		/// <seealso cref="SortField.AUTO">
 		/// </seealso>
 		public Sort(System.String[] fields)
 		{
 			SetSort(fields);
 		}
 		
-		
 		/// <summary>Sorts by the criteria in the given SortField. </summary>
 		public Sort(SortField field)
 		{
 			SetSort(field);
 		}
 		
-		
 		/// <summary>Sorts in succession by the criteria in each SortField. </summary>
 		public Sort(SortField[] fields)
 		{
 			SetSort(fields);
 		}
 		
-		
-		/// <summary>Sets the sort to the terms in <code>Field</code> then by index order
-		/// (document number). 
+		/// <summary> Sets the sort to the terms in <code>field</code> then by index order
+		/// (document number).
 		/// </summary>
 		public void  SetSort(System.String field)
 		{
 			SetSort(field, false);
 		}
 		
-		
-		/// <summary>Sets the sort to the terms in <code>Field</code> possibly in reverse,
-		/// then by index order (document number). 
+		/// <summary> Sets the sort to the terms in <code>field</code> possibly in reverse,
+		/// then by index order (document number).
 		/// </summary>
 		public virtual void  SetSort(System.String field, bool reverse)
 		{
@@ -192,8 +189,7 @@
 			fields = nfields;
 		}
 		
-		
-		/// <summary>Sets the sort to the terms in each Field in succession. </summary>
+		/// <summary>Sets the sort to the terms in each field in succession. </summary>
 		public virtual void  SetSort(System.String[] fieldnames)
 		{
 			int n = fieldnames.Length;
@@ -205,18 +201,24 @@
 			fields = nfields;
 		}
 		
-		
 		/// <summary>Sets the sort to the given criteria. </summary>
 		public virtual void  SetSort(SortField field)
 		{
 			this.fields = new SortField[]{field};
 		}
 		
-		
 		/// <summary>Sets the sort to the given criteria in succession. </summary>
 		public virtual void  SetSort(SortField[] fields)
 		{
 			this.fields = fields;
+		}
+		
+		/// <summary> Representation of the sort criteria.</summary>
+		/// <returns> Array of SortField objects used in this sort criteria
+		/// </returns>
+		public virtual SortField[] GetSort()
+		{
+			return fields;
 		}
 		
 		public override System.String ToString()

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,8 +13,10 @@
  * 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
 {
 	
@@ -25,8 +27,8 @@
 	/// adequate sorting.  It maintains an internal cache of values which
 	/// could be quite large.  The cache is an array of Comparable,
 	/// one for each document in the index.  There is a distinct
-	/// Comparable for each unique term in the Field - if
-	/// some documents have the same term in the Field, the cache
+	/// Comparable for each unique term in the field - if
+	/// some documents have the same term in the field, the cache
 	/// array will have entries which reference the same Comparable.
 	/// 
 	/// <p>Created: Apr 21, 2004 5:08:38 PM
@@ -34,7 +36,7 @@
 	/// </summary>
 	/// <author>   Tim Jones
 	/// </author>
-	/// <version>  $Id: SortComparator.java,v 1.2.2.1 2004/09/30 19:20:16 dnaber Exp $
+	/// <version>  $Id: SortComparator.java 150541 2004-09-29 15:09:02Z goller $
 	/// </version>
 	/// <since>   1.4
 	/// </since>
@@ -83,7 +85,8 @@
 		public virtual ScoreDocComparator NewComparator(IndexReader reader, System.String fieldname)
 		{
 			System.String field = String.Intern(fieldname);
-            System.IComparable[] cachedValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetCustom(reader, field, this);
+			System.IComparable[] cachedValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetCustom(reader, field, this);
+			
 			return new AnonymousClassScoreDocComparator(cachedValues, this);
 		}
 		

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,8 +13,10 @@
  * 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
 {
 	
@@ -25,14 +27,14 @@
 	/// </summary>
 	/// <author>   Tim Jones
 	/// </author>
-	/// <version>  $Id: SortComparatorSource.java,v 1.2 2004/05/19 23:05:27 tjones Exp $
+	/// <version>  $Id: SortComparatorSource.java 150348 2004-05-19 23:05:27Z tjones $
 	/// </version>
 	/// <since>   1.4
 	/// </since>
 	public interface SortComparatorSource
 	{
 		
-		/// <summary> Creates a comparator for the Field in the given index.</summary>
+		/// <summary> Creates a comparator for the field in the given index.</summary>
 		/// <param name="reader">Index to create comparator for.
 		/// </param>
 		/// <param name="fieldname"> Field to create comparator for.

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,12 +13,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+
 namespace Lucene.Net.Search
 {
 	
 	/// <summary> Stores information about how to sort documents by terms in an individual
-	/// Field.  Fields must be indexed in order to sort by them.
+	/// field.  Fields must be indexed in order to sort by them.
 	/// 
 	/// <p>Created: Feb 11, 2004 1:25:29 PM
 	/// 
@@ -27,7 +29,7 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: SortField.java,v 1.9 2004/05/24 22:51:42 tjones Exp $
+	/// <version>  $Id: SortField.java 150357 2004-05-24 22:51:42Z tjones $
 	/// </version>
 	/// <seealso cref="Sort">
 	/// </seealso>
@@ -45,8 +47,8 @@
 		/// </summary>
 		public const int DOC = 1;
 		
-		/// <summary>Guess type of sort based on Field contents.  A regular expression is used
-		/// to look at the first term indexed for the Field and determine if it
+		/// <summary>Guess type of sort based on field contents.  A regular expression is used
+		/// to look at the first term indexed for the field and determine if it
 		/// represents an integer number, a floating point number, or just arbitrary
 		/// string characters. 
 		/// </summary>
@@ -90,20 +92,20 @@
 		internal bool reverse = false; // defaults to natural order
 		private SortComparatorSource factory;
 		
-		/// <summary>Creates a sort by terms in the given Field where the type of term value
+		/// <summary>Creates a sort by terms in the given field where the type of term value
 		/// is determined dynamically ({@link #AUTO AUTO}).
 		/// </summary>
-		/// <param name="Field">Name of Field to sort by, cannot be <code>null</code>.
+		/// <param name="field">Name of field to sort by, cannot be <code>null</code>.
 		/// </param>
 		public SortField(System.String field)
 		{
 			this.field = String.Intern(field);
 		}
 		
-		/// <summary>Creates a sort, possibly in reverse, by terms in the given Field where
+		/// <summary>Creates a sort, possibly in reverse, by terms in the given field where
 		/// the type of term value is determined dynamically ({@link #AUTO AUTO}).
 		/// </summary>
-		/// <param name="Field">Name of Field to sort by, cannot be <code>null</code>.
+		/// <param name="field">Name of field to sort by, cannot be <code>null</code>.
 		/// </param>
 		/// <param name="reverse">True if natural order should be reversed.
 		/// </param>
@@ -113,10 +115,10 @@
 			this.reverse = reverse;
 		}
 		
-		/// <summary>Creates a sort by terms in the given Field with the type of term
+		/// <summary>Creates a sort by terms in the given field with the type of term
 		/// values explicitly given.
 		/// </summary>
-		/// <param name="Field"> Name of Field to sort by.  Can be <code>null</code> if
+		/// <param name="field"> Name of field to sort by.  Can be <code>null</code> if
 		/// <code>type</code> is SCORE or DOC.
 		/// </param>
 		/// <param name="type">  Type of values in the terms.
@@ -127,10 +129,10 @@
 			this.type = type;
 		}
 		
-		/// <summary>Creates a sort, possibly in reverse, by terms in the given Field with the
+		/// <summary>Creates a sort, possibly in reverse, by terms in the given field with the
 		/// type of term values explicitly given.
 		/// </summary>
-		/// <param name="Field"> Name of Field to sort by.  Can be <code>null</code> if
+		/// <param name="field"> Name of field to sort by.  Can be <code>null</code> if
 		/// <code>type</code> is SCORE or DOC.
 		/// </param>
 		/// <param name="type">  Type of values in the terms.
@@ -144,12 +146,12 @@
 			this.reverse = reverse;
 		}
 		
-		/// <summary>Creates a sort by terms in the given Field sorted
+		/// <summary>Creates a sort by terms in the given field sorted
 		/// according to the given locale.
 		/// </summary>
-		/// <param name="Field"> Name of Field to sort by, cannot be <code>null</code>.
+		/// <param name="field"> Name of field to sort by, cannot be <code>null</code>.
 		/// </param>
-		/// <param name="locale">Locale of values in the Field.
+		/// <param name="locale">Locale of values in the field.
 		/// </param>
 		public SortField(System.String field, System.Globalization.CultureInfo locale)
 		{
@@ -158,12 +160,12 @@
 			this.locale = locale;
 		}
 		
-		/// <summary>Creates a sort, possibly in reverse, by terms in the given Field sorted
+		/// <summary>Creates a sort, possibly in reverse, by terms in the given field sorted
 		/// according to the given locale.
 		/// </summary>
-		/// <param name="Field"> Name of Field to sort by, cannot be <code>null</code>.
+		/// <param name="field"> Name of field to sort by, cannot be <code>null</code>.
 		/// </param>
-		/// <param name="locale">Locale of values in the Field.
+		/// <param name="locale">Locale of values in the field.
 		/// </param>
 		public SortField(System.String field, System.Globalization.CultureInfo locale, bool reverse)
 		{
@@ -174,7 +176,7 @@
 		}
 		
 		/// <summary>Creates a sort with a custom comparison function.</summary>
-		/// <param name="Field">Name of Field to sort by; cannot be <code>null</code>.
+		/// <param name="field">Name of field to sort by; cannot be <code>null</code>.
 		/// </param>
 		/// <param name="comparator">Returns a comparator for sorting hits.
 		/// </param>
@@ -186,7 +188,7 @@
 		}
 		
 		/// <summary>Creates a sort, possibly in reverse, with a custom comparison function.</summary>
-		/// <param name="Field">Name of Field to sort by; cannot be <code>null</code>.
+		/// <param name="field">Name of field to sort by; cannot be <code>null</code>.
 		/// </param>
 		/// <param name="comparator">Returns a comparator for sorting hits.
 		/// </param>
@@ -200,20 +202,20 @@
 			this.factory = comparator;
 		}
 		
-		/// <summary>Returns the name of the Field.  Could return <code>null</code>
+		/// <summary>Returns the name of the field.  Could return <code>null</code>
 		/// if the sort is by SCORE or DOC.
 		/// </summary>
-		/// <returns> Name of Field, possibly <code>null</code>.
+		/// <returns> Name of field, possibly <code>null</code>.
 		/// </returns>
 		public virtual System.String GetField()
 		{
 			return field;
 		}
 		
-		/// <summary>Returns the type of contents in the Field.</summary>
+		/// <summary>Returns the type of contents in the field.</summary>
 		/// <returns> One of the constants SCORE, DOC, AUTO, STRING, INT or FLOAT.
 		/// </returns>
-		new public virtual int GetType()
+		public virtual int GetType()
 		{
 			return type;
 		}
@@ -255,7 +257,7 @@
 					break;
 				
 				
-				case CUSTOM:  
+				case CUSTOM:
 					buffer.Append("<custom:\"" + field + "\": " + factory + ">");
 					break;
 				

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/NearSpans.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpans.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/NearSpans.cs Sat Jun  3 19:41:13 2006
@@ -13,9 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
 using PriorityQueue = Lucene.Net.Util.PriorityQueue;
+
 namespace Lucene.Net.Search.Spans
 {
 	
@@ -105,18 +107,17 @@
 				}
 				
 			}
-			
 			private Spans spans;
 			public SpansCell next;
 			private int length = - 1;
 			public int index;
 			
-            public SpansCell(NearSpans enclosingInstance, Spans spans, int index)
+			public SpansCell(NearSpans enclosingInstance, Spans spans, int index)
 			{
 				InitBlock(enclosingInstance);
-                this.spans = spans;
-                this.index = index;
-            }
+				this.spans = spans;
+				this.index = index;
+			}
 			
 			public virtual 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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -16,9 +16,9 @@
 <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
+href="SpanTermQuery.html">SpanTermQueries</a>) and inter-phrase
 proximity (when constructed from other <a
-href="SpanNearQuery.html">SpanNearQueries</a>.</li>
+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>

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanFirstQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,14 +13,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
+using Query = Lucene.Net.Search.Query;
+using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search.Spans
 {
 	
-	/// <summary>Matches spans near the beginning of a Field. </summary>
+	/// <summary>Matches spans near the beginning of a field. </summary>
 	[Serializable]
-	public class SpanFirstQuery:SpanQuery
+	public class SpanFirstQuery : SpanQuery
 	{
 		private class AnonymousClassSpans : Spans
 		{
@@ -129,12 +133,34 @@
 			buffer.Append(", ");
 			buffer.Append(end);
 			buffer.Append(")");
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
 			return buffer.ToString();
 		}
 		
 		public override Spans GetSpans(IndexReader reader)
 		{
 			return new AnonymousClassSpans(reader, this);
+		}
+		
+		public override Query Rewrite(IndexReader reader)
+		{
+			SpanFirstQuery clone = null;
+			
+			SpanQuery rewritten = (SpanQuery) match.Rewrite(reader);
+			if (rewritten != match)
+			{
+				clone = (SpanFirstQuery) this.Clone();
+				clone.match = rewritten;
+			}
+			
+			if (clone != null)
+			{
+				return clone; // some clauses rewrote
+			}
+			else
+			{
+				return this; // no clauses rewrote
+			}
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanNearQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNearQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,8 +13,12 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
+using Query = Lucene.Net.Search.Query;
+using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search.Spans
 {
 	
@@ -23,7 +27,7 @@
 	/// matches are required to be in-order. 
 	/// </summary>
 	[Serializable]
-	public class SpanNearQuery:SpanQuery
+	public class SpanNearQuery : SpanQuery
 	{
 		private System.Collections.ArrayList clauses;
 		private int slop;
@@ -46,12 +50,12 @@
 				SpanQuery clause = clauses[i];
 				if (i == 0)
 				{
-					// check Field
+					// check field
 					field = clause.GetField();
 				}
 				else if (!clause.GetField().Equals(field))
 				{
-					throw new System.ArgumentException("Clauses must have same Field.");
+					throw new System.ArgumentException("Clauses must have same field.");
 				}
 				this.clauses.Add(clause);
 			}
@@ -63,7 +67,7 @@
 		/// <summary>Return the clauses whose spans are matched. </summary>
 		public virtual SpanQuery[] GetClauses()
 		{
-            return (SpanQuery[]) clauses.ToArray(typeof(SpanQuery));
+			return (SpanQuery[]) clauses.ToArray(typeof(SpanQuery));
 		}
 		
 		/// <summary>Return the maximum number of intervening unmatched positions permitted.</summary>
@@ -90,8 +94,7 @@
 			while (i.MoveNext())
 			{
 				SpanQuery clause = (SpanQuery) i.Current;
-                //{{}}// _SupportClass.ICollectionSupport.AddAll(terms, clause.GetTerms()); // {{Aroush-1.4.3}}
-                terms.AddRange(clause.GetTerms());
+				terms.AddRange(clause.GetTerms());
 			}
 			return terms;
 		}
@@ -115,6 +118,7 @@
 			buffer.Append(", ");
 			buffer.Append(inOrder);
 			buffer.Append(")");
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
 			return buffer.ToString();
 		}
 		
@@ -129,6 +133,63 @@
 				return ((SpanQuery) clauses[0]).GetSpans(reader);
 			
 			return new NearSpans(this, reader);
+		}
+		
+		public override Query Rewrite(IndexReader reader)
+		{
+			SpanNearQuery clone = null;
+			for (int i = 0; i < clauses.Count; i++)
+			{
+				SpanQuery c = (SpanQuery) clauses[i];
+				SpanQuery query = (SpanQuery) c.Rewrite(reader);
+				if (query != c)
+				{
+					// clause rewrote: must clone
+					if (clone == null)
+						clone = (SpanNearQuery) this.Clone();
+					clone.clauses[i] = query;
+				}
+			}
+			if (clone != null)
+			{
+				return clone; // some clauses rewrote
+			}
+			else
+			{
+				return this; // no clauses rewrote
+			}
+		}
+		
+		/// <summary>Returns true iff <code>o</code> is equal to this. </summary>
+		public  override bool Equals(System.Object o)
+		{
+			if (this == o)
+				return true;
+			if (o == null || GetType() != o.GetType())
+				return false;
+			
+			SpanNearQuery spanNearQuery = (SpanNearQuery) o;
+			
+			if (inOrder != spanNearQuery.inOrder)
+				return false;
+			if (slop != spanNearQuery.slop)
+				return false;
+			if (!clauses.Equals(spanNearQuery.clauses))
+				return false;
+			if (!field.Equals(spanNearQuery.field))
+				return false;
+			
+			return GetBoost() == spanNearQuery.GetBoost();
+		}
+		
+		public override int GetHashCode()
+		{
+			int result;
+			result = clauses.GetHashCode();
+			result += slop * 29;
+			result += (inOrder?1:0);
+			result ^= field.GetHashCode();
+			return result;
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanNotQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanNotQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,14 +13,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
+using Query = Lucene.Net.Search.Query;
+using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search.Spans
 {
 	
 	/// <summary>Removes matches which overlap with another SpanQuery. </summary>
 	[Serializable]
-	public class SpanNotQuery:SpanQuery
+	public class SpanNotQuery : SpanQuery
 	{
 		private class AnonymousClassSpans : Spans
 		{
@@ -130,7 +134,7 @@
 			this.exclude = exclude;
 			
 			if (!include.GetField().Equals(exclude.GetField()))
-				throw new System.ArgumentException("Clauses must have same Field.");
+				throw new System.ArgumentException("Clauses must have same field.");
 		}
 		
 		/// <summary>Return the SpanQuery whose matches are filtered. </summary>
@@ -163,6 +167,7 @@
 			buffer.Append(", ");
 			buffer.Append(exclude.ToString(field));
 			buffer.Append(")");
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
 			return buffer.ToString();
 		}
 		
@@ -170,6 +175,34 @@
 		public override Spans GetSpans(IndexReader reader)
 		{
 			return new AnonymousClassSpans(reader, this);
+		}
+		
+		public override Query Rewrite(IndexReader reader)
+		{
+			SpanNotQuery clone = null;
+			
+			SpanQuery rewrittenInclude = (SpanQuery) include.Rewrite(reader);
+			if (rewrittenInclude != include)
+			{
+				clone = (SpanNotQuery) this.Clone();
+				clone.include = rewrittenInclude;
+			}
+			SpanQuery rewrittenExclude = (SpanQuery) exclude.Rewrite(reader);
+			if (rewrittenExclude != exclude)
+			{
+				if (clone == null)
+					clone = (SpanNotQuery) this.Clone();
+				clone.exclude = rewrittenExclude;
+			}
+			
+			if (clone != null)
+			{
+				return clone; // some clauses rewrote
+			}
+			else
+			{
+				return this; // no clauses rewrote
+			}
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanOrQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanOrQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,9 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
+using Query = Lucene.Net.Search.Query;
 using PriorityQueue = Lucene.Net.Util.PriorityQueue;
+using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search.Spans
 {
 	
@@ -171,12 +175,12 @@
 				SpanQuery clause = clauses[i];
 				if (i == 0)
 				{
-					// check Field
+					// check field
 					field = clause.GetField();
 				}
 				else if (!clause.GetField().Equals(field))
 				{
-					throw new System.ArgumentException("Clauses must have same Field.");
+					throw new System.ArgumentException("Clauses must have same field.");
 				}
 				this.clauses.Add(clause);
 			}
@@ -205,6 +209,31 @@
 			return terms;
 		}
 		
+		public override Query Rewrite(IndexReader reader)
+		{
+			SpanOrQuery clone = null;
+			for (int i = 0; i < clauses.Count; i++)
+			{
+				SpanQuery c = (SpanQuery) clauses[i];
+				SpanQuery query = (SpanQuery) c.Rewrite(reader);
+				if (query != c)
+				{
+					// clause rewrote: must clone
+					if (clone == null)
+						clone = (SpanOrQuery) this.Clone();
+					clone.clauses[i] = query;
+				}
+			}
+			if (clone != null)
+			{
+				return clone; // some clauses rewrote
+			}
+			else
+			{
+				return this; // no clauses rewrote
+			}
+		}
+		
 		public override System.String ToString(System.String field)
 		{
 			System.Text.StringBuilder buffer = new System.Text.StringBuilder();
@@ -220,10 +249,36 @@
 				}
 			}
 			buffer.Append("])");
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
 			return buffer.ToString();
 		}
 		
-		private class SpanQueue:PriorityQueue
+		public  override bool Equals(System.Object o)
+		{
+			if (this == o)
+				return true;
+			if (o == null || GetType() != o.GetType())
+				return false;
+			
+			SpanOrQuery that = (SpanOrQuery) o;
+			
+			if (!clauses.Equals(that.clauses))
+				return false;
+			if (!field.Equals(that.field))
+				return false;
+			
+			return GetBoost() == that.GetBoost();
+		}
+		
+		public override int GetHashCode()
+		{
+			int result;
+			result = clauses.GetHashCode();
+			result = 29 * result + field.GetHashCode();
+			return result;
+		}
+		
+		private class SpanQueue : PriorityQueue
 		{
 			private void  InitBlock(SpanOrQuery enclosingInstance)
 			{
@@ -270,7 +325,7 @@
 		public override Spans GetSpans(IndexReader reader)
 		{
 			if (clauses.Count == 1)
-			// optimize 1-clause case
+    			// optimize 1-clause case
 				return ((SpanQuery) clauses[0]).GetSpans(reader);
 			
 			return new AnonymousClassSpans(reader, this);

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,11 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
 using Query = Lucene.Net.Search.Query;
 using Searcher = Lucene.Net.Search.Searcher;
 using Weight = Lucene.Net.Search.Weight;
+
 namespace Lucene.Net.Search.Spans
 {
 	
@@ -30,7 +32,7 @@
 		/// </summary>
 		public abstract Spans GetSpans(IndexReader reader);
 		
-		/// <summary>Returns the name of the Field matched by this query.</summary>
+		/// <summary>Returns the name of the field matched by this query.</summary>
 		public abstract System.String GetField();
 		
 		/// <summary>Returns a collection of all terms matched by this query.</summary>

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=411501&r1=411500&r2=411501&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 Sat Jun  3 19:41:13 2006
@@ -13,16 +13,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 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
 {
 	
 	
-	class SpanScorer:Scorer
+	class SpanScorer : Scorer
 	{
 		private Spans spans;
 		private Weight weight;
@@ -40,7 +42,7 @@
 			this.spans = spans;
 			this.norms = norms;
 			this.weight = weight;
-			this.value_Renamed = weight.Value;
+			this.value_Renamed = weight.GetValue();
 		}
 		
 		public override bool Next()

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanTermQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanTermQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,10 +13,13 @@
  * 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 ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search.Spans
 {
 	
@@ -73,6 +76,12 @@
 			
 			public virtual bool SkipTo(int target)
 			{
+				// are we already at the correct position?
+				if (doc >= target)
+				{
+					return true;
+				}
+				
 				if (!positions.SkipTo(target))
 				{
 					doc = System.Int32.MaxValue;
@@ -129,18 +138,36 @@
 		public override System.Collections.ICollection GetTerms()
 		{
 			System.Collections.ArrayList terms = new System.Collections.ArrayList();
-            terms.Add(term);
+			terms.Add(term);
 			return terms;
 		}
 		
 		public override System.String ToString(System.String field)
 		{
+			System.Text.StringBuilder buffer = new System.Text.StringBuilder();
 			if (term.Field().Equals(field))
-				return term.Text();
+				buffer.Append(term.Text());
 			else
 			{
-				return term.ToString();
+				buffer.Append(term.ToString());
 			}
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
+			return buffer.ToString();
+		}
+		
+		/// <summary>Returns true iff <code>o</code> is equal to this. </summary>
+		public  override bool Equals(System.Object o)
+		{
+			if (!(o is SpanTermQuery))
+				return false;
+			SpanTermQuery other = (SpanTermQuery) o;
+			return (this.GetBoost() == other.GetBoost()) && this.term.Equals(other.term);
+		}
+		
+		/// <summary>Returns a hash code value for this object.</summary>
+		public override int GetHashCode()
+		{
+            return GetBoost().ToString().GetHashCode() ^ term.GetHashCode();    // {{Aroush-1.9}} Is this OK?
 		}
 		
 		public override Spans GetSpans(IndexReader reader)

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/SpanWeight.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/SpanWeight.cs Sat Jun  3 19:41:13 2006
@@ -13,6 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using IndexReader = Lucene.Net.Index.IndexReader;
 using Term = Lucene.Net.Index.Term;
@@ -22,29 +23,14 @@
 using Searcher = Lucene.Net.Search.Searcher;
 using Similarity = Lucene.Net.Search.Similarity;
 using Weight = Lucene.Net.Search.Weight;
+
 namespace Lucene.Net.Search.Spans
 {
 	
 	[Serializable]
 	class SpanWeight : Weight
 	{
-        virtual public Query Query
-        {
-            get
-            {
-                return query;
-            }
-			
-        }
-        virtual public float Value
-        {
-            get
-            {
-                return value_Renamed;
-            }
-			
-        }
-        private Searcher searcher;
+		private Similarity similarity;
 		private float value_Renamed;
 		private float idf;
 		private float queryNorm;
@@ -55,14 +41,24 @@
 		
 		public SpanWeight(SpanQuery query, Searcher searcher)
 		{
-			this.searcher = searcher;
+			this.similarity = query.GetSimilarity(searcher);
 			this.query = query;
 			this.terms = query.GetTerms();
+			
+			idf = this.query.GetSimilarity(searcher).Idf(terms, searcher);
+		}
+		
+		public virtual Query GetQuery()
+		{
+			return query;
+		}
+		public virtual float GetValue()
+		{
+			return value_Renamed;
 		}
 		
 		public virtual float SumOfSquaredWeights()
 		{
-			idf = this.query.GetSimilarity(searcher).Idf(terms, searcher);
 			queryWeight = idf * query.GetBoost(); // compute query weight
 			return queryWeight * queryWeight; // square it
 		}
@@ -76,15 +72,15 @@
 		
 		public virtual Scorer Scorer(IndexReader reader)
 		{
-			return new SpanScorer(query.GetSpans(reader), this, query.GetSimilarity(searcher), reader.Norms(query.GetField()));
+			return new SpanScorer(query.GetSpans(reader), this, similarity, reader.Norms(query.GetField()));
 		}
 		
 		public virtual Explanation Explain(IndexReader reader, int doc)
 		{
 			
 			Explanation result = new Explanation();
-			result.SetDescription("weight(" + Query + " in " + doc + "), product of:");
-			System.String field = ((SpanQuery) Query).GetField();
+			result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
+			System.String field = ((SpanQuery) GetQuery()).GetField();
 			
 			System.Text.StringBuilder docFreqs = new System.Text.StringBuilder();
 			System.Collections.IEnumerator i = terms.GetEnumerator();
@@ -93,7 +89,7 @@
 				Term term = (Term) i.Current;
 				docFreqs.Append(term.Text());
 				docFreqs.Append("=");
-				docFreqs.Append(searcher.DocFreq(term));
+				docFreqs.Append(reader.DocFreq(term));
 				
 				if (i.MoveNext())
 				{
@@ -105,10 +101,10 @@
 			
 			// explain query weight
 			Explanation queryExpl = new Explanation();
-			queryExpl.SetDescription("queryWeight(" + Query + "), product of:");
+			queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");
 			
-			Explanation boostExpl = new Explanation(Query.GetBoost(), "boost");
-			if (Query.GetBoost() != 1.0f)
+			Explanation boostExpl = new Explanation(GetQuery().GetBoost(), "boost");
+			if (GetQuery().GetBoost() != 1.0f)
 				queryExpl.AddDetail(boostExpl);
 			queryExpl.AddDetail(idfExpl);
 			
@@ -119,7 +115,7 @@
 			
 			result.AddDetail(queryExpl);
 			
-			// explain Field weight
+			// explain field weight
 			Explanation fieldExpl = new Explanation();
 			fieldExpl.SetDescription("fieldWeight(" + field + ":" + query.ToString(field) + " in " + doc + "), product of:");
 			
@@ -131,7 +127,7 @@
 			byte[] fieldNorms = reader.Norms(field);
 			float fieldNorm = fieldNorms != null ? Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;
 			fieldNormExpl.SetValue(fieldNorm);
-			fieldNormExpl.SetDescription("fieldNorm(Field=" + field + ", doc=" + doc + ")");
+			fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
 			fieldExpl.AddDetail(fieldNormExpl);
 			
 			fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Spans.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/Spans/Spans.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Spans.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/Spans/Spans.cs Sat Jun  3 19:41:13 2006
@@ -13,7 +13,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+
 namespace Lucene.Net.Search.Spans
 {
 	

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TermQuery.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermQuery.cs Sat Jun  3 19:41:13 2006
@@ -13,10 +13,13 @@
  * 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 TermDocs = Lucene.Net.Index.TermDocs;
+using ToStringUtils = Lucene.Net.Util.ToStringUtils;
+
 namespace Lucene.Net.Search
 {
 	
@@ -36,23 +39,7 @@
 				this.enclosingInstance = enclosingInstance;
 			}
 			private TermQuery enclosingInstance;
-            virtual public Query Query
-            {
-                get
-                {
-                    return Enclosing_Instance;
-                }
-				
-            }
-            virtual public float Value
-            {
-                get
-                {
-                    return value_Renamed;
-                }
-				
-            }
-            public TermQuery Enclosing_Instance
+			public TermQuery Enclosing_Instance
 			{
 				get
 				{
@@ -60,7 +47,7 @@
 				}
 				
 			}
-			private Searcher searcher;
+			private Similarity similarity;
 			private float value_Renamed;
 			private float idf;
 			private float queryNorm;
@@ -69,7 +56,8 @@
 			public TermWeight(TermQuery enclosingInstance, Searcher searcher)
 			{
 				InitBlock(enclosingInstance);
-				this.searcher = searcher;
+				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
+				idf = similarity.Idf(Enclosing_Instance.term, searcher); // compute idf
 			}
 			
 			public override System.String ToString()
@@ -77,9 +65,17 @@
 				return "weight(" + Enclosing_Instance + ")";
 			}
 			
+			public virtual Query GetQuery()
+			{
+				return Enclosing_Instance;
+			}
+			public virtual float GetValue()
+			{
+				return value_Renamed;
+			}
+			
 			public virtual float SumOfSquaredWeights()
 			{
-				idf = Enclosing_Instance.GetSimilarity(searcher).Idf(Enclosing_Instance.term, searcher); // compute idf
 				queryWeight = idf * Enclosing_Instance.GetBoost(); // compute query weight
 				return queryWeight * queryWeight; // square it
 			}
@@ -88,7 +84,7 @@
 			{
 				this.queryNorm = queryNorm;
 				queryWeight *= queryNorm; // normalize query weight
-				value_Renamed = queryWeight * idf; // idf for document 
+				value_Renamed = queryWeight * idf; // idf for document
 			}
 			
 			public virtual Scorer Scorer(IndexReader reader)
@@ -98,20 +94,20 @@
 				if (termDocs == null)
 					return null;
 				
-				return new TermScorer(this, termDocs, Enclosing_Instance.GetSimilarity(searcher), reader.Norms(Enclosing_Instance.term.Field()));
+				return new TermScorer(this, termDocs, similarity, reader.Norms(Enclosing_Instance.term.Field()));
 			}
 			
 			public virtual Explanation Explain(IndexReader reader, int doc)
 			{
 				
 				Explanation result = new Explanation();
-				result.SetDescription("weight(" + Query + " in " + doc + "), product of:");
+				result.SetDescription("weight(" + GetQuery() + " in " + doc + "), product of:");
 				
-				Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + searcher.DocFreq(Enclosing_Instance.term) + ")");
+				Explanation idfExpl = new Explanation(idf, "idf(docFreq=" + reader.DocFreq(Enclosing_Instance.term) + ")");
 				
 				// explain query weight
 				Explanation queryExpl = new Explanation();
-				queryExpl.SetDescription("queryWeight(" + Query + "), product of:");
+				queryExpl.SetDescription("queryWeight(" + GetQuery() + "), product of:");
 				
 				Explanation boostExpl = new Explanation(Enclosing_Instance.GetBoost(), "boost");
 				if (Enclosing_Instance.GetBoost() != 1.0f)
@@ -125,7 +121,7 @@
 				
 				result.AddDetail(queryExpl);
 				
-				// explain Field weight
+				// explain field weight
 				System.String field = Enclosing_Instance.term.Field();
 				Explanation fieldExpl = new Explanation();
 				fieldExpl.SetDescription("fieldWeight(" + Enclosing_Instance.term + " in " + doc + "), product of:");
@@ -136,9 +132,9 @@
 				
 				Explanation fieldNormExpl = new Explanation();
 				byte[] fieldNorms = reader.Norms(field);
-				float fieldNorm = fieldNorms != null?Similarity.DecodeNorm(fieldNorms[doc]):0.0f;
+				float fieldNorm = fieldNorms != null ? Similarity.DecodeNorm(fieldNorms[doc]) : 0.0f;
 				fieldNormExpl.SetValue(fieldNorm);
-				fieldNormExpl.SetDescription("fieldNorm(Field=" + field + ", doc=" + doc + ")");
+				fieldNormExpl.SetDescription("fieldNorm(field=" + field + ", doc=" + doc + ")");
 				fieldExpl.AddDetail(fieldNormExpl);
 				
 				fieldExpl.SetValue(tfExpl.GetValue() * idfExpl.GetValue() * fieldNormExpl.GetValue());
@@ -172,6 +168,12 @@
 			return new TermWeight(this, searcher);
 		}
 		
+		public override void  ExtractTerms(System.Collections.Hashtable terms)
+		{
+            Term term = GetTerm();
+			terms.Add(term, term);
+		}
+		
 		/// <summary>Prints a user-readable version of this query. </summary>
 		public override System.String ToString(System.String field)
 		{
@@ -182,17 +184,7 @@
 				buffer.Append(":");
 			}
 			buffer.Append(term.Text());
-			if (GetBoost() != 1.0f)
-			{
-                System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat;
-                nfi.NumberDecimalDigits = 1;
-
-                buffer.Append("^");
-                buffer.Append(GetBoost().ToString("N", nfi));
-
-				//buffer.Append("^");
-				//buffer.Append(GetBoost().ToString());
-			}
+			buffer.Append(ToStringUtils.Boost(GetBoost()));
 			return buffer.ToString();
 		}
 		
@@ -208,7 +200,12 @@
 		/// <summary>Returns a hash code value for this object.</summary>
 		public override int GetHashCode()
 		{
-            return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ term.GetHashCode();
+			return BitConverter.ToInt32(BitConverter.GetBytes(GetBoost()), 0) ^ term.GetHashCode();
+		}
+		// {{Aroush-1.9}} Do we need this?!
+		public override System.Object Clone()
+		{
+			return null;
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TermScorer.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TermScorer.cs Sat Jun  3 19:41:13 2006
@@ -13,12 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
 using TermDocs = Lucene.Net.Index.TermDocs;
+
 namespace Lucene.Net.Search
 {
 	
-	sealed class TermScorer:Scorer
+	/// <summary>Expert: A <code>Scorer</code> for documents matching a <code>Term</code>.</summary>
+	sealed class TermScorer : Scorer
 	{
 		private Weight weight;
 		private TermDocs termDocs;
@@ -34,22 +37,79 @@
 		private const int SCORE_CACHE_SIZE = 32;
 		private float[] scoreCache = new float[SCORE_CACHE_SIZE];
 		
+		/// <summary>Construct a <code>TermScorer</code>.</summary>
+		/// <param name="weight">The weight of the <code>Term</code> in the query.
+		/// </param>
+		/// <param name="td">An iterator over the documents matching the <code>Term</code>.
+		/// </param>
+		/// <param name="similarity">The </code>Similarity</code> implementation to be used for score computations.
+		/// </param>
+		/// <param name="norms">The field norms of the document fields for the <code>Term</code>.
+		/// </param>
 		internal TermScorer(Weight weight, TermDocs td, Similarity similarity, byte[] norms) : base(similarity)
 		{
 			this.weight = weight;
 			this.termDocs = td;
 			this.norms = norms;
-			this.weightValue = weight.Value;
+			this.weightValue = weight.GetValue();
 			
 			for (int i = 0; i < SCORE_CACHE_SIZE; i++)
 				scoreCache[i] = GetSimilarity().Tf(i) * weightValue;
 		}
 		
+		public override void  Score(HitCollector hc)
+		{
+			Next();
+			Score(hc, System.Int32.MaxValue);
+		}
+		
+		protected internal override bool Score(HitCollector c, int end)
+		{
+			Similarity similarity = GetSimilarity(); // cache sim in local
+			float[] normDecoder = Similarity.GetNormDecoder();
+			while (doc < end)
+			{
+				// for docs in window
+				int f = freqs[pointer];
+				float score = f < SCORE_CACHE_SIZE?scoreCache[f]:similarity.Tf(f) * weightValue; // cache miss
+				
+				score *= normDecoder[norms[doc] & 0xFF]; // normalize for field
+				
+				c.Collect(doc, score); // collect score
+				
+				if (++pointer >= pointerMax)
+				{
+					pointerMax = termDocs.Read(docs, freqs); // refill buffers
+					if (pointerMax != 0)
+					{
+						pointer = 0;
+					}
+					else
+					{
+						termDocs.Close(); // close stream
+						doc = System.Int32.MaxValue; // set to sentinel value
+						return false;
+					}
+				}
+				doc = docs[pointer];
+			}
+			return true;
+		}
+		
+		/// <summary>Returns the current document number matching the query.
+		/// Initially invalid, until {@link #Next()} is called the first time.
+		/// </summary>
 		public override int Doc()
 		{
 			return doc;
 		}
 		
+		/// <summary>Advances to the next document matching the query.
+		/// <br>The iterator over the matching documents is buffered using
+		/// {@link TermDocs#Read(int[],int[])}.
+		/// </summary>
+		/// <returns> true iff there is another document matching the query.
+		/// </returns>
 		public override bool Next()
 		{
 			pointer++;
@@ -76,9 +136,17 @@
 			int f = freqs[pointer];
 			float raw = f < SCORE_CACHE_SIZE ? scoreCache[f] : GetSimilarity().Tf(f) * weightValue; // cache miss
 			
-			return raw * Similarity.DecodeNorm(norms[doc]); // normalize for Field
+			return raw * Similarity.DecodeNorm(norms[doc]); // normalize for field
 		}
 		
+		/// <summary>Skips to the first match beyond the current whose document number is
+		/// greater than or equal to a given target. 
+		/// <br>The implementation uses {@link TermDocs#SkipTo(int)}.
+		/// </summary>
+		/// <param name="target">The target document number.
+		/// </param>
+		/// <returns> true iff there is such a match.
+		/// </returns>
 		public override bool SkipTo(int target)
 		{
 			// first scan in cache
@@ -107,9 +175,16 @@
 			return result;
 		}
 		
+		/// <summary>Returns an explanation of the score for a document.
+		/// <br>When this method is used, the {@link #Next()} method
+		/// and the {@link #Score(HitCollector)} method should not be used.
+		/// </summary>
+		/// <param name="doc">The document number for the explanation.
+		/// </param>
+		/// <todo>  Modify to make use of {@link TermDocs#SkipTo(int)}. </todo>
 		public override Explanation Explain(int doc)
 		{
-			TermQuery query = (TermQuery) weight.Query;
+			TermQuery query = (TermQuery) weight.GetQuery();
 			Explanation tfExplanation = new Explanation();
 			int tf = 0;
 			while (pointer < pointerMax)
@@ -135,6 +210,7 @@
 			return tfExplanation;
 		}
 		
+		/// <summary>Returns a string representation of this <code>TermScorer</code>. </summary>
 		public override System.String ToString()
 		{
 			return "scorer(" + weight + ")";

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopDocs.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopDocs.cs Sat Jun  3 19:41:13 2006
@@ -13,27 +13,45 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+
 namespace Lucene.Net.Search
 {
+	
 	/// <summary>Expert: Returned by low-level search implementations.</summary>
-	/// <seealso cref="Searcher#Search(Query,Filter,int)">
+	/// <seealso cref="Searcher.Search(Query,Filter,int)">
 	/// </seealso>
 	[Serializable]
 	public class TopDocs
 	{
 		/// <summary>Expert: The total number of hits for the query.</summary>
-		/// <seealso cref="Hits#Length()">
+		/// <seealso cref="Hits.Length()">
 		/// </seealso>
 		public int totalHits;
 		/// <summary>Expert: The top hits for the query. </summary>
 		public ScoreDoc[] scoreDocs;
+		/// <summary>Expert: Stores the maximum score value encountered, needed for normalizing. </summary>
+		private float maxScore;
+		
+		/// <summary>Expert: Returns the maximum score value encountered. </summary>
+		public virtual float GetMaxScore()
+		{
+			return maxScore;
+		}
+		
+		/// <summary>Expert: Sets the maximum score value encountered. </summary>
+		public virtual void  SetMaxScore(float maxScore)
+		{
+			this.maxScore = maxScore;
+		}
 		
 		/// <summary>Expert: Constructs a TopDocs.</summary>
-		internal TopDocs(int totalHits, ScoreDoc[] scoreDocs)
+		internal TopDocs(int totalHits, ScoreDoc[] scoreDocs, float maxScore)
 		{
 			this.totalHits = totalHits;
 			this.scoreDocs = scoreDocs;
+			this.maxScore = maxScore;
 		}
 	}
 }

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Search/TopFieldDocs.cs?rev=411501&r1=411500&r2=411501&view=diff
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Search/TopFieldDocs.cs Sat Jun  3 19:41:13 2006
@@ -13,9 +13,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 using System;
+
 namespace Lucene.Net.Search
 {
+	
+	
 	/// <summary> Expert: Returned by low-level sorted search implementations.
 	/// 
 	/// <p>Created: Feb 12, 2004 8:58:46 AM 
@@ -25,12 +29,12 @@
 	/// </author>
 	/// <since>   lucene 1.4
 	/// </since>
-	/// <version>  $Id: TopFieldDocs.java,v 1.2 2004/02/27 12:29:31 otis Exp $
+	/// <version>  $Id: TopFieldDocs.java 354819 2005-12-07 17:48:37Z yonik $
 	/// </version>
-	/// <seealso cref="Searchable#Search(Query,Filter,int,Sort)">
+	/// <seealso cref="Searcher.Search(Query,Filter,int,Sort)">
 	/// </seealso>
 	[Serializable]
-	public class TopFieldDocs:TopDocs
+	public class TopFieldDocs : TopDocs
 	{
 		
 		/// <summary>The fields which were used to sort results by. </summary>
@@ -43,7 +47,9 @@
 		/// </param>
 		/// <param name="fields">    The sort criteria used to find the top hits.
 		/// </param>
-		internal TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields):base(totalHits, scoreDocs)
+		/// <param name="maxScore">  The maximum score encountered.
+		/// </param>
+		internal TopFieldDocs(int totalHits, ScoreDoc[] scoreDocs, SortField[] fields, float maxScore) : base(totalHits, scoreDocs, maxScore)
 		{
 			this.fields = fields;
 		}



Mime
View raw message