lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aro...@apache.org
Subject svn commit: r533920 - in /incubator/lucene.net: tags/Lucene.Net_2_0_0/src/HISTORY.txt tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs trunk/C#/src/HISTORY.txt trunk/C#/src/Lucene.Net/Document/NumberTools.cs
Date Tue, 01 May 2007 03:15:25 GMT
Author: aroush
Date: Mon Apr 30 20:15:24 2007
New Revision: 533920

URL: http://svn.apache.org/viewvc?view=rev&rev=533920
Log:
Fixed LUCENENET-37 "Exception while search in Lucene.Net and Index prepared by Lucene Java"

Modified:
    incubator/lucene.net/tags/Lucene.Net_2_0_0/src/HISTORY.txt
    incubator/lucene.net/tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs
    incubator/lucene.net/trunk/C#/src/HISTORY.txt
    incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/NumberTools.cs

Modified: incubator/lucene.net/tags/Lucene.Net_2_0_0/src/HISTORY.txt
URL: http://svn.apache.org/viewvc/incubator/lucene.net/tags/Lucene.Net_2_0_0/src/HISTORY.txt?view=diff&rev=533920&r1=533919&r2=533920
==============================================================================
--- incubator/lucene.net/tags/Lucene.Net_2_0_0/src/HISTORY.txt (original)
+++ incubator/lucene.net/tags/Lucene.Net_2_0_0/src/HISTORY.txt Mon Apr 30 20:15:24 2007
@@ -2,6 +2,11 @@
 -------------------------
 
 
+30Apr07:
+	- Patch:  Apache Lucene.Net.2.0 build 005 "final"
+	- Fix: LUCENENET-37 "Exception while search in Lucene.Net and Index prepared by Lucene Java"
+
+
 11Mar07:
 	- Release:  Apache Lucene.Net.2.0 build 004 "final"
 	- Fix: LUCENENET-36 "Countries using "," as decimal separator gets an exception in QueryParser.cs
with a query like color~0.5"

Modified: incubator/lucene.net/tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs?view=diff&rev=533920&r1=533919&r2=533920
==============================================================================
--- incubator/lucene.net/tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs (original)
+++ incubator/lucene.net/tags/Lucene.Net_2_0_0/src/Lucene.Net/Document/NumberTools.cs Mon
Apr 30 20:15:24 2007
@@ -20,118 +20,186 @@
 namespace Lucene.Net.Documents
 {
 	
-	/// <summary> Provides support for converting longs to Strings, and back again. The
strings
-	/// are structured so that lexicographic sorting order is preserved.
-	/// 
-	/// <p>
-	/// That is, if l1 is less than l2 for any two longs l1 and l2, then
-	/// NumberTools.longToString(l1) is lexicographically less than
-	/// NumberTools.longToString(l2). (Similarly for "greater than" and "equals".)
-	/// 
-	/// <p>
-	/// This class handles <b>all</b> long values (unlike
-	/// {@link Lucene.Net.document.DateField}).
-	/// 
-	/// </summary>
-	/// <author>  Matt Quail (spud at madbean dot com)
-	/// </author>
-	public class NumberTools
-	{
-		
-		private const int RADIX = 16;
-		
-		private const char NEGATIVE_PREFIX = '-';
-		
-		// NB: NEGATIVE_PREFIX must be < POSITIVE_PREFIX
-		private const char POSITIVE_PREFIX = '0';
-		
-		//NB: this must be less than
-		/// <summary> Equivalent to longToString(Long.MIN_VALUE)</summary>
-		public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000000";
-		
-		/// <summary> Equivalent to longToString(Long.MAX_VALUE)</summary>
-		public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "7fffffffffffffff";
-		
-		/// <summary> The length of (all) strings returned by {@link #longToString}</summary>
-		public static readonly int STR_SIZE = MIN_STRING_VALUE.Length;
-		
-		/// <summary> Converts a long to a String suitable for indexing.</summary>
-		public static System.String LongToString(long l)
-		{
+    /// <summary> Provides support for converting longs to Strings, and back again.
The strings
+    /// are structured so that lexicographic sorting order is preserved.
+    /// 
+    /// <p>
+    /// That is, if l1 is less than l2 for any two longs l1 and l2, then
+    /// NumberTools.longToString(l1) is lexicographically less than
+    /// NumberTools.longToString(l2). (Similarly for "greater than" and "equals".)
+    /// 
+    /// <p>
+    /// This class handles <b>all</b> long values (unlike
+    /// {@link Lucene.Net.document.DateField}).
+    /// 
+    /// </summary>
+    /// <author>  Matt Quail (spud at madbean dot com)
+    /// </author>
+    public class NumberTools
+    {
+		
+        private const int RADIX = 16;
+		
+        private const char NEGATIVE_PREFIX = '-';
+		
+        // NB: NEGATIVE_PREFIX must be < POSITIVE_PREFIX
+        private const char POSITIVE_PREFIX = '0';
+		
+        //NB: this must be less than
+        /// <summary> Equivalent to longToString(Long.MIN_VALUE)</summary>
+#if LUCENE_JAVA_COMPATIBLE
+        public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000";
+#else
+        public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000000";
+#endif
+		
+        /// <summary> Equivalent to longToString(Long.MAX_VALUE)</summary>
+#if LUCENE_JAVA_COMPATIBLE
+		public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "1y2p0ij32e8e7";
+#else
+        public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "7fffffffffffffff";
+#endif
+		
+        /// <summary> The length of (all) strings returned by {@link #longToString}</summary>
+        public static readonly int STR_SIZE = MIN_STRING_VALUE.Length;
+		
+        /// <summary> Converts a long to a String suitable for indexing.</summary>
+        public static System.String LongToString(long l)
+        {
 
             if (l == System.Int64.MinValue)
-			{
-				// special case, because long is not symetric around zero
-				return MIN_STRING_VALUE;
-			}
-			
-			System.Text.StringBuilder buf = new System.Text.StringBuilder(STR_SIZE);
-			
-			if (l < 0)
-			{
-				buf.Append(NEGATIVE_PREFIX);
-				l = System.Int64.MaxValue + l + 1;
-			}
-			else
-			{
-				buf.Append(POSITIVE_PREFIX);
-			}
-			System.String num = System.Convert.ToString(l, RADIX);
-			
-			int padLen = STR_SIZE - num.Length - buf.Length;
-			while (padLen-- > 0)
-			{
-				buf.Append('0');
-			}
-			buf.Append(num);
-			
-			return buf.ToString();
-		}
-		
-		/// <summary> Converts a String that was returned by {@link #longToString} back to
a
-		/// long.
-		/// 
-		/// </summary>
-		/// <throws>  IllegalArgumentException </throws>
-		/// <summary>             if the input is null
-		/// </summary>
-		/// <throws>  NumberFormatException </throws>
-		/// <summary>             if the input does not parse (it was not a String returned
by
-		/// longToString()).
-		/// </summary>
-		public static long StringToLong(System.String str)
-		{
-			if (str == null)
-			{
-				throw new System.NullReferenceException("string cannot be null");
-			}
-			if (str.Length != STR_SIZE)
-			{
-				throw new System.FormatException("string is the wrong size");
-			}
-			
-			if (str.Equals(MIN_STRING_VALUE))
-			{
-				return System.Int64.MinValue;
-			}
-			
-			char prefix = str[0];
-			long l = System.Convert.ToInt64(str.Substring(1), RADIX);
-			
-			if (prefix == POSITIVE_PREFIX)
-			{
-				// nop
-			}
-			else if (prefix == NEGATIVE_PREFIX)
-			{
-				l = l - System.Int64.MaxValue - 1;
-			}
-			else
-			{
-				throw new System.FormatException("string does not begin with the correct prefix");
-			}
-			
-			return l;
-		}
-	}
+            {
+                // special case, because long is not symetric around zero
+                return MIN_STRING_VALUE;
+            }
+			
+            System.Text.StringBuilder buf = new System.Text.StringBuilder(STR_SIZE);
+			
+            if (l < 0)
+            {
+                buf.Append(NEGATIVE_PREFIX);
+                l = System.Int64.MaxValue + l + 1;
+            }
+            else
+            {
+                buf.Append(POSITIVE_PREFIX);
+            }
+#if LUCENE_JAVA_COMPATIBLE
+			System.String num = ToString(l);
+#else
+            System.String num = System.Convert.ToString(l, RADIX);
+#endif
+			
+            int padLen = STR_SIZE - num.Length - buf.Length;
+            while (padLen-- > 0)
+            {
+                buf.Append('0');
+            }
+            buf.Append(num);
+			
+            return buf.ToString();
+        }
+		
+        /// <summary> Converts a String that was returned by {@link #longToString}
back to a
+        /// long.
+        /// 
+        /// </summary>
+        /// <throws>  IllegalArgumentException </throws>
+        /// <summary>             if the input is null
+        /// </summary>
+        /// <throws>  NumberFormatException </throws>
+        /// <summary>             if the input does not parse (it was not a String
returned by
+        /// longToString()).
+        /// </summary>
+        public static long StringToLong(System.String str)
+        {
+            if (str == null)
+            {
+                throw new System.NullReferenceException("string cannot be null");
+            }
+            if (str.Length != STR_SIZE)
+            {
+                throw new System.FormatException("string is the wrong size");
+            }
+			
+            if (str.Equals(MIN_STRING_VALUE))
+            {
+                return System.Int64.MinValue;
+            }
+			
+            char prefix = str[0];
+#if LUCENE_JAVA_COMPATIBLE
+			long l = ToLong(str.Substring(1));
+#else
+            long l = System.Convert.ToInt64(str.Substring(1), RADIX);
+#endif
+			
+            if (prefix == POSITIVE_PREFIX)
+            {
+                // nop
+            }
+            else if (prefix == NEGATIVE_PREFIX)
+            {
+                l = l - System.Int64.MaxValue - 1;
+            }
+            else
+            {
+                throw new System.FormatException("string does not begin with the correct
prefix");
+            }
+			
+            return l;
+        }
+
+#if LUCENE_JAVA_COMPATIBLE
+        #region BASE36 OPS 
+        static System.String digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+        static long[] powersOf36 = 
+            {
+                1L,
+                36L,
+                36L*36L,
+                36L*36L*36L,
+                36L*36L*36L*36L,
+                36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L
+            };
+
+        public static System.String ToString(long lval)
+        {
+            int maxStrLen = powersOf36.Length;
+            long curval = lval;
+
+            char[] tb = new char[maxStrLen];
+            int outpos = 0;
+            for (int i = 0; i < maxStrLen; i++)
+            {
+                long pval = powersOf36[maxStrLen - i - 1];
+                int pos = (int)(curval / pval);
+                tb[outpos++] = digits.Substring(pos, 1).ToCharArray()[0];
+                curval = curval % pval;
+            }
+            if (outpos == 0)
+                tb[outpos++] = '0';
+            return new System.String(tb, 0, outpos).TrimStart('0');
+        }
+
+        public static long ToLong(System.String t)
+        {
+            long ival = 0;
+            char[] tb = t.ToCharArray();
+            for (int i = 0; i < tb.Length; i++)
+            {
+                ival += powersOf36[i] * digits.IndexOf(tb[tb.Length - i - 1]);
+            }
+            return ival;
+        }
+        #endregion
+#endif
+    }
 }

Modified: incubator/lucene.net/trunk/C#/src/HISTORY.txt
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/HISTORY.txt?view=diff&rev=533920&r1=533919&r2=533920
==============================================================================
--- incubator/lucene.net/trunk/C#/src/HISTORY.txt (original)
+++ incubator/lucene.net/trunk/C#/src/HISTORY.txt Mon Apr 30 20:15:24 2007
@@ -2,6 +2,11 @@
 -------------------------
 
 
+30Apr07:
+	- Patch:  Apache Lucene.Net.2.0 build 005 "final"
+	- Fix: LUCENENET-37 "Exception while search in Lucene.Net and Index prepared by Lucene Java"
+
+
 11Mar07:
 	- Release:  Apache Lucene.Net.2.0 build 004 "final"
 	- Fix: LUCENENET-36 "Countries using "," as decimal separator gets an exception in QueryParser.cs
with a query like color~0.5"

Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/NumberTools.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Document/NumberTools.cs?view=diff&rev=533920&r1=533919&r2=533920
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/NumberTools.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Document/NumberTools.cs Mon Apr 30 20:15:24
2007
@@ -20,118 +20,186 @@
 namespace Lucene.Net.Documents
 {
 	
-	/// <summary> Provides support for converting longs to Strings, and back again. The
strings
-	/// are structured so that lexicographic sorting order is preserved.
-	/// 
-	/// <p>
-	/// That is, if l1 is less than l2 for any two longs l1 and l2, then
-	/// NumberTools.longToString(l1) is lexicographically less than
-	/// NumberTools.longToString(l2). (Similarly for "greater than" and "equals".)
-	/// 
-	/// <p>
-	/// This class handles <b>all</b> long values (unlike
-	/// {@link Lucene.Net.document.DateField}).
-	/// 
-	/// </summary>
-	/// <author>  Matt Quail (spud at madbean dot com)
-	/// </author>
-	public class NumberTools
-	{
-		
-		private const int RADIX = 16;
-		
-		private const char NEGATIVE_PREFIX = '-';
-		
-		// NB: NEGATIVE_PREFIX must be < POSITIVE_PREFIX
-		private const char POSITIVE_PREFIX = '0';
-		
-		//NB: this must be less than
-		/// <summary> Equivalent to longToString(Long.MIN_VALUE)</summary>
-		public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000000";
-		
-		/// <summary> Equivalent to longToString(Long.MAX_VALUE)</summary>
-		public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "7fffffffffffffff";
-		
-		/// <summary> The length of (all) strings returned by {@link #longToString}</summary>
-		public static readonly int STR_SIZE = MIN_STRING_VALUE.Length;
-		
-		/// <summary> Converts a long to a String suitable for indexing.</summary>
-		public static System.String LongToString(long l)
-		{
+    /// <summary> Provides support for converting longs to Strings, and back again.
The strings
+    /// are structured so that lexicographic sorting order is preserved.
+    /// 
+    /// <p>
+    /// That is, if l1 is less than l2 for any two longs l1 and l2, then
+    /// NumberTools.longToString(l1) is lexicographically less than
+    /// NumberTools.longToString(l2). (Similarly for "greater than" and "equals".)
+    /// 
+    /// <p>
+    /// This class handles <b>all</b> long values (unlike
+    /// {@link Lucene.Net.document.DateField}).
+    /// 
+    /// </summary>
+    /// <author>  Matt Quail (spud at madbean dot com)
+    /// </author>
+    public class NumberTools
+    {
+		
+        private const int RADIX = 16;
+		
+        private const char NEGATIVE_PREFIX = '-';
+		
+        // NB: NEGATIVE_PREFIX must be < POSITIVE_PREFIX
+        private const char POSITIVE_PREFIX = '0';
+		
+        //NB: this must be less than
+        /// <summary> Equivalent to longToString(Long.MIN_VALUE)</summary>
+#if LUCENE_JAVA_COMPATIBLE
+        public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000";
+#else
+        public static readonly System.String MIN_STRING_VALUE = NEGATIVE_PREFIX + "0000000000000000";
+#endif
+		
+        /// <summary> Equivalent to longToString(Long.MAX_VALUE)</summary>
+#if LUCENE_JAVA_COMPATIBLE
+		public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "1y2p0ij32e8e7";
+#else
+        public static readonly System.String MAX_STRING_VALUE = POSITIVE_PREFIX + "7fffffffffffffff";
+#endif
+		
+        /// <summary> The length of (all) strings returned by {@link #longToString}</summary>
+        public static readonly int STR_SIZE = MIN_STRING_VALUE.Length;
+		
+        /// <summary> Converts a long to a String suitable for indexing.</summary>
+        public static System.String LongToString(long l)
+        {
 
             if (l == System.Int64.MinValue)
-			{
-				// special case, because long is not symetric around zero
-				return MIN_STRING_VALUE;
-			}
-			
-			System.Text.StringBuilder buf = new System.Text.StringBuilder(STR_SIZE);
-			
-			if (l < 0)
-			{
-				buf.Append(NEGATIVE_PREFIX);
-				l = System.Int64.MaxValue + l + 1;
-			}
-			else
-			{
-				buf.Append(POSITIVE_PREFIX);
-			}
-			System.String num = System.Convert.ToString(l, RADIX);
-			
-			int padLen = STR_SIZE - num.Length - buf.Length;
-			while (padLen-- > 0)
-			{
-				buf.Append('0');
-			}
-			buf.Append(num);
-			
-			return buf.ToString();
-		}
-		
-		/// <summary> Converts a String that was returned by {@link #longToString} back to
a
-		/// long.
-		/// 
-		/// </summary>
-		/// <throws>  IllegalArgumentException </throws>
-		/// <summary>             if the input is null
-		/// </summary>
-		/// <throws>  NumberFormatException </throws>
-		/// <summary>             if the input does not parse (it was not a String returned
by
-		/// longToString()).
-		/// </summary>
-		public static long StringToLong(System.String str)
-		{
-			if (str == null)
-			{
-				throw new System.NullReferenceException("string cannot be null");
-			}
-			if (str.Length != STR_SIZE)
-			{
-				throw new System.FormatException("string is the wrong size");
-			}
-			
-			if (str.Equals(MIN_STRING_VALUE))
-			{
-				return System.Int64.MinValue;
-			}
-			
-			char prefix = str[0];
-			long l = System.Convert.ToInt64(str.Substring(1), RADIX);
-			
-			if (prefix == POSITIVE_PREFIX)
-			{
-				// nop
-			}
-			else if (prefix == NEGATIVE_PREFIX)
-			{
-				l = l - System.Int64.MaxValue - 1;
-			}
-			else
-			{
-				throw new System.FormatException("string does not begin with the correct prefix");
-			}
-			
-			return l;
-		}
-	}
+            {
+                // special case, because long is not symetric around zero
+                return MIN_STRING_VALUE;
+            }
+			
+            System.Text.StringBuilder buf = new System.Text.StringBuilder(STR_SIZE);
+			
+            if (l < 0)
+            {
+                buf.Append(NEGATIVE_PREFIX);
+                l = System.Int64.MaxValue + l + 1;
+            }
+            else
+            {
+                buf.Append(POSITIVE_PREFIX);
+            }
+#if LUCENE_JAVA_COMPATIBLE
+			System.String num = ToString(l);
+#else
+            System.String num = System.Convert.ToString(l, RADIX);
+#endif
+			
+            int padLen = STR_SIZE - num.Length - buf.Length;
+            while (padLen-- > 0)
+            {
+                buf.Append('0');
+            }
+            buf.Append(num);
+			
+            return buf.ToString();
+        }
+		
+        /// <summary> Converts a String that was returned by {@link #longToString}
back to a
+        /// long.
+        /// 
+        /// </summary>
+        /// <throws>  IllegalArgumentException </throws>
+        /// <summary>             if the input is null
+        /// </summary>
+        /// <throws>  NumberFormatException </throws>
+        /// <summary>             if the input does not parse (it was not a String
returned by
+        /// longToString()).
+        /// </summary>
+        public static long StringToLong(System.String str)
+        {
+            if (str == null)
+            {
+                throw new System.NullReferenceException("string cannot be null");
+            }
+            if (str.Length != STR_SIZE)
+            {
+                throw new System.FormatException("string is the wrong size");
+            }
+			
+            if (str.Equals(MIN_STRING_VALUE))
+            {
+                return System.Int64.MinValue;
+            }
+			
+            char prefix = str[0];
+#if LUCENE_JAVA_COMPATIBLE
+			long l = ToLong(str.Substring(1));
+#else
+            long l = System.Convert.ToInt64(str.Substring(1), RADIX);
+#endif
+			
+            if (prefix == POSITIVE_PREFIX)
+            {
+                // nop
+            }
+            else if (prefix == NEGATIVE_PREFIX)
+            {
+                l = l - System.Int64.MaxValue - 1;
+            }
+            else
+            {
+                throw new System.FormatException("string does not begin with the correct
prefix");
+            }
+			
+            return l;
+        }
+
+#if LUCENE_JAVA_COMPATIBLE
+        #region BASE36 OPS 
+        static System.String digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+        static long[] powersOf36 = 
+            {
+                1L,
+                36L,
+                36L*36L,
+                36L*36L*36L,
+                36L*36L*36L*36L,
+                36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L,
+                36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L*36L
+            };
+
+        public static System.String ToString(long lval)
+        {
+            int maxStrLen = powersOf36.Length;
+            long curval = lval;
+
+            char[] tb = new char[maxStrLen];
+            int outpos = 0;
+            for (int i = 0; i < maxStrLen; i++)
+            {
+                long pval = powersOf36[maxStrLen - i - 1];
+                int pos = (int)(curval / pval);
+                tb[outpos++] = digits.Substring(pos, 1).ToCharArray()[0];
+                curval = curval % pval;
+            }
+            if (outpos == 0)
+                tb[outpos++] = '0';
+            return new System.String(tb, 0, outpos).TrimStart('0');
+        }
+
+        public static long ToLong(System.String t)
+        {
+            long ival = 0;
+            char[] tb = t.ToCharArray();
+            for (int i = 0; i < tb.Length; i++)
+            {
+                ival += powersOf36[i] * digits.IndexOf(tb[tb.Length - i - 1]);
+            }
+            return ival;
+        }
+        #endregion
+#endif
+    }
 }



Mime
View raw message