lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ccurr...@apache.org
Subject svn commit: r1304578 [1/2] - /incubator/lucene.net/trunk/src/contrib/Highlighter/
Date Fri, 23 Mar 2012 20:16:38 GMT
Author: ccurrens
Date: Fri Mar 23 20:16:37 2012
New Revision: 1304578

URL: http://svn.apache.org/viewvc?rev=1304578&view=rev
Log:
[LUCENENET-463] - Started porting Highlighter.  Will also require a port of MemoryIndex, which if I call correctly was a huge pain.  Not sure if this will make it into 3.0.3

Added:
    incubator/lucene.net/trunk/src/contrib/Highlighter/IEncoder.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/InvalidTokenOffsetsException.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermScorer.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTerm.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTermExtractor.cs
Removed:
    incubator/lucene.net/trunk/src/contrib/Highlighter/Encoder.cs
Modified:
    incubator/lucene.net/trunk/src/contrib/Highlighter/Contrib.Highlighter.csproj
    incubator/lucene.net/trunk/src/contrib/Highlighter/DefaultEncoder.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/Formatter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/Fragmenter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/GradientFormatter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/Highlighter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/NullFragmenter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/Package.html
    incubator/lucene.net/trunk/src/contrib/Highlighter/QueryScorer.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermExtractor.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/Scorer.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleFragmenter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLEncoder.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLFormatter.cs
    incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedTerm.cs

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Contrib.Highlighter.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Contrib.Highlighter.csproj?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Contrib.Highlighter.csproj (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Contrib.Highlighter.csproj Fri Mar 23 20:16:37 2012
@@ -19,7 +19,6 @@
  under the License.
 
 -->
-
 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
   <PropertyGroup>
     <ProjectType>Local</ProjectType>
@@ -123,7 +122,7 @@
     <Compile Include="DefaultEncoder.cs">
       <SubType>Code</SubType>
     </Compile>
-    <Compile Include="Encoder.cs">
+    <Compile Include="IEncoder.cs">
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="Formatter.cs">
@@ -138,6 +137,7 @@
     <Compile Include="Highlighter.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="InvalidTokenOffsetsException.cs" />
     <Compile Include="NullFragmenter.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -147,6 +147,7 @@
     <Compile Include="QueryTermExtractor.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="QueryTermScorer.cs" />
     <Compile Include="Scorer.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -171,6 +172,8 @@
     <Compile Include="TokenSources.cs">
       <SubType>Code</SubType>
     </Compile>
+    <Compile Include="WeightedSpanTerm.cs" />
+    <Compile Include="WeightedSpanTermExtractor.cs" />
     <Compile Include="WeightedTerm.cs">
       <SubType>Code</SubType>
     </Compile>

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/DefaultEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/DefaultEncoder.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/DefaultEncoder.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/DefaultEncoder.cs Fri Mar 23 20:16:37 2012
@@ -15,20 +15,13 @@
  * limitations under the License.
  */
 
-using System;
+using Lucene.Net.Search.Highlight;
 
 namespace Lucene.Net.Highlight
 {
-	/// <summary> Simple <see cref="Encoder"/> implementation that does not modify the output</summary>
-	/// <author>  Nicko Cadell
-	/// 
-	/// </author>
-	public class DefaultEncoder : Encoder
+	/// <summary>Simple <see cref="IEncoder"/> implementation that does not modify the output</summary>
+	public class DefaultEncoder : IEncoder
 	{
-		public DefaultEncoder()
-		{
-		}
-		
 		public virtual System.String EncodeText(System.String originalText)
 		{
 			return originalText;

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Formatter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Formatter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Formatter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Formatter.cs Fri Mar 23 20:16:37 2012
@@ -15,21 +15,17 @@
  * limitations under the License.
  */
 
-using System;
+using Lucene.Net.Highlight;
 
-namespace Lucene.Net.Highlight
+namespace Lucene.Net.Search.Highlight
 {
 	/// <summary> Processes terms found in the original text, typically by applying some form 
-	/// of mark-up to highlight terms in HTML search results pages.
-	/// 
-	/// </summary>
-	public interface Formatter
+	/// of mark-up to highlight terms in HTML search results pages.</summary>
+	public interface IFormatter
 	{
-		/// <param name="originalText">The section of text being considered for markup
-		/// </param>
+		/// <param name="originalText">The section of text being considered for markup</param>
 		/// <param name="tokenGroup">contains one or several overlapping Tokens along with
-		/// their scores and positions.
-		/// </param>
-		System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup);
+		/// their scores and positions.</param>
+		string HighlightTerm(System.String originalText, TokenGroup tokenGroup);
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Fragmenter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Fragmenter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Fragmenter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Fragmenter.cs Fri Mar 23 20:16:37 2012
@@ -15,28 +15,33 @@
  * limitations under the License.
  */
 
-using System;
-using Token = Lucene.Net.Analysis.Token;
+using Lucene.Net.Analysis;
+using Lucene.Net.Highlight;
 
-namespace Lucene.Net.Highlight
+namespace Lucene.Net.Search.Highlight
 {
-	
-	/// <summary> Implements the policy for breaking text into multiple fragments for consideration
-	/// by the <see cref="Highlighter"/> class. A sophisticated implementation may do this on the basis
-	/// of detecting end of sentences in the text. 
-	/// </summary>
-	/// <author>  mark@searcharea.co.uk
-	/// </author>
-	public interface Fragmenter
-	{
-		/// <summary> Initializes the Fragmenter</summary>
-        /// <param name="originalText">
-		/// </param>
-		void  Start(System.String originalText);
-		
-		/// <summary> Test to see if this token from the stream should be held in a new TextFragment</summary>
-        /// <param name="nextToken">
-		/// </param>
-		bool IsNewFragment(Token nextToken);
-	}
+
+    /// <summary> Implements the policy for breaking text into multiple fragments for consideration
+    /// by the <see cref="Highlighter"/> class. A sophisticated implementation may do this on the basis
+    /// of detecting end of sentences in the text. 
+    /// </summary>
+    /// <author>  mark@searcharea.co.uk
+    /// </author>
+    public interface IFragmenter
+    {
+        /// <summary>
+        /// Initializes the Fragmenter. You can grab references to the Attributes you are
+        /// interested in from tokenStream and then access the values in {@link #isNewFragment()}.
+        /// </summary>
+        /// <param name="originalText">the original source text</param>
+        ///<param name="tokenStream">tokenStream the <see cref="TokenStream" /> to be fragmented</param>
+        void Start(string originalText, TokenStream tokenStream);
+
+        /// <summary>
+        /// Test to see if this token from the stream should be held in a new
+        /// TextFragment. Every time this is called, the TokenStream
+        /// passed to start(String, TokenStream) will have been incremented.
+        /// </summary>
+        bool IsNewFragment();
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/GradientFormatter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/GradientFormatter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/GradientFormatter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/GradientFormatter.cs Fri Mar 23 20:16:37 2012
@@ -16,6 +16,7 @@
  */
 
 using System;
+using Lucene.Net.Search.Highlight;
 
 namespace Lucene.Net.Highlight
 {
@@ -25,7 +26,7 @@ namespace Lucene.Net.Highlight
 	/// </summary>
 	/// <author>  maharwood
 	/// </author>
-	public class GradientFormatter : Formatter
+	public class GradientFormatter : IFormatter
 	{
 		private float maxScore;
 		
@@ -41,9 +42,7 @@ namespace Lucene.Net.Highlight
 		
 		protected internal bool highlightBackground;
 		
-		/// <summary> Sets the color range for the IDF scores
-		/// 
-		/// </summary>
+		/// <summary> Sets the color range for the IDF scores</summary>
         /// <param name="maxScore">
 		/// The score (and above) displayed as maxColor (See QueryScorer.getMaxWeight 
 		/// which can be used to callibrate scoring scale)
@@ -64,26 +63,27 @@ namespace Lucene.Net.Highlight
 		/// The largest hex color used for representing IDF scores eg
 		/// #000000 (black) or null if no background color required
 		/// </param>
-		public GradientFormatter(float maxScore, System.String minForegroundColor, System.String maxForegroundColor, System.String minBackgroundColor, System.String maxBackgroundColor)
+		public GradientFormatter(float maxScore, string minForegroundColor, string maxForegroundColor, string minBackgroundColor, string maxBackgroundColor)
 		{
-			highlightForeground = (minForegroundColor != null) && (maxForegroundColor != null);
-			if (highlightForeground)
+		    highlightForeground = (minForegroundColor != null) && (maxForegroundColor != null);
+
+            if (highlightForeground)
 			{
 				if (minForegroundColor.Length != 7)
 				{
-					throw new System.ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
+					throw new ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
 				}
 				if (maxForegroundColor.Length != 7)
 				{
-					throw new System.ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
+					throw new ArgumentException("minForegroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
 				}
-				fgRMin = HexToInt(minForegroundColor.Substring(1, (3) - (1)));
-				fgGMin = HexToInt(minForegroundColor.Substring(3, (5) - (3)));
-				fgBMin = HexToInt(minForegroundColor.Substring(5, (7) - (5)));
+				fgRMin = HexToInt(minForegroundColor.Substring(1, 2));
+				fgGMin = HexToInt(minForegroundColor.Substring(3, 2));
+				fgBMin = HexToInt(minForegroundColor.Substring(5, 2));
 				
-				fgRMax = HexToInt(maxForegroundColor.Substring(1, (3) - (1)));
-				fgGMax = HexToInt(maxForegroundColor.Substring(3, (5) - (3)));
-				fgBMax = HexToInt(maxForegroundColor.Substring(5, (7) - (5)));
+				fgRMax = HexToInt(maxForegroundColor.Substring(1, 2));
+				fgGMax = HexToInt(maxForegroundColor.Substring(3, 2));
+				fgBMax = HexToInt(maxForegroundColor.Substring(5, 2));
 			}
 			
 			highlightBackground = (minBackgroundColor != null) && (maxBackgroundColor != null);
@@ -97,20 +97,20 @@ namespace Lucene.Net.Highlight
 				{
 					throw new System.ArgumentException("minBackgroundColor is not 7 bytes long eg a hex " + "RGB value such as #FFFFFF");
 				}
-				bgRMin = HexToInt(minBackgroundColor.Substring(1, (3) - (1)));
-				bgGMin = HexToInt(minBackgroundColor.Substring(3, (5) - (3)));
-				bgBMin = HexToInt(minBackgroundColor.Substring(5, (7) - (5)));
+				bgRMin = HexToInt(minBackgroundColor.Substring(1, 2));
+				bgGMin = HexToInt(minBackgroundColor.Substring(3, 2));
+				bgBMin = HexToInt(minBackgroundColor.Substring(5, 2));
 				
-				bgRMax = HexToInt(maxBackgroundColor.Substring(1, (3) - (1)));
-				bgGMax = HexToInt(maxBackgroundColor.Substring(3, (5) - (3)));
-				bgBMax = HexToInt(maxBackgroundColor.Substring(5, (7) - (5)));
+				bgRMax = HexToInt(maxBackgroundColor.Substring(1, 2));
+				bgGMax = HexToInt(maxBackgroundColor.Substring(3, 2));
+				bgBMax = HexToInt(maxBackgroundColor.Substring(5, 2));
 			}
 			//        this.corpusReader = corpusReader;
 			this.maxScore = maxScore;
 			//        totalNumDocs = corpusReader.numDocs();
 		}
 		
-		public virtual System.String HighlightTerm(System.String originalText, TokenGroup tokenGroup)
+		public virtual string HighlightTerm(string originalText, TokenGroup tokenGroup)
 		{
 			if (tokenGroup.GetTotalScore() == 0)
 				return originalText;
@@ -119,7 +119,8 @@ namespace Lucene.Net.Highlight
 			{
 				return originalText;
 			}
-			System.Text.StringBuilder sb = new System.Text.StringBuilder();
+
+			var sb = new System.Text.StringBuilder();
 			sb.Append("<font ");
 			if (highlightForeground)
 			{
@@ -139,12 +140,12 @@ namespace Lucene.Net.Highlight
 			return sb.ToString();
 		}
 		
-		protected internal virtual System.String GetForegroundColorString(float score)
+		protected internal virtual string GetForegroundColorString(float score)
 		{
 			int rVal = GetColorVal(fgRMin, fgRMax, score);
 			int gVal = GetColorVal(fgGMin, fgGMax, score);
 			int bVal = GetColorVal(fgBMin, fgBMax, score);
-			System.Text.StringBuilder sb = new System.Text.StringBuilder();
+			var sb = new System.Text.StringBuilder();
 			sb.Append("#");
 			sb.Append(IntToHex(rVal));
 			sb.Append(IntToHex(gVal));
@@ -152,12 +153,12 @@ namespace Lucene.Net.Highlight
 			return sb.ToString();
 		}
 		
-		protected internal virtual System.String GetBackgroundColorString(float score)
+		protected internal virtual string GetBackgroundColorString(float score)
 		{
 			int rVal = GetColorVal(bgRMin, bgRMax, score);
 			int gVal = GetColorVal(bgGMin, bgGMax, score);
 			int bVal = GetColorVal(bgBMin, bgBMax, score);
-			System.Text.StringBuilder sb = new System.Text.StringBuilder();
+			var sb = new System.Text.StringBuilder();
 			sb.Append("#");
 			sb.Append(IntToHex(rVal));
 			sb.Append(IntToHex(gVal));
@@ -171,15 +172,15 @@ namespace Lucene.Net.Highlight
 			{
 				return colorMin;
 			}
-			float scale = System.Math.Abs(colorMin - colorMax);
-			float relScorePercent = System.Math.Min(maxScore, score) / maxScore;
+			float scale = Math.Abs(colorMin - colorMax);
+			float relScorePercent = Math.Min(maxScore, score) / maxScore;
 			float colScore = scale * relScorePercent;
-			return System.Math.Min(colorMin, colorMax) + (int) colScore;
+			return Math.Min(colorMin, colorMax) + (int) colScore;
 		}
 		
 		private static char[] hexDigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
 		
-		private static System.String IntToHex(int i)
+		private static string IntToHex(int i)
 		{
 			return "" + hexDigits[(i & 0xF0) >> 4] + hexDigits[i & 0x0F];
 		}
@@ -199,11 +200,11 @@ namespace Lucene.Net.Highlight
 		/// </param>
         /// <exception cref="FormatException">if the string is more than 16 characters long, or if any
 		/// character is not in the set [0-9a-fA-f]</exception>
-		public static int HexToInt(System.String hex)
+		public static int HexToInt(string hex)
 		{
 			int len = hex.Length;
 			if (len > 16)
-				throw new System.FormatException();
+				throw new FormatException();
 			
 			int l = 0;
 			for (int i = 0; i < len; i++)
@@ -211,7 +212,7 @@ namespace Lucene.Net.Highlight
 				l <<= 4;
 				int c = (int) System.Char.GetNumericValue(hex[i]);
 				if (c < 0)
-					throw new System.FormatException();
+					throw new FormatException();
 				l |= c;
 			}
 			return l;

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Highlighter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Highlighter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Highlighter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Highlighter.cs Fri Mar 23 20:16:37 2012
@@ -16,6 +16,7 @@
  */
 
 using System;
+using Lucene.Net.Search.Highlight;
 using Lucene.Net.Util;
 using Analyzer = Lucene.Net.Analysis.Analyzer;
 using Token = Lucene.Net.Analysis.Token;
@@ -23,10 +24,9 @@ using TokenStream = Lucene.Net.Analysis.
 
 namespace Lucene.Net.Highlight
 {
-	
 	/// <summary> Class used to markup highlighted terms found in the best sections of a 
-	/// text, using configurable <see cref="Fragmenter"/>, <see cref="Scorer"/>, <see cref="Formatter"/>, 
-	/// <see cref="Encoder"/> and tokenizers.
+	/// text, using configurable <see cref="IFragmenter"/>, <see cref="IScorer"/>, <see cref="IFormatter"/>, 
+	/// <see cref="IEncoder"/> and tokenizers.
 	/// </summary>
 	/// <author>  mark@searcharea.co.uk
 	/// </author>
@@ -35,22 +35,22 @@ namespace Lucene.Net.Highlight
 		
 		public const int DEFAULT_MAX_DOC_BYTES_TO_ANALYZE = 50 * 1024;
 		private int maxDocBytesToAnalyze = DEFAULT_MAX_DOC_BYTES_TO_ANALYZE;
-		private Formatter formatter;
-		private Encoder encoder;
-		private Fragmenter textFragmenter = new SimpleFragmenter();
-		private Scorer fragmentScorer = null;
+		private IFormatter formatter;
+		private IEncoder encoder;
+		private IFragmenter textFragmenter = new SimpleFragmenter();
+		private IScorer fragmentScorer = null;
 		
-		public Highlighter(Scorer fragmentScorer) : this(new SimpleHTMLFormatter(), fragmentScorer)
+		public Highlighter(IScorer fragmentScorer) : this(new SimpleHTMLFormatter(), fragmentScorer)
 		{
 		}
 		
 		
-		public Highlighter(Formatter formatter, Scorer fragmentScorer) : this(formatter, new DefaultEncoder(), fragmentScorer)
+		public Highlighter(IFormatter formatter, IScorer fragmentScorer) : this(formatter, new DefaultEncoder(), fragmentScorer)
 		{
 		}
 		
 		
-		public Highlighter(Formatter formatter, Encoder encoder, Scorer fragmentScorer)
+		public Highlighter(IFormatter formatter, IEncoder encoder, IScorer fragmentScorer)
 		{
 			this.formatter = formatter;
 			this.encoder = encoder;
@@ -472,20 +472,20 @@ namespace Lucene.Net.Highlight
 		}
 		
 		
-		public virtual Fragmenter GetTextFragmenter()
+		public virtual IFragmenter GetTextFragmenter()
 		{
 			return textFragmenter;
 		}
 
         /// <param name="fragmenter"> </param>
-		public virtual void  SetTextFragmenter(Fragmenter fragmenter)
+		public virtual void  SetTextFragmenter(IFragmenter fragmenter)
 		{
 			textFragmenter = fragmenter;
 		}
 		
 		/// <returns> Object used to score each text fragment 
 		/// </returns>
-		public virtual Scorer GetFragmentScorer()
+		public virtual IScorer GetFragmentScorer()
 		{
 			return fragmentScorer;
 		}
@@ -493,16 +493,16 @@ namespace Lucene.Net.Highlight
 
         /// <param name="scorer">
 		/// </param>
-		public virtual void  SetFragmentScorer(Scorer scorer)
+		public virtual void  SetFragmentScorer(IScorer scorer)
 		{
 			fragmentScorer = scorer;
 		}
 		
-		public virtual Encoder GetEncoder()
+		public virtual IEncoder GetEncoder()
 		{
 			return encoder;
 		}
-		public virtual void  SetEncoder(Encoder encoder)
+		public virtual void  SetEncoder(IEncoder encoder)
 		{
 			this.encoder = encoder;
 		}

Added: incubator/lucene.net/trunk/src/contrib/Highlighter/IEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/IEncoder.cs?rev=1304578&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/IEncoder.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/IEncoder.cs Fri Mar 23 20:16:37 2012
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+namespace Lucene.Net.Search.Highlight
+{
+	/// <summary>Encodes original text. The IEncoder works with the Formatter to generate the output.</summary>
+	public interface IEncoder
+	{
+		/// <param name="originalText">The section of text being output</param>
+		string EncodeText(System.String originalText);
+	}
+}
\ No newline at end of file

Added: incubator/lucene.net/trunk/src/contrib/Highlighter/InvalidTokenOffsetsException.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/InvalidTokenOffsetsException.cs?rev=1304578&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/InvalidTokenOffsetsException.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/InvalidTokenOffsetsException.cs Fri Mar 23 20:16:37 2012
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+
+namespace Lucene.Net.Search.Highlight
+{
+    [Serializable]
+    public class InvalidTokenOffsetsException : Exception
+    {
+        public InvalidTokenOffsetsException()
+        {
+        }
+
+        public InvalidTokenOffsetsException(string message) : base(message)
+        {
+        }
+
+        public InvalidTokenOffsetsException(string message, Exception inner) : base(message, inner)
+        {
+        }
+
+        protected InvalidTokenOffsetsException(
+            SerializationInfo info,
+            StreamingContext context) : base(info, context)
+        {
+        }
+    }
+}

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/NullFragmenter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/NullFragmenter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/NullFragmenter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/NullFragmenter.cs Fri Mar 23 20:16:37 2012
@@ -16,23 +16,24 @@
  */
 
 using System;
+using Lucene.Net.Analysis;
+using Lucene.Net.Search.Highlight;
 using Token = Lucene.Net.Analysis.Token;
 
 namespace Lucene.Net.Highlight
 {
 	
-	/// <summary> <see cref="Fragmenter"/> implementation which does not fragment the text.
+	/// <summary> <see cref="IFragmenter"/> implementation which does not fragment the text.
 	/// This is useful for highlighting the entire content of a document or field.
 	/// </summary>
-	public class NullFragmenter : Fragmenter
+	public class NullFragmenter : IFragmenter
 	{
-		public virtual void  Start(System.String s)
-		{
-		}
-		
-		public virtual bool IsNewFragment(Token token)
-		{
-			return false;
-		}
+	    public virtual void Start(string originalText, TokenStream tokenStream)
+	    { }
+
+	    public virtual bool IsNewFragment()
+	    {
+            return false;
+	    }
 	}
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Package.html
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Package.html?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Package.html (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Package.html Fri Mar 23 20:16:37 2012
@@ -44,8 +44,8 @@
 	}
 </pre>
         <h2>New features 06/02/2005</h2>
-        This release adds options for encoding (thanks to Nicko Cadell). An "Encoder" 
-        implementation such as the new SimpleHTMLEncoder class can be passed to the 
+        This release adds options for encoding (thanks to Nicko Cadell). An "IEncoder" 
+        implementation such as the new SimpleHTMLIEncoder class can be passed to the 
         highlighter to encode all those non-xhtml standard characters such as &amp; 
         into legal values. This simple class may not suffice for some languages - 
         Commons Lang has an implementation that could be used: escapeHtml(String) in 

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/QueryScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/QueryScorer.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/QueryScorer.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/QueryScorer.cs Fri Mar 23 20:16:37 2012
@@ -16,134 +16,294 @@
  */
 
 using System;
-using Token = Lucene.Net.Analysis.Token;
-using IndexReader = Lucene.Net.Index.IndexReader;
-using Query = Lucene.Net.Search.Query;
+using System.Collections.Generic;
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Highlight;
+using Lucene.Net.Index;
+using Lucene.Net.Search.Spans;
+using Lucene.Net.Support;
+using Lucene.Net.Util;
 
-namespace Lucene.Net.Highlight
+namespace Lucene.Net.Search.Highlight
 {
-	
-	/// <summary> <see cref="Scorer"/> implementation which scores text fragments by the number of unique query terms found.
-	/// This class uses the <see cref="QueryTermExtractor"/> class to process determine the query terms and 
-	/// their boosts to be used. 
-	/// </summary>
-	/// <author>  mark@searcharea.co.uk
-	/// </author>
-	//TODO: provide option to boost score of fragments near beginning of document 
-	// based on fragment.getFragNum()
-	public class QueryScorer : Scorer
-	{
-		internal TextFragment currentTextFragment = null;
-		internal System.Collections.Hashtable uniqueTermsInFragment;
-		internal float totalScore = 0;
-		internal float maxTermWeight = 0;
-		private System.Collections.Hashtable termsToFind;
-		
-		
-		/// <summary> </summary>
-		/// <param name="query">a Lucene query (ideally rewritten using query.rewrite 
-		/// before being passed to this class and the searcher)
-		/// </param>
-		public QueryScorer(Query query):this(QueryTermExtractor.GetTerms(query))
-		{
-		}
-		
-		/// <summary> </summary>
-		/// <param name="query">a Lucene query (ideally rewritten using query.rewrite 
-		/// before being passed to this class and the searcher)
-		/// </param>
-		/// <param name="fieldName">the Field name which is used to match Query terms
-		/// </param>
-		public QueryScorer(Query query, System.String fieldName):this(QueryTermExtractor.GetTerms(query, false, fieldName))
-		{
-		}
-		
-		/// <summary> </summary>
-		/// <param name="query">a Lucene query (ideally rewritten using query.rewrite 
-		/// before being passed to this class and the searcher)
-		/// </param>
-		/// <param name="reader">used to compute IDF which can be used to a) score selected fragments better 
-		/// b) use graded highlights eg set font color intensity
-		/// </param>
-		/// <param name="fieldName">the field on which Inverse Document Frequency (IDF) calculations are based
-		/// </param>
-		public QueryScorer(Query query, IndexReader reader, System.String fieldName):this(QueryTermExtractor.GetIdfWeightedTerms(query, reader, fieldName))
-		{
-		}
-		
-		public QueryScorer(WeightedTerm[] weightedTerms)
-		{
-			termsToFind = new System.Collections.Hashtable();
-			for (int i = 0; i < weightedTerms.Length; i++)
-			{
-				WeightedTerm existingTerm = (WeightedTerm) termsToFind[weightedTerms[i].term];
-				if ((existingTerm == null) || (existingTerm.weight < weightedTerms[i].weight))
-				{
-					//if a term is defined more than once, always use the highest scoring weight
-					termsToFind[weightedTerms[i].term] = weightedTerms[i];
-					maxTermWeight = System.Math.Max(maxTermWeight, weightedTerms[i].GetWeight());
-				}
-			}
-		}
-		
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.FragmentScorer.startFragment(Lucene.Net.Highlight.TextFragment)"/>
-		*/
-		public virtual void  StartFragment(TextFragment newFragment)
-		{
-			uniqueTermsInFragment = new System.Collections.Hashtable();
-			currentTextFragment = newFragment;
-			totalScore = 0;
-		}
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.FragmentScorer.scoreToken(org.apache.lucene.analysis.Token)"/>
-		*/
-		public virtual float GetTokenScore(Token token)
-		{
-			System.String termText = token.Term();
-			
-			WeightedTerm queryTerm = (WeightedTerm) termsToFind[termText];
-			if (queryTerm == null)
-			{
-				//not a query term - return
-				return 0;
-			}
-			//found a query term - is it unique in this doc?
-			if (!uniqueTermsInFragment.Contains(termText))
-			{
-				totalScore += queryTerm.GetWeight();
-				uniqueTermsInFragment.Add(termText, termText);
-			}
-			return queryTerm.GetWeight();
-		}
-		
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.FragmentScorer.endFragment(Lucene.Net.Highlight.TextFragment)"/>
-		*/
-		public virtual float GetFragmentScore()
-		{
-			return totalScore;
-		}
-		
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.FragmentScorer.allFragmentsProcessed()"/>
-		*/
-		public virtual void  AllFragmentsProcessed()
-		{
-			//this class has no special operations to perform at end of processing
-		}
-		
-		/// <summary> </summary>
-		/// <returns> The highest weighted term (useful for passing to GradientFormatter to set
-		/// top end of coloring scale.  
-		/// </returns>
-		public virtual float GetMaxTermWeight()
-		{
-			return maxTermWeight;
-		}
-	}
+
+    ///<summary>
+    /// <see cref="IScorer"/> implementation which scores text fragments by the number of
+    /// unique query terms found. This class converts appropriate <see cref="Query"/>s to
+    /// <see cref="SpanQuery"/>s and attempts to score only those terms that participated in
+    /// generating the 'hit' on the document.
+    /// </summary>
+    public class QueryScorer : IScorer
+    {
+        private float totalScore;
+        private ISet<String> foundTerms;
+        private IDictionary<String, WeightedSpanTerm> fieldWeightedSpanTerms;
+        private float maxTermWeight;
+        private int position = -1;
+        private String defaultField;
+        private TermAttribute termAtt;
+        private PositionIncrementAttribute posIncAtt;
+        private bool expandMultiTermQuery = true;
+        private Query query;
+        private String field;
+        private IndexReader reader;
+        private bool skipInitExtractor;
+        private bool wrapToCaching = true;
+
+        /**
+         * @param query Query to use for highlighting
+         */
+
+        public QueryScorer(Query query)
+        {
+            init(query, null, null, true);
+        }
+
+        /**
+         * @param query Query to use for highlighting
+         * @param field Field to highlight - pass null to ignore fields
+         */
+
+        public QueryScorer(Query query, String field)
+        {
+            init(query, field, null, true);
+        }
+
+        /**
+         * @param query Query to use for highlighting
+         * @param field Field to highlight - pass null to ignore fields
+         * @param reader {@link IndexReader} to use for quasi tf/idf scoring
+         */
+
+        public QueryScorer(Query query, IndexReader reader, String field)
+        {
+            init(query, field, reader, true);
+        }
+
+
+        /**
+         * @param query to use for highlighting
+         * @param reader {@link IndexReader} to use for quasi tf/idf scoring
+         * @param field to highlight - pass null to ignore fields
+         * @param defaultField
+         */
+
+        public QueryScorer(Query query, IndexReader reader, String field, String defaultField)
+        {
+            this.defaultField = StringHelper.Intern(defaultField);
+            init(query, field, reader, true);
+        }
+
+        /**
+         * @param defaultField - The default field for queries with the field name unspecified
+         */
+
+        public QueryScorer(Query query, String field, String defaultField)
+        {
+            this.defaultField = StringHelper.Intern(defaultField);
+            init(query, field, null, true);
+        }
+
+        /**
+         * @param weightedTerms an array of pre-created {@link WeightedSpanTerm}s
+         */
+
+        public QueryScorer(WeightedSpanTerm[] weightedTerms)
+        {
+            this.fieldWeightedSpanTerms = new HashMap<String, WeightedSpanTerm>(weightedTerms.Length);
+
+            for (int i = 0; i < weightedTerms.Length; i++)
+            {
+                WeightedSpanTerm existingTerm = fieldWeightedSpanTerms[weightedTerms[i].term];
+
+                if ((existingTerm == null) ||
+                    (existingTerm.weight < weightedTerms[i].weight))
+                {
+                    // if a term is defined more than once, always use the highest
+                    // scoring weight
+                    fieldWeightedSpanTerms[weightedTerms[i].term] = weightedTerms[i];
+                    maxTermWeight = Math.Max(maxTermWeight, weightedTerms[i].GetWeight());
+                }
+            }
+            skipInitExtractor = true;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.apache.lucene.search.highlight.Scorer#getFragmentScore()
+         */
+
+        public float getFragmentScore()
+        {
+            return totalScore;
+        }
+
+        /**
+         *
+         * @return The highest weighted term (useful for passing to
+         *         GradientFormatter to set top end of coloring scale).
+         */
+
+        public float getMaxTermWeight()
+        {
+            return maxTermWeight;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.apache.lucene.search.highlight.Scorer#getTokenScore(org.apache.lucene.analysis.Token,
+         *      int)
+         */
+
+        public float getTokenScore()
+        {
+            position += posIncAtt.PositionIncrement;
+            String termText = termAtt.Term();
+
+            WeightedSpanTerm weightedSpanTerm;
+
+            if ((weightedSpanTerm = fieldWeightedSpanTerms[termText]) == null)
+            {
+                return 0;
+            }
+
+            if (weightedSpanTerm.isPositionSensitive() &&
+                !weightedSpanTerm.checkPosition(position))
+            {
+                return 0;
+            }
+
+            float score = weightedSpanTerm.GetWeight();
+
+            // found a query term - is it unique in this doc?
+            if (!foundTerms.Contains(termText))
+            {
+                totalScore += score;
+                foundTerms.Add(termText);
+            }
+
+            return score;
+        }
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Scorer#init(org.apache.lucene.analysis.TokenStream)
+         */
+
+        public TokenStream init(TokenStream tokenStream)
+        {
+            position = -1;
+            termAtt = tokenStream.AddAttribute<TermAttribute>();
+            posIncAtt = tokenStream.AddAttribute<PositionIncrementAttribute>();
+            if (!skipInitExtractor)
+            {
+                if (fieldWeightedSpanTerms != null)
+                {
+                    fieldWeightedSpanTerms.Clear();
+                }
+                return initExtractor(tokenStream);
+            }
+            return null;
+        }
+
+        /**
+         * Retrieve the {@link WeightedSpanTerm} for the specified token. Useful for passing
+         * Span information to a {@link Fragmenter}.
+         *
+         * @param token to get {@link WeightedSpanTerm} for
+         * @return WeightedSpanTerm for token
+         */
+
+        public WeightedSpanTerm getWeightedSpanTerm(String token)
+        {
+            return fieldWeightedSpanTerms[token];
+        }
+
+        /**
+         */
+
+        private void init(Query query, String field, IndexReader reader, bool expandMultiTermQuery)
+        {
+            this.reader = reader;
+            this.expandMultiTermQuery = expandMultiTermQuery;
+            this.query = query;
+            this.field = field;
+        }
+
+        private TokenStream initExtractor(TokenStream tokenStream)
+        {
+            WeightedSpanTermExtractor qse = defaultField == null
+                                                ? new WeightedSpanTermExtractor()
+                                                : new WeightedSpanTermExtractor(defaultField);
+
+            qse.setExpandMultiTermQuery(expandMultiTermQuery);
+            qse.setWrapIfNotCachingTokenFilter(wrapToCaching);
+            if (reader == null)
+            {
+                this.fieldWeightedSpanTerms = qse.getWeightedSpanTerms(query,
+                                                                       tokenStream, field);
+            }
+            else
+            {
+                this.fieldWeightedSpanTerms = qse.getWeightedSpanTermsWithScores(query,
+                                                                                 tokenStream, field, reader);
+            }
+            if (qse.isCachedTokenStream())
+            {
+                return qse.getTokenStream();
+            }
+
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.apache.lucene.search.highlight.Scorer#startFragment(org.apache.lucene.search.highlight.TextFragment)
+         */
+
+        public void startFragment(TextFragment newFragment)
+        {
+            foundTerms = new HashSet<String>();
+            totalScore = 0;
+        }
+
+        /**
+         * @return true if multi-term queries should be expanded
+         */
+
+        public bool isExpandMultiTermQuery()
+        {
+            return expandMultiTermQuery;
+        }
+
+        /**
+         * Controls whether or not multi-term queries are expanded
+         * against a {@link MemoryIndex} {@link IndexReader}.
+         * 
+         * @param expandMultiTermQuery true if multi-term queries should be expanded
+         */
+
+        public void setExpandMultiTermQuery(bool expandMultiTermQuery)
+        {
+            this.expandMultiTermQuery = expandMultiTermQuery;
+        }
+
+        /**
+         * By default, {@link TokenStream}s that are not of the type
+         * {@link CachingTokenFilter} are wrapped in a {@link CachingTokenFilter} to
+         * ensure an efficient reset - if you are already using a different caching
+         * {@link TokenStream} impl and you don't want it to be wrapped, set this to
+         * false.
+         * 
+         * @param wrap
+         */
+
+        public void setWrapIfNotCachingTokenFilter(bool wrap)
+        {
+            this.wrapToCaching = wrap;
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermExtractor.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermExtractor.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermExtractor.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermExtractor.cs Fri Mar 23 20:16:37 2012
@@ -17,23 +17,20 @@
 
 using System;
 using System.Collections.Generic;
-using IndexReader = Lucene.Net.Index.IndexReader;
-using Term = Lucene.Net.Index.Term;
-using BooleanClause = Lucene.Net.Search.BooleanClause;
-using BooleanQuery = Lucene.Net.Search.BooleanQuery;
-using FilteredQuery = Lucene.Net.Search.FilteredQuery;
-using Query = Lucene.Net.Search.Query;
+using System.IO;
+using System.Linq;
+using Lucene.Net.Highlight;
+using Lucene.Net.Index;
+using Lucene.Net.Util;
 
-namespace Lucene.Net.Highlight
+namespace Lucene.Net.Search.Highlight
 {
 	
 	/// <summary> Utility class used to extract the terms used in a query, plus any weights.
 	/// This class will not find terms for MultiTermQuery, RangeQuery and PrefixQuery classes
 	/// so the caller must pass a rewritten query (see Query.rewrite) to obtain a list of 
-	/// expanded terms. 
-	/// 
-	/// </summary>
-	public sealed class QueryTermExtractor
+	/// expanded terms.</summary>
+	public static class QueryTermExtractor
 	{
 		
 		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
@@ -51,63 +48,51 @@ namespace Lucene.Net.Highlight
 		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
 		/// 
 		/// </summary>
-		/// <param name="query">     Query to extract term texts from
-		/// </param>
+		/// <param name="query">Query to extract term texts from</param>
 		/// <param name="reader">used to compute IDF which can be used to a) score selected fragments better 
-		/// b) use graded highlights eg chaning intensity of font color
-		/// </param>
-		/// <param name="fieldName">the field on which Inverse Document Frequency (IDF) calculations are based
-		/// </param>
-		/// <returns> an array of the terms used in a query, plus their weights.
-		/// </returns>
-		public static WeightedTerm[] GetIdfWeightedTerms(Query query, IndexReader reader, System.String fieldName)
-		{
-			WeightedTerm[] terms = GetTerms(query, false, fieldName);
-			int totalNumDocs = reader.GetNumDocs();
-			for (int i = 0; i < terms.Length; i++)
-			{
-				try
-				{
-					int docFreq = reader.DocFreq(new Term(fieldName, terms[i].term));
-					//IDF algorithm taken from DefaultSimilarity class
-					float idf = (float) (System.Math.Log((float) totalNumDocs / (double) (docFreq + 1)) + 1.0);
-					terms[i].weight *= idf;
-				}
-				catch (System.IO.IOException e)
-				{
-					//ignore 
-				}
-			}
-			return terms;
+		/// b) use graded highlights eg chaning intensity of font color</param>
+		/// <param name="fieldName">the field on which Inverse Document Frequency (IDF) calculations are based</param>
+		/// <returns> an array of the terms used in a query, plus their weights.</returns>
+		public static WeightedTerm[] GetIdfWeightedTerms(Query query, IndexReader reader, string fieldName)
+		{
+            WeightedTerm[] terms = GetTerms(query, false, fieldName);
+            int totalNumDocs = reader.NumDocs();
+            foreach (WeightedTerm t in terms)
+            {
+                try
+                {
+                    int docFreq = reader.DocFreq(new Term(fieldName, t.term));
+                    // docFreq counts deletes
+                    if (totalNumDocs < docFreq)
+                    {
+                        docFreq = totalNumDocs;
+                    }
+                    //IDF algorithm taken from DefaultSimilarity class
+                    var idf = (float)(Math.Log((float)totalNumDocs / (double)(docFreq + 1)) + 1.0);
+                    t.weight *= idf;
+                }
+                catch (IOException e)
+                {
+                    //ignore 
+                }
+            }
+		    return terms;
 		}
 		
-		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
-		/// 
-		/// </summary>
-		/// <param name="query">     Query to extract term texts from
-		/// </param>
-		/// <param name="prohibited"><c>true</c> to extract "prohibited" terms, too
-		/// </param>
-		/// <param name="fieldName"> The fieldName used to filter query terms
-		/// </param>
-		/// <returns> an array of the terms used in a query, plus their weights.
-		/// </returns>
-		public static WeightedTerm[] GetTerms(Query query, bool prohibited, System.String fieldName)
+		/// <summary>Extracts all terms texts of a given Query into an array of WeightedTerms</summary>
+		/// <param name="query">Query to extract term texts from</param>
+		/// <param name="prohibited"><c>true</c> to extract "prohibited" terms, too </param>
+		/// <param name="fieldName"> The fieldName used to filter query terms</param>
+		/// <returns>an array of the terms used in a query, plus their weights.</returns>
+		public static WeightedTerm[] GetTerms(Query query, bool prohibited, string fieldName)
 		{
-			System.Collections.Hashtable terms = new System.Collections.Hashtable();
-			if (fieldName != null)
-			{
-				fieldName = String.Intern(fieldName);
-			}
-			GetTerms(query, terms, prohibited, fieldName);
-
-            WeightedTerm[] result = new WeightedTerm[terms.Count];
-            int i = 0;
-            foreach (System.Object item in terms.Values)
+            var terms = new HashSet<WeightedTerm>();
+            if (fieldName != null)
             {
-                result[i++] = (WeightedTerm) item;
+                fieldName = StringHelper.Intern(fieldName);
             }
-            return (result);
+            GetTerms(query, terms, prohibited, fieldName);
+            return terms.ToArray();
 		}
 		
 		/// <summary> Extracts all terms texts of a given Query into an array of WeightedTerms
@@ -125,36 +110,34 @@ namespace Lucene.Net.Highlight
 		}
 		
 		//fieldname MUST be interned prior to this call
-		private static void  GetTerms(Query query, System.Collections.Hashtable terms, bool prohibited, System.String fieldName)
-		{
-			try
-			{
-				if (query is BooleanQuery)
-					GetTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
-				else if (query is FilteredQuery)
-					GetTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
-				else
-				{
-					var nonWeightedTerms = new HashSet<Term>();
-					query.ExtractTerms(nonWeightedTerms);
-
+        private static void GetTerms(Query query, HashSet<WeightedTerm> terms, bool prohibited, string fieldName)
+        {
+            try
+            {
+                if (query is BooleanQuery)
+                    GetTermsFromBooleanQuery((BooleanQuery) query, terms, prohibited, fieldName);
+                else if (query is FilteredQuery)
+                    GetTermsFromFilteredQuery((FilteredQuery) query, terms, prohibited, fieldName);
+                else
+                {
+                    HashSet<Term> nonWeightedTerms = new HashSet<Term>();
+                    query.ExtractTerms(nonWeightedTerms);
                     foreach (var term in nonWeightedTerms)
                     {
                         if ((fieldName == null) || (term.Field == fieldName))
                         {
-                            var temp = new WeightedTerm(query.Boost, term.Text);
-                            terms.Add(temp, temp);
+                            terms.Add(new WeightedTerm(query.Boost, term.Text));
                         }
                     }
-				}
-			}
-			catch (System.NotSupportedException ignore)
-			{
-				//this is non-fatal for our purposes
-			}
-		}
-		
-		/// <summary> extractTerms is currently the only query-independent means of introspecting queries but it only reveals
+                }
+            }
+            catch (System.NotSupportedException ignore)
+            {
+                //this is non-fatal for our purposes
+            }
+        }
+
+	    /// <summary> extractTerms is currently the only query-independent means of introspecting queries but it only reveals
 		/// a list of terms for that query - not the boosts each individual term in that query may or may not have.
 		/// "Container" queries such as BooleanQuery should be unwrapped to get at the boost info held
 		/// in each child element. 
@@ -164,16 +147,16 @@ namespace Lucene.Net.Highlight
 		/// something common which would allow access to child queries so what follows here are query-specific
 		/// implementations for accessing embedded query elements. 
 		/// </summary>
-		private static void  GetTermsFromBooleanQuery(BooleanQuery query, System.Collections.Hashtable terms, bool prohibited, System.String fieldName)
+		private static void  GetTermsFromBooleanQuery(BooleanQuery query, HashSet<WeightedTerm> terms, bool prohibited, string fieldName)
 		{
-			BooleanClause[] queryClauses = query.GetClauses();
-			for (int i = 0; i < queryClauses.Length; i++)
-			{
-				if (prohibited || queryClauses[i].GetOccur() != BooleanClause.Occur.MUST_NOT)
-					GetTerms(queryClauses[i].GetQuery(), terms, prohibited, fieldName);
-			}
+            BooleanClause[] queryClauses = query.GetClauses();
+            for (int i = 0; i < queryClauses.Length; i++)
+            {
+                if (prohibited || queryClauses[i].GetOccur() != BooleanClause.Occur.MUST_NOT)
+                    GetTerms(queryClauses[i].GetQuery(), terms, prohibited, fieldName);
+            }
 		}
-		private static void  GetTermsFromFilteredQuery(FilteredQuery query, System.Collections.Hashtable terms, bool prohibited, System.String fieldName)
+        private static void GetTermsFromFilteredQuery(FilteredQuery query, HashSet<WeightedTerm> terms, bool prohibited, string fieldName)
 		{
 			GetTerms(query.Query, terms, prohibited, fieldName);
 		}

Added: incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermScorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermScorer.cs?rev=1304578&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermScorer.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/QueryTermScorer.cs Fri Mar 23 20:16:37 2012
@@ -0,0 +1,170 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Highlight;
+using Lucene.Net.Index;
+using Lucene.Net.Support;
+
+namespace Lucene.Net.Search.Highlight
+{
+    /**
+ * {@link Scorer} implementation which scores text fragments by the number of
+ * unique query terms found. This class uses the {@link QueryTermExtractor}
+ * class to process determine the query terms and their boosts to be used.
+ */
+    // TODO: provide option to boost score of fragments near beginning of document
+    // based on fragment.getFragNum()
+    public class QueryTermScorer : IScorer
+    {
+        private TextFragment currentTextFragment = null;
+        private HashSet<String> uniqueTermsInFragment;
+
+        private float totalScore = 0;
+        private float maxTermWeight = 0;
+        private HashMap<String, WeightedTerm> termsToFind;
+
+        private TermAttribute termAtt;
+
+        /**
+         * 
+         * @param query a Lucene query (ideally rewritten using query.rewrite before
+         *        being passed to this class and the searcher)
+         */
+
+        public QueryTermScorer(Query query)
+            : this(QueryTermExtractor.GetTerms(query))
+        {
+        }
+
+        /**
+         * 
+         * @param query a Lucene query (ideally rewritten using query.rewrite before
+         *        being passed to this class and the searcher)
+         * @param fieldName the Field name which is used to match Query terms
+         */
+
+        public QueryTermScorer(Query query, String fieldName)
+            : this(QueryTermExtractor.GetTerms(query, false, fieldName))
+        {
+        }
+
+        /**
+         * 
+         * @param query a Lucene query (ideally rewritten using query.rewrite before
+         *        being passed to this class and the searcher)
+         * @param reader used to compute IDF which can be used to a) score selected
+         *        fragments better b) use graded highlights eg set font color
+         *        intensity
+         * @param fieldName the field on which Inverse Document Frequency (IDF)
+         *        calculations are based
+         */
+
+        public QueryTermScorer(Query query, IndexReader reader, String fieldName)
+            : this(QueryTermExtractor.GetIdfWeightedTerms(query, reader, fieldName))
+        {
+        }
+
+        public QueryTermScorer(WeightedTerm[] weightedTerms)
+        {
+            termsToFind = new HashMap<String, WeightedTerm>();
+            for (int i = 0; i < weightedTerms.Length; i++)
+            {
+                WeightedTerm existingTerm = termsToFind[weightedTerms[i].term];
+                if ((existingTerm == null)
+                    || (existingTerm.weight < weightedTerms[i].weight))
+                {
+                    // if a term is defined more than once, always use the highest scoring
+                    // weight
+                    termsToFind[weightedTerms[i].term] = weightedTerms[i];
+                    maxTermWeight = Math.Max(maxTermWeight, weightedTerms[i].GetWeight());
+                }
+            }
+        }
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Scorer#init(org.apache.lucene.analysis.TokenStream)
+         */
+
+        public TokenStream init(TokenStream tokenStream)
+        {
+            termAtt = tokenStream.AddAttribute<TermAttribute>();
+            return null;
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see
+         * org.apache.lucene.search.highlight.FragmentScorer#startFragment(org.apache
+         * .lucene.search.highlight.TextFragment)
+         */
+
+        public void startFragment(TextFragment newFragment)
+        {
+            uniqueTermsInFragment = new HashSet<String>();
+            currentTextFragment = newFragment;
+            totalScore = 0;
+
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Scorer#getTokenScore()
+         */
+
+        public float getTokenScore()
+        {
+            String termText = termAtt.Term();
+
+            WeightedTerm queryTerm = termsToFind[termText];
+            if (queryTerm == null)
+            {
+                // not a query term - return
+                return 0;
+            }
+            // found a query term - is it unique in this doc?
+            if (!uniqueTermsInFragment.Contains(termText))
+            {
+                totalScore += queryTerm.GetWeight();
+                uniqueTermsInFragment.Add(termText);
+            }
+            return queryTerm.GetWeight();
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Scorer#getFragmentScore()
+         */
+
+        public float getFragmentScore()
+        {
+            return totalScore;
+        }
+
+        /*
+         * (non-Javadoc)
+         * 
+         * @see
+         * org.apache.lucene.search.highlight.FragmentScorer#allFragmentsProcessed()
+         */
+
+        public void allFragmentsProcessed()
+        {
+            // this class has no special operations to perform at end of processing
+        }
+
+        /**
+         * 
+         * @return The highest weighted term (useful for passing to GradientFormatter
+         *         to set top end of coloring scale.
+         */
+
+        public float getMaxTermWeight()
+        {
+            return maxTermWeight;
+        }
+    }
+}
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/Scorer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/Scorer.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/Scorer.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/Scorer.cs Fri Mar 23 20:16:37 2012
@@ -15,35 +15,48 @@
  * limitations under the License.
  */
 
-using System;
-using Token = Lucene.Net.Analysis.Token;
+using System.IO;
+using Lucene.Net.Analysis;
 
 namespace Lucene.Net.Highlight
 {
-	
-	/// <summary> Adds to the score for a fragment based on its tokens</summary>
-	/// <author>  mark@searcharea.co.uk
-	/// </author>
-	public interface Scorer
-	{
-		/// <summary> called when a new fragment is started for consideration</summary>
-        /// <param name="newFragment"></param>
-		void  StartFragment(TextFragment newFragment);
-		
-		/// <summary> Called for each token in the current fragment</summary>
-		/// <param name="token">The token to be scored
-		/// </param>
-		/// <returns> a score which is passed to the Highlighter class to influence the mark-up of the text
-		/// (this return value is NOT used to score the fragment)
-		/// </returns>
-		float GetTokenScore(Token token);
-		
-		
-		/// <summary> Called when the highlighter has no more tokens for the current fragment - the scorer returns
-		/// the weighting it has derived for the most recent fragment, typically based on the tokens
-		/// passed to getTokenScore(). 
-		/// 
-		/// </summary>
-		float GetFragmentScore();
-	}
+    /// <summary> Adds to the score for a fragment based on its tokens</summary>
+    public interface IScorer
+    {
+        /// <summary>
+        /// Called to init the Scorer with a {@link TokenStream}. You can grab references to
+        /// the attributes you are interested in here and access them from {@link #getTokenScore()}.
+        /// </summary>
+        /// <param name="tokenStream">the {@link TokenStream} that will be scored.</param>
+        /// <returns>
+        /// either a {@link TokenStream} that the Highlighter should continue using (eg
+        /// if you read the tokenSream in this method) or null to continue
+        /// using the same {@link TokenStream} that was passed in.
+        /// </returns> 
+        /// <exception cref="IOException"></exception>
+        ///
+        TokenStream init(TokenStream tokenStream);
+
+        /// <summary>
+        /// Called when a new fragment is started for consideration.
+        /// </summary>
+        /// <param name="newFragment">the fragment that will be scored next</param>
+        void startFragment(TextFragment newFragment);
+
+        /// <summary>
+        /// Called for each token in the current fragment. The {@link Highlighter} will
+        /// increment the {@link TokenStream} passed to init on every call.
+        /// </summary>
+        /// <returns>a score which is passed to the {@link Highlighter} class to influence the
+        /// mark-up of the text (this return value is NOT used to score the
+        /// fragment)</returns> 
+        float getTokenScore();
+
+        ///<summary>
+        /// Called when the {@link Highlighter} has no more tokens for the current fragment -
+        /// the Scorer returns the weighting it has derived for the most recent
+        /// fragment, typically based on the results of {@link #getTokenScore()}.
+        /// </summary>
+        float getFragmentScore();
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleFragmenter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleFragmenter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleFragmenter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleFragmenter.cs Fri Mar 23 20:16:37 2012
@@ -16,69 +16,83 @@
  */
 
 using System;
+using Lucene.Net.Analysis;
+using Lucene.Net.Analysis.Tokenattributes;
+using Lucene.Net.Search.Highlight;
 using Token = Lucene.Net.Analysis.Token;
 
 namespace Lucene.Net.Highlight
 {
-	
-	/// <summary> <see cref="Fragmenter"/> implementation which breaks text up into same-size 
-	/// fragments with no concerns over spotting sentence boundaries.
-	/// </summary>
-	/// <author>  mark@searcharea.co.uk
-	/// </author>
-	public class SimpleFragmenter : Fragmenter
-	{
-		private const int DEFAULT_FRAGMENT_SIZE = 100;
-		private int currentNumFrags;
-		private int fragmentSize;
-		
-		
-		public SimpleFragmenter():this(DEFAULT_FRAGMENT_SIZE)
-		{
-		}
-		
-		
-		/// <summary> </summary>
-		/// <param name="fragmentSize">size in bytes of each fragment
-		/// </param>
-		public SimpleFragmenter(int fragmentSize)
-		{
-			this.fragmentSize = fragmentSize;
-		}
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.TextFragmenter.start(java.lang.String)"/>
-		*/
-		public virtual void  Start(System.String originalText)
-		{
-			currentNumFrags = 1;
-		}
-		
-		/* (non-Javadoc)
-		* <see cref="Lucene.Net.Highlight.TextFragmenter.isNewFragment(org.apache.lucene.analysis.Token)"/>
-		*/
-		public virtual bool IsNewFragment(Token token)
-		{
-			bool isNewFrag = token.EndOffset >= (fragmentSize * currentNumFrags);
-			if (isNewFrag)
-			{
-				currentNumFrags++;
-			}
-			return isNewFrag;
-		}
-		
-		/// <returns> size in bytes of each fragment
-		/// </returns>
-		public virtual int GetFragmentSize()
-		{
-			return fragmentSize;
-		}
-		
-		/// <param name="size">size in bytes of each fragment
-		/// </param>
-		public virtual void  SetFragmentSize(int size)
-		{
-			fragmentSize = size;
-		}
-	}
+
+    /// <summary> <see cref="IFragmenter"/> implementation which breaks text up into same-size 
+    /// fragments with no concerns over spotting sentence boundaries.
+    /// </summary>
+    /// <author>  mark@searcharea.co.uk
+    /// </author>
+    public class SimpleFragmenter : IFragmenter
+    {
+        private static int DEFAULT_FRAGMENT_SIZE = 100;
+        private int currentNumFrags;
+        private int fragmentSize;
+        private OffsetAttribute offsetAtt;
+
+        public SimpleFragmenter()
+            : this(DEFAULT_FRAGMENT_SIZE)
+        {
+        }
+
+        /**
+         * 
+         * @param fragmentSize size in number of characters of each fragment
+         */
+
+        public SimpleFragmenter(int fragmentSize)
+        {
+            this.fragmentSize = fragmentSize;
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Fragmenter#start(java.lang.String, org.apache.lucene.analysis.TokenStream)
+         */
+
+        public void Start(String originalText, TokenStream stream)
+        {
+            offsetAtt = stream.AddAttribute<OffsetAttribute>();
+            currentNumFrags = 1;
+        }
+
+
+        /* (non-Javadoc)
+         * @see org.apache.lucene.search.highlight.Fragmenter#isNewFragment()
+         */
+
+        public bool IsNewFragment()
+        {
+            bool isNewFrag = offsetAtt.EndOffset >= (fragmentSize*currentNumFrags);
+            if (isNewFrag)
+            {
+                currentNumFrags++;
+            }
+            return isNewFrag;
+        }
+
+        /**
+         * @return size in number of characters of each fragment
+         */
+
+        public int getFragmentSize()
+        {
+            return fragmentSize;
+        }
+
+        /**
+         * @param size size in characters of each fragment
+         */
+
+        public void setFragmentSize(int size)
+        {
+            fragmentSize = size;
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLEncoder.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLEncoder.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLEncoder.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLEncoder.cs Fri Mar 23 20:16:37 2012
@@ -16,76 +16,71 @@
  */
 
 using System;
+using System.Text;
+using Lucene.Net.Search.Highlight;
 
 namespace Lucene.Net.Highlight
 {
-	/// <summary> Simple <see cref="Encoder"/> implementation to escape text for HTML output</summary>
-	/// <author>  Nicko Cadell
-	/// 
-	/// </author>
-	public class SimpleHTMLEncoder : Encoder
-	{
-		public SimpleHTMLEncoder()
-		{
-		}
-		
-		public virtual System.String EncodeText(System.String originalText)
-		{
-			return HtmlEncode(originalText);
-		}
-		
-		/// <summary> Encode string into HTML</summary>
-		public static System.String HtmlEncode(System.String plainText)
-		{
-			if (plainText == null || plainText.Length == 0)
-			{
-				return "";
-			}
-			
-			System.Text.StringBuilder result = new System.Text.StringBuilder(plainText.Length);
-			
-			for (int index = 0; index < plainText.Length; index++)
-			{
-				char ch = plainText[index];
-				
-				switch (ch)
-				{
-					
-					case '"': 
-						result.Append("&quot;");
-						break;
-					
-					
-					case '&': 
-						result.Append("&amp;");
-						break;
-					
-					
-					case '<': 
-						result.Append("&lt;");
-						break;
-					
-					
-					case '>': 
-						result.Append("&gt;");
-						break;
-					
-					
-					default: 
-						if (ch < 128)
-						{
-							result.Append(ch);
-						}
-						else
-						{
-							result.Append("&#").Append((int) ch).Append(";");
-						}
-						break;
-					
-				}
-			}
-			
-			return result.ToString();
-		}
-	}
+    /// <summary> Simple <see cref="IEncoder"/> implementation to escape text for HTML output</summary>
+    public class SimpleHTMLEncoder : IEncoder
+    {
+        public SimpleHTMLEncoder()
+        {
+        }
+
+        public String EncodeText(String originalText)
+        {
+            return HtmlEncode(originalText);
+        }
+
+        /**
+         * Encode string into HTML
+         */
+        public static String HtmlEncode(String plainText)
+        {
+            if (string.IsNullOrEmpty(plainText))
+            {
+                return string.Empty;
+            }
+
+            var result = new StringBuilder(plainText.Length);
+
+            for (int index = 0; index < plainText.Length; index++)
+            {
+                char ch = plainText[index];
+
+                switch (ch)
+                {
+                    case '"':
+                        result.Append("&quot;");
+                        break;
+
+                    case '&':
+                        result.Append("&amp;");
+                        break;
+
+                    case '<':
+                        result.Append("&lt;");
+                        break;
+
+                    case '>':
+                        result.Append("&gt;");
+                        break;
+
+                    default:
+                        if (ch < 128)
+                        {
+                            result.Append(ch);
+                        }
+                        else
+                        {
+                            result.Append("&#").Append((int)ch).Append(";");
+                        }
+                        break;
+                }
+            }
+
+            return result.ToString();
+        }
+    }
 }
\ No newline at end of file

Modified: incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLFormatter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLFormatter.cs?rev=1304578&r1=1304577&r2=1304578&view=diff
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLFormatter.cs (original)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/SimpleHTMLFormatter.cs Fri Mar 23 20:16:37 2012
@@ -16,14 +16,15 @@
  */
 
 using System;
+using Lucene.Net.Search.Highlight;
 
 namespace Lucene.Net.Highlight
 {
-	/// <summary> Simple <see cref="Formatter"/> implementation to highlight terms with a pre and post tag</summary>
+	/// <summary> Simple <see cref="IFormatter"/> implementation to highlight terms with a pre and post tag</summary>
 	/// <author>  MAHarwood
 	/// 
 	/// </author>
-	public class SimpleHTMLFormatter : Formatter
+	public class SimpleHTMLFormatter : IFormatter
 	{
 		internal System.String preTag;
 		internal System.String postTag;

Added: incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTerm.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTerm.cs?rev=1304578&view=auto
==============================================================================
--- incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTerm.cs (added)
+++ incubator/lucene.net/trunk/src/contrib/Highlighter/WeightedSpanTerm.cs Fri Mar 23 20:16:37 2012
@@ -0,0 +1,121 @@
+/**
+ * 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 System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Lucene.Net.Highlight;
+
+namespace Lucene.Net.Search.Highlight
+{
+    /**
+     * Lightweight class to hold term, weight, and positions used for scoring this
+     * term.
+     */
+
+    public class WeightedSpanTerm : WeightedTerm
+    {
+        private bool positionSensitive;
+        private List<PositionSpan> positionSpans = new List<PositionSpan>();
+
+        /**
+         * @param weight
+         * @param term
+         */
+
+        public WeightedSpanTerm(float weight, String term)
+            : base(weight, term)
+        {
+
+            this.positionSpans = new List<PositionSpan>();
+        }
+
+        /**
+         * @param weight
+         * @param term
+         * @param positionSensitive
+         */
+
+        public WeightedSpanTerm(float weight, String term, bool positionSensitive)
+            : base(weight, term)
+        {
+
+            this.positionSensitive = positionSensitive;
+        }
+
+        /**
+         * Checks to see if this term is valid at <code>position</code>.
+         *
+         * @param position
+         *            to check against valid term postions
+         * @return true iff this term is a hit at this position
+         */
+
+        public bool checkPosition(int position)
+        {
+            // There would probably be a slight speed improvement if PositionSpans
+            // where kept in some sort of priority queue - that way this method
+            // could
+            // bail early without checking each PositionSpan.
+
+            foreach (var positionSpan in positionSpans)
+            {
+                if (((position >= positionSpan.Start) && (position <= positionSpan.End)))
+                {
+                    return true;
+                }
+            }
+
+            return false;
+        }
+
+        public void addPositionSpans(List<PositionSpan> positionSpans)
+        {
+            this.positionSpans.AddRange(positionSpans);
+        }
+
+        public bool isPositionSensitive()
+        {
+            return positionSensitive;
+        }
+
+        public void setPositionSensitive(bool positionSensitive)
+        {
+            this.positionSensitive = positionSensitive;
+        }
+
+        public List<PositionSpan> getPositionSpans()
+        {
+            return positionSpans;
+        }
+    }
+
+
+    // Utility class to store a Span
+    public class PositionSpan
+    {
+        public int Start { get; private set; }
+        public int End { get; private set; }
+
+        public PositionSpan(int start, int end)
+        {
+            this.Start = start;
+            this.End = end;
+        }
+    }
+}



Mime
View raw message