You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/08/13 16:33:35 UTC

[3/5] lucenenet git commit: API: Lucene.Net.Documents.Field: Added similar Number value types as in Java so the numeric types can be stored as object without boxing/unboxing. Also added overloads for numeric GetXXXValue() fields to IIndexableField so the

API: Lucene.Net.Documents.Field: Added similar Number value types as in Java so the numeric types can be stored as object without boxing/unboxing. Also added overloads for numeric GetXXXValue() fields to IIndexableField so these values can be retrieved without boxing/unboxing.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/beb4894f
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/beb4894f
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/beb4894f

Branch: refs/heads/master
Commit: beb4894f85bab7750b98c36dbe33e195011617f2
Parents: 361ceb6
Author: Shad Storhaug <sh...@shadstorhaug.com>
Authored: Sun Aug 13 00:51:01 2017 +0700
Committer: Shad Storhaug <sh...@shadstorhaug.com>
Committed: Sun Aug 13 00:51:59 2017 +0700

----------------------------------------------------------------------
 .../Taxonomy/FloatAssociationFacetField.cs      |   4 +-
 src/Lucene.Net.Misc/Document/LazyDocument.cs    |  36 ++
 .../Index/TestIndexWriterExceptions.cs          |  36 ++
 .../Index/TestIndexableField.cs                 |  36 ++
 src/Lucene.Net/Document/DoubleField.cs          |   4 +-
 src/Lucene.Net/Document/Field.cs                | 198 +++++++--
 src/Lucene.Net/Document/FloatField.cs           |   4 +-
 src/Lucene.Net/Document/IntField.cs             |   4 +-
 src/Lucene.Net/Document/LongField.cs            |   4 +-
 .../Document/NumericDocValuesField.cs           |   2 +-
 src/Lucene.Net/Document/StoredField.cs          |   8 +-
 src/Lucene.Net/Index/IndexableField.cs          |  48 ++-
 src/Lucene.Net/Lucene.Net.csproj                |   1 +
 .../Support/Document/DocumentExtensions.cs      |  17 +
 src/Lucene.Net/Support/Document/Field.cs        | 412 +++++++++++++++++++
 15 files changed, 773 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs
index 8595a0f..eb54233 100644
--- a/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs
+++ b/src/Lucene.Net.Facet/Taxonomy/FloatAssociationFacetField.cs
@@ -50,7 +50,7 @@ namespace Lucene.Net.Facet.Taxonomy
         /// </summary>
         public static BytesRef SingleToBytesRef(float v)
         {
-            return Int32AssociationFacetField.Int32ToBytesRef(Number.SingleToInt32Bits(v));
+            return Int32AssociationFacetField.Int32ToBytesRef(Support.Number.SingleToInt32Bits(v));
         }
 
         /// <summary>
@@ -60,7 +60,7 @@ namespace Lucene.Net.Facet.Taxonomy
         /// </summary>
         public static float BytesRefToSingle(BytesRef b)
         {
-            return Number.Int32BitsToSingle(Int32AssociationFacetField.BytesRefToInt32(b));
+            return Support.Number.Int32BitsToSingle(Int32AssociationFacetField.BytesRefToInt32(b));
         }
 
         public override string ToString()

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net.Misc/Document/LazyDocument.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Misc/Document/LazyDocument.cs b/src/Lucene.Net.Misc/Document/LazyDocument.cs
index 7bab218..33b8b4a 100644
--- a/src/Lucene.Net.Misc/Document/LazyDocument.cs
+++ b/src/Lucene.Net.Misc/Document/LazyDocument.cs
@@ -204,6 +204,42 @@ namespace Lucene.Net.Documents
                 return GetRealValue().GetNumericValue();
             }
 
+            // LUCENENET specific - created overload for Byte, since we have no Number class in .NET
+            public virtual byte? GetByteValue()
+            {
+                return GetRealValue().GetByteValue();
+            }
+
+            // LUCENENET specific - created overload for Short, since we have no Number class in .NET
+            public virtual short? GetInt16Value()
+            {
+                return GetRealValue().GetInt16Value();
+            }
+
+            // LUCENENET specific - created overload for Int32, since we have no Number class in .NET
+            public virtual int? GetInt32Value()
+            {
+                return GetRealValue().GetInt32Value();
+            }
+
+            // LUCENENET specific - created overload for Int64, since we have no Number class in .NET
+            public virtual long? GetInt64Value()
+            {
+                return GetRealValue().GetInt64Value();
+            }
+
+            // LUCENENET specific - created overload for Single, since we have no Number class in .NET
+            public virtual float? GetSingleValue()
+            {
+                return GetRealValue().GetSingleValue();
+            }
+
+            // LUCENENET specific - created overload for Double, since we have no Number class in .NET
+            public virtual double? GetDoubleValue()
+            {
+                return GetRealValue().GetDoubleValue();
+            }
+
             public virtual IIndexableFieldType IndexableFieldType
             {
                 get { return GetRealValue().IndexableFieldType; }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
index feded19..4d557e1 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
@@ -2031,6 +2031,42 @@ namespace Lucene.Net.Index
                 return null;
             }
 
+            // LUCENENET specific - created overload for Byte, since we have no Number class in .NET
+            public virtual byte? GetByteValue()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Short, since we have no Number class in .NET
+            public virtual short? GetInt16Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Int32, since we have no Number class in .NET
+            public virtual int? GetInt32Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Int64, since we have no Number class in .NET
+            public virtual long? GetInt64Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Single, since we have no Number class in .NET
+            public virtual float? GetSingleValue()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Double, since we have no Number class in .NET
+            public virtual double? GetDoubleValue()
+            {
+                return null;
+            }
+
             public TokenStream GetTokenStream(Analyzer analyzer)
             {
                 return null;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net.Tests/Index/TestIndexableField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Index/TestIndexableField.cs b/src/Lucene.Net.Tests/Index/TestIndexableField.cs
index b41f9c2..2aac045 100644
--- a/src/Lucene.Net.Tests/Index/TestIndexableField.cs
+++ b/src/Lucene.Net.Tests/Index/TestIndexableField.cs
@@ -195,6 +195,42 @@ namespace Lucene.Net.Index
                 return null;
             }
 
+            // LUCENENET specific - created overload for Byte, since we have no Number class in .NET
+            public virtual byte? GetByteValue()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Short, since we have no Number class in .NET
+            public virtual short? GetInt16Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Int32, since we have no Number class in .NET
+            public virtual int? GetInt32Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Int64, since we have no Number class in .NET
+            public virtual long? GetInt64Value()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Single, since we have no Number class in .NET
+            public virtual float? GetSingleValue()
+            {
+                return null;
+            }
+
+            // LUCENENET specific - created overload for Double, since we have no Number class in .NET
+            public virtual double? GetDoubleValue()
+            {
+                return null;
+            }
+
             public IIndexableFieldType IndexableFieldType
             {
                 get { return fieldType; }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/DoubleField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/DoubleField.cs b/src/Lucene.Net/Document/DoubleField.cs
index f764782..16d089d 100644
--- a/src/Lucene.Net/Document/DoubleField.cs
+++ b/src/Lucene.Net/Document/DoubleField.cs
@@ -155,7 +155,7 @@ namespace Lucene.Net.Documents
         public DoubleField(string name, double value, Store stored)
             : base(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED)
         {
-            m_fieldsData = Convert.ToDouble(value);
+            m_fieldsData = new Double(value);
         }
 
         /// <summary>
@@ -174,7 +174,7 @@ namespace Lucene.Net.Documents
             {
                 throw new System.ArgumentException("type.NumericType must be NumericType.DOUBLE but got " + type.NumericType);
             }
-            m_fieldsData = Convert.ToDouble(value);
+            m_fieldsData = new Double(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/Field.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/Field.cs b/src/Lucene.Net/Document/Field.cs
index 9c0f6ce..793b047 100644
--- a/src/Lucene.Net/Document/Field.cs
+++ b/src/Lucene.Net/Document/Field.cs
@@ -49,7 +49,7 @@ namespace Lucene.Net.Documents
 #if FEATURE_SERIALIZABLE
     [Serializable]
 #endif
-    public class Field : IIndexableField
+    public partial class Field : IIndexableField
     {
         /// <summary>
         /// Field's type
@@ -290,7 +290,7 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual string GetStringValue() // LUCENENET specific: Added verb Get to make it more clear that this returns the value
         {
-            if (m_fieldsData is string || m_fieldsData is int || m_fieldsData is float || m_fieldsData is double || m_fieldsData is long)
+            if (m_fieldsData is string || m_fieldsData is Number)
             {
                 return m_fieldsData.ToString();
             }
@@ -301,6 +301,59 @@ namespace Lucene.Net.Documents
         }
 
         /// <summary>
+        /// The value of the field as a <see cref="string"/>, or <c>null</c>. If <c>null</c>, the <see cref="TextReader"/> value or
+        /// binary value is used. Exactly one of <see cref="GetStringValue()"/>, <see cref="GetReaderValue()"/>, and
+        /// <see cref="GetBinaryValue()"/> must be set.
+        /// </summary>
+        public virtual string GetStringValue(IFormatProvider provider) // LUCENENET specific: Added verb Get to make it more clear that this returns the value
+        {
+            if (m_fieldsData is string)
+            {
+                return m_fieldsData.ToString();
+            }
+            else if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).ToString(provider);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        public virtual string GetStringValue(string format) // LUCENENET specific: Added verb Get to make it more clear that this returns the value
+        {
+            if (m_fieldsData is string)
+            {
+                return m_fieldsData.ToString();
+            }
+            else if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).ToString(format);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        public virtual string GetStringValue(string format, IFormatProvider provider) // LUCENENET specific: Added verb Get to make it more clear that this returns the value
+        {
+            if (m_fieldsData is string)
+            {
+                return m_fieldsData.ToString();
+            }
+            else if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).ToString(format, provider);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
         /// The value of the field as a <see cref="TextReader"/>, or <c>null</c>. If <c>null</c>, the <see cref="string"/> value or
         /// binary value is used. Exactly one of <see cref="GetStringValue()"/>, <see cref="GetReaderValue()"/>, and
         /// <see cref="GetBinaryValue()"/> must be set.
@@ -392,11 +445,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetByteValue(byte value)
         {
-            if (!(m_fieldsData is byte?))
+            if (!(m_fieldsData is Byte))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Byte");
             }
-            m_fieldsData = Convert.ToByte(value);
+            m_fieldsData = new Byte(value);
         }
 
         /// <summary>
@@ -405,11 +458,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetInt16Value(short value) // LUCENENET specific: Renamed from SetShortValue to follow .NET conventions
         {
-            if (!(m_fieldsData is short?))
+            if (!(m_fieldsData is Int16))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Short");
             }
-            m_fieldsData = Convert.ToInt16(value);
+            m_fieldsData = new Int16(value);
         }
 
         /// <summary>
@@ -418,11 +471,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetInt32Value(int value) // LUCENENET specific: Renamed from SetIntValue to follow .NET conventions
         {
-            if (!(m_fieldsData is int?))
+            if (!(m_fieldsData is Int32))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Integer");
             }
-            m_fieldsData = Convert.ToInt32(value);
+            m_fieldsData = new Int32(value);
         }
 
         /// <summary>
@@ -431,11 +484,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetInt64Value(long value) // LUCENENET specific: Renamed from SetLongValue to follow .NET conventions
         {
-            if (!(m_fieldsData is long?))
+            if (!(m_fieldsData is Int64))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Long");
             }
-            m_fieldsData = Convert.ToInt64(value);
+            m_fieldsData = new Int64(value);
         }
 
         /// <summary>
@@ -444,11 +497,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetSingleValue(float value) // LUCENENET specific: Renamed from SetFloatValue to follow .NET conventions
         {
-            if (!(m_fieldsData is float?))
+            if (!(m_fieldsData is Single))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Float");
             }
-            m_fieldsData = Convert.ToSingle(value);
+            m_fieldsData = new Single(value);
         }
 
         /// <summary>
@@ -457,11 +510,11 @@ namespace Lucene.Net.Documents
         /// </summary>
         public virtual void SetDoubleValue(double value)
         {
-            if (!(m_fieldsData is double?))
+            if (!(m_fieldsData is Double))
             {
                 throw new System.ArgumentException("cannot change value type from " + m_fieldsData.GetType().Name + " to Double");
             }
-            m_fieldsData = Convert.ToDouble(value);
+            m_fieldsData = new Double(value);
         }
 
         // LUCENENET TODO: Add SetValue() overloads for each type?
@@ -527,14 +580,113 @@ namespace Lucene.Net.Documents
             // wrong StoredFieldsVisitor method will be called (in this case it was calling Int64Field() instead of StringField()).
             // This is an extremely difficult thing to track down and very confusing to end users.
 
-            if (m_fieldsData is int || m_fieldsData is float || m_fieldsData is double || m_fieldsData is long)
+            if (m_fieldsData is Int32)
+            {
+                return ((Int32)m_fieldsData).GetInt32Value();
+            }
+            else if (m_fieldsData is Int64)
+            {
+                return ((Int64)m_fieldsData).GetInt64Value();
+            }
+            else if (m_fieldsData is Single)
+            {
+                return ((Single)m_fieldsData).GetSingleValue();
+            }
+            else if (m_fieldsData is Double)
             {
-                return m_fieldsData;
+                return ((Double)m_fieldsData).GetDoubleValue();
+            }
+            else if (m_fieldsData is Int16)
+            {
+                return ((Int16)m_fieldsData).GetInt16Value();
+            }
+            else if (m_fieldsData is Byte)
+            {
+                return ((Byte)m_fieldsData).GetByteValue();
             }
 
             return null;
         }
 
+        // LUCENENET specific - created overload for Byte, since we have no Number class in .NET
+        public virtual byte? GetByteValue()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetByteValue();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        // LUCENENET specific - created overload for Short, since we have no Number class in .NET
+        public virtual short? GetInt16Value()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetInt16Value();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        // LUCENENET specific - created overload for Int32, since we have no Number class in .NET
+        public virtual int? GetInt32Value()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetInt32Value();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        // LUCENENET specific - created overload for Int64, since we have no Number class in .NET
+        public virtual long? GetInt64Value()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetInt64Value();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        // LUCENENET specific - created overload for Single, since we have no Number class in .NET
+        public virtual float? GetSingleValue()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetSingleValue();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        // LUCENENET specific - created overload for Double, since we have no Number class in .NET
+        public virtual double? GetDoubleValue()
+        {
+            if (m_fieldsData is Number)
+            {
+                return ((Number)m_fieldsData).GetDoubleValue();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+
         public virtual BytesRef GetBinaryValue() // LUCENENET specific: Added verb Get to make it more clear that this returns the value
         {
             if (m_fieldsData is BytesRef)
@@ -599,23 +751,23 @@ namespace Lucene.Net.Documents
                 }
                 var nts = (NumericTokenStream)internalTokenStream;
                 // initialize value in TokenStream
-                object val = m_fieldsData;
+                Number val = (Number)m_fieldsData;
                 switch (numericType)
                 {
                     case NumericType.INT32:
-                        nts.SetInt32Value(Convert.ToInt32(val));
+                        nts.SetInt32Value(val.GetInt32Value());
                         break;
 
                     case NumericType.INT64:
-                        nts.SetInt64Value(Convert.ToInt64(val));
+                        nts.SetInt64Value(val.GetInt64Value());
                         break;
 
                     case NumericType.SINGLE:
-                        nts.SetSingleValue(Convert.ToSingle(val));
+                        nts.SetSingleValue(val.GetSingleValue());
                         break;
 
                     case NumericType.DOUBLE:
-                        nts.SetDoubleValue(Convert.ToDouble(val));
+                        nts.SetDoubleValue(val.GetDoubleValue());
                         break;
 
                     default:
@@ -636,7 +788,7 @@ namespace Lucene.Net.Documents
                     // (attributes,...) if not needed (stored field loading)
                     internalTokenStream = new StringTokenStream();
                 }
-                ((StringTokenStream)internalTokenStream).SetValue(GetStringValue());
+                ((StringTokenStream)internalTokenStream).SetValue(GetStringValue()); // LUCENENET TODO: API Make overload that accepts format/provider
                 return internalTokenStream;
             }
 
@@ -650,7 +802,7 @@ namespace Lucene.Net.Documents
             }
             else if (GetStringValue() != null)
             {
-                TextReader sr = new StringReader(GetStringValue());
+                TextReader sr = new StringReader(GetStringValue()); // LUCENENET TODO: API Make overload that accepts format/provider
                 return analyzer.GetTokenStream(Name, sr);
             }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/FloatField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/FloatField.cs b/src/Lucene.Net/Document/FloatField.cs
index 51adec3..a602c99 100644
--- a/src/Lucene.Net/Document/FloatField.cs
+++ b/src/Lucene.Net/Document/FloatField.cs
@@ -159,7 +159,7 @@ namespace Lucene.Net.Documents
         public SingleField(string name, float value, Store stored)
             : base(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED)
         {
-            m_fieldsData = Convert.ToSingle(value);
+            m_fieldsData = new Single(value);
         }
 
         /// <summary>
@@ -178,7 +178,7 @@ namespace Lucene.Net.Documents
             {
                 throw new System.ArgumentException("type.NumericType must be NumericType.SINGLE but got " + type.NumericType);
             }
-            m_fieldsData = Convert.ToSingle(value);
+            m_fieldsData = new Single(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/IntField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/IntField.cs b/src/Lucene.Net/Document/IntField.cs
index 0bcaea7..2921900 100644
--- a/src/Lucene.Net/Document/IntField.cs
+++ b/src/Lucene.Net/Document/IntField.cs
@@ -158,7 +158,7 @@ namespace Lucene.Net.Documents
         public Int32Field(string name, int value, Store stored)
             : base(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED)
         {
-            m_fieldsData = Convert.ToInt32(value);
+            m_fieldsData = new Int32(value);
         }
 
         /// <summary>
@@ -179,7 +179,7 @@ namespace Lucene.Net.Documents
             {
                 throw new System.ArgumentException("type.NumericType must be NumericType.INT32 but got " + type.NumericType);
             }
-            m_fieldsData = Convert.ToInt32(value);
+            m_fieldsData = new Int32(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/LongField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/LongField.cs b/src/Lucene.Net/Document/LongField.cs
index 43108f1..9249486 100644
--- a/src/Lucene.Net/Document/LongField.cs
+++ b/src/Lucene.Net/Document/LongField.cs
@@ -169,7 +169,7 @@ namespace Lucene.Net.Documents
         public Int64Field(string name, long value, Store stored)
             : base(name, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED)
         {
-            m_fieldsData = Convert.ToInt64(value);
+            m_fieldsData = new Int64(value);
         }
 
         /// <summary>
@@ -189,7 +189,7 @@ namespace Lucene.Net.Documents
             {
                 throw new System.ArgumentException("type.NumericType must be NumericType.INT64 but got " + type.NumericType);
             }
-            m_fieldsData = Convert.ToInt64(value);
+            m_fieldsData = new Int64(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/NumericDocValuesField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/NumericDocValuesField.cs b/src/Lucene.Net/Document/NumericDocValuesField.cs
index 02d79ac..7b6eac2 100644
--- a/src/Lucene.Net/Document/NumericDocValuesField.cs
+++ b/src/Lucene.Net/Document/NumericDocValuesField.cs
@@ -55,7 +55,7 @@ namespace Lucene.Net.Documents
         public NumericDocValuesField(string name, long value)
             : base(name, TYPE)
         {
-            m_fieldsData = Convert.ToInt64(value);
+            m_fieldsData = new Int64(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Document/StoredField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Document/StoredField.cs b/src/Lucene.Net/Document/StoredField.cs
index e881336..dd3d8b2 100644
--- a/src/Lucene.Net/Document/StoredField.cs
+++ b/src/Lucene.Net/Document/StoredField.cs
@@ -101,7 +101,7 @@ namespace Lucene.Net.Documents
         public StoredField(string name, int value)
             : base(name, TYPE)
         {
-            m_fieldsData = value;
+            m_fieldsData = new Int32(value);
         }
 
         /// <summary>
@@ -112,7 +112,7 @@ namespace Lucene.Net.Documents
         public StoredField(string name, float value)
             : base(name, TYPE)
         {
-            m_fieldsData = value;
+            m_fieldsData = new Single(value);
         }
 
         /// <summary>
@@ -123,7 +123,7 @@ namespace Lucene.Net.Documents
         public StoredField(string name, long value)
             : base(name, TYPE)
         {
-            m_fieldsData = value;
+            m_fieldsData = new Int64(value);
         }
 
         /// <summary>
@@ -134,7 +134,7 @@ namespace Lucene.Net.Documents
         public StoredField(string name, double value)
             : base(name, TYPE)
         {
-            m_fieldsData = value;
+            m_fieldsData = new Double(value);
         }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Index/IndexableField.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Index/IndexableField.cs b/src/Lucene.Net/Index/IndexableField.cs
index 98b38d7..a04c5e6 100644
--- a/src/Lucene.Net/Index/IndexableField.cs
+++ b/src/Lucene.Net/Index/IndexableField.cs
@@ -73,11 +73,11 @@ namespace Lucene.Net.Index
         float Boost { get; }
 
         /// <summary>
-        /// Non-null if this field has a binary value </summary>
+        /// Non-null if this field has a binary value. </summary>
         BytesRef GetBinaryValue();
 
         /// <summary>
-        /// Non-null if this field has a string value </summary>
+        /// Non-null if this field has a string value. </summary>
         string GetStringValue();
 
         /// <summary>
@@ -85,10 +85,52 @@ namespace Lucene.Net.Index
         TextReader GetReaderValue();
 
         /// <summary>
-        /// Non-null if this field has a numeric value </summary>
+        /// Non-null if this field has a numeric value. </summary>
         object GetNumericValue(); // LUCENENET TODO: Can we eliminate object?
 
         /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        byte? GetByteValue();
+
+        /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        short? GetInt16Value();
+
+        /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        int? GetInt32Value();
+
+        /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        long? GetInt64Value();
+
+        /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        float? GetSingleValue();
+
+        /// <summary>
+        /// Non-null if this field has a numeric value.
+        /// <para/>
+        /// LUCENENET specific
+        /// </summary>
+        double? GetDoubleValue();
+
+        /// <summary>
         /// Creates the <see cref="TokenStream"/> used for indexing this field.  If appropriate,
         /// implementations should use the given <see cref="Analyzer"/> to create the <see cref="TokenStream"/>s.
         /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj
index aaa3c7b..8ca72e7 100644
--- a/src/Lucene.Net/Lucene.Net.csproj
+++ b/src/Lucene.Net/Lucene.Net.csproj
@@ -396,6 +396,7 @@
     <Compile Include="LucenePackage.cs" />
     <Compile Include="Support\AssemblyUtils.cs" />
     <Compile Include="Support\Document\DocumentExtensions.cs" />
+    <Compile Include="Support\Document\Field.cs" />
     <Compile Include="Support\IO\Compression\LZOCompressor.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Search\AutomatonQuery.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Support/Document/DocumentExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/Document/DocumentExtensions.cs b/src/Lucene.Net/Support/Document/DocumentExtensions.cs
index c04dc21..ba83483 100644
--- a/src/Lucene.Net/Support/Document/DocumentExtensions.cs
+++ b/src/Lucene.Net/Support/Document/DocumentExtensions.cs
@@ -3,6 +3,23 @@ using System.Linq;
 
 namespace Lucene.Net.Documents
 {
+    /*
+     * 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.
+     */
+
     /// <summary>
     /// Extension methods to the <see cref="Document"/> class.
     /// </summary>

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/beb4894f/src/Lucene.Net/Support/Document/Field.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/Document/Field.cs b/src/Lucene.Net/Support/Document/Field.cs
new file mode 100644
index 0000000..81da67e
--- /dev/null
+++ b/src/Lucene.Net/Support/Document/Field.cs
@@ -0,0 +1,412 @@
+using System;
+
+namespace Lucene.Net.Documents
+{
+    /*
+     * 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.
+     */
+
+    public partial class Field
+    {
+
+        // LUCENENET NOTE: The following classes were duplicated from Apache Harmony
+        // because nullable types in .NET are not reference types, therefore storing
+        // them in a field type object will require boxing/unboxing.
+
+#if FEATURE_SERIALIZABLE
+        [Serializable]
+#endif
+        protected abstract class Number
+        {
+            /// <summary>
+            /// Returns this object's value as a <see cref="byte"/>. Might involve rounding and/or
+            /// truncating the value, so it fits into a <see cref="byte"/>.
+            /// </summary>
+            /// <returns>the primitive <see cref="byte"/> value of this object.</returns>
+            public virtual byte GetByteValue()
+            {
+                return (byte)GetInt32Value();
+            }
+
+            /// <summary>
+            /// Returns this object's value as a <see cref="double"/>. Might involve rounding.
+            /// </summary>
+            /// <returns>the primitive <see cref="double"/> value of this object.</returns>
+            public abstract double GetDoubleValue();
+
+            /// <summary>
+            /// Returns this object's value as a <see cref="float"/>. Might involve rounding.
+            /// </summary>
+            /// <returns>the primitive <see cref="float"/> value of this object.</returns>
+            public abstract float GetSingleValue();
+
+            /// <summary>
+            /// Returns this object's value as an <see cref="int"/>. Might involve rounding and/or
+            /// truncating the value, so it fits into an <see cref="int"/>.
+            /// </summary>
+            /// <returns>the primitive <see cref="int"/> value of this object.</returns>
+            public abstract int GetInt32Value();
+
+            /// <summary>
+            /// Returns this object's value as a <see cref="long"/>. Might involve rounding and/or
+            /// truncating the value, so it fits into a <see cref="long"/>.
+            /// </summary>
+            /// <returns>the primitive <see cref="long"/> value of this object.</returns>
+            public abstract long GetInt64Value();
+
+            /// <summary>
+            /// Returns this object's value as a <see cref="short"/>. Might involve rounding and/or
+            /// truncating the value, so it fits into a <see cref="short"/>.
+            /// </summary>
+            /// <returns>the primitive <see cref="short"/> value of this object.</returns>
+            public virtual short GetInt16Value()
+            {
+                return (short)GetInt32Value();
+            }
+
+            public abstract override string ToString(); 
+
+            public abstract string ToString(string format);
+
+            public abstract string ToString(IFormatProvider provider);
+
+            public abstract string ToString(string format, IFormatProvider provider);
+        }
+
+        protected sealed class Byte : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly byte value;
+
+            public Byte(byte value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+
+        protected sealed class Int16 : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly short value;
+
+            public Int16(short value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return value;
+            }
+
+            public override short GetInt16Value()
+            {
+                return value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+
+        protected sealed class Int32 : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly int value;
+
+            public Int32(int value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+
+        protected sealed class Int64 : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly long value;
+
+            public Int64(long value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return (int)value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+
+        protected sealed class Double : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly double value;
+
+            public Double(double value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return (float)value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return (int)value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return (long)value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+
+        protected sealed class Single : Number
+        {
+            /// <summary>
+            /// The value which the receiver represents.
+            /// </summary>
+            private readonly float value;
+
+            public Single(float value)
+            {
+                this.value = value;
+            }
+
+            public override double GetDoubleValue()
+            {
+                return value;
+            }
+
+            public override float GetSingleValue()
+            {
+                return value;
+            }
+
+            public override int GetInt32Value()
+            {
+                return (int)value;
+            }
+
+            public override long GetInt64Value()
+            {
+                return (long)value;
+            }
+
+            public override string ToString()
+            {
+                return value.ToString();
+            }
+
+            public override string ToString(string format)
+            {
+                return value.ToString(format);
+            }
+
+            public override string ToString(IFormatProvider provider)
+            {
+                return value.ToString(provider);
+            }
+
+            public override string ToString(string format, IFormatProvider provider)
+            {
+                return value.ToString(format, provider);
+            }
+        }
+    }
+}