lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [lucenenet] NightOwl888 commented on a change in pull request #385: Adding overloads to Document for GetValues and Get
Date Thu, 05 Nov 2020 16:47:16 GMT

NightOwl888 commented on a change in pull request #385:
URL: https://github.com/apache/lucenenet/pull/385#discussion_r517450130



##########
File path: src/Lucene.Net.Misc/Document/LazyDocument.cs
##########
@@ -356,6 +356,11 @@ public virtual TokenStream GetTokenStream(Analyzer analyzer)
             {
                 return GetRealValue().GetTokenStream(analyzer);
             }
+
+            public virtual string ToString(IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue()) != null)
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(format)) != null)
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, IFormatProvider provider)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format, IFormatProvider provider)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format, provider);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(format, provider)) != null)
   ```

##########
File path: src/Lucene.Net.Tests/Index/TestIndexWriterExceptions.cs
##########
@@ -2043,6 +2043,11 @@ public TokenStream GetTokenStream(Analyzer analyzer)
             {
                 return null;
             }
+
+            public virtual string ToString(IFormatProvider provider)

Review comment:
       Please see my comment about the leaky abstraction - ultimately this method can be removed after removing `IIndexWriter.ToString(IFormatProvider)`.

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name = "provider" > An object that supplies culture-specific formatting information.This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, IFormatProvider provider)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format, IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name = "provider" > An object that supplies culture-specific formatting information.This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, IFormatProvider provider)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format, IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Field.cs
##########
@@ -835,6 +835,26 @@ public override string ToString()
             return result.ToString();
         }
 
+        /// <summary>
+        /// Prints a <see cref="Field"/> for human consumption.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public virtual string ToString(IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -288,5 +451,26 @@ public override string ToString()
             buffer.Append(">");
             return buffer.ToString();
         }
+
+        /// <summary>
+        /// Prints the fields of a document for human consumption. 
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string ToString(IFormatProvider provider)

Review comment:
       Please add a comment to indicate we have diverged from Java
   
   ```
   // LUCENENET specific - method added for better .NET compatibility
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name = "provider" > An object that supplies culture-specific formatting information.This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, IFormatProvider provider)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(provider)) != null)
   ```

##########
File path: src/Lucene.Net/Document/Field.cs
##########
@@ -835,6 +835,26 @@ public override string ToString()
             return result.ToString();
         }
 
+        /// <summary>
+        /// Prints a <see cref="Field"/> for human consumption.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public virtual string ToString(IFormatProvider provider)
+        {
+            StringBuilder result = new StringBuilder();
+
+            if(FieldsData != null)
+            {
+                result.AppendFormat(provider, "{0}<{1}:{3}>", m_type.ToString(), m_name.ToString(), FieldsData);

Review comment:
       Since the `Field.Number` class doesn't implement `IFormattable`, this call will not pass the provider on to `FieldsData` when it is a numeric type.
   
   [StringBuilder Source Code](https://referencesource.microsoft.com/#mscorlib/system/text/stringbuilder.cs,1449).
   
   So, this can be fixed in one of two ways:
   
   1. Implement `IFormattable` on `Field.Number`
   2. Check `if (FieldsData is Number number)` and then call the appropriate `ToString()` overload here
   
   Both fixes are acceptable, but either way we should implement `IFormattable` on `Field.Number` for compatibility.

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue()) != null)
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -235,9 +235,101 @@ public string[] GetValues(string name)
             var result = new List<string>();
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    result.Add(field.GetStringValue());
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name = "provider" > An object that supplies culture-specific formatting information.This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, IFormatProvider provider)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    result.Add(fieldStringValue);
+                }
+            }
+
+            if (result.Count == 0)
+            {
+                return NO_STRINGS;
+            }
+
+            return result.ToArray();
+        }
+
+        /// <summary>
+        /// Returns an array of values of the field specified as the method parameter.
+        /// This method returns an empty array when there are no
+        /// matching fields. It never returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instances back, use <see cref="GetFields(string)"/>. </summary>
+        /// <param name="name"> the name of the field </param>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        /// <returns> a <see cref="T:string[]"/> of field values </returns>
+        public string[] GetValues(string name, string format, IFormatProvider provider)
+        {
+            var result = new List<string>();
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format, provider);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(format, provider)) != null)
   ```

##########
File path: src/Lucene.Net/Document/Field.cs
##########
@@ -835,6 +835,26 @@ public override string ToString()
             return result.ToString();
         }
 
+        /// <summary>
+        /// Prints a <see cref="Field"/> for human consumption.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public virtual string ToString(IFormatProvider provider)
+        {
+            StringBuilder result = new StringBuilder();
+
+            if(FieldsData != null)
+            {
+                result.AppendFormat(provider, "{0}<{1}:{3}>", m_type.ToString(), m_name.ToString(), FieldsData);

Review comment:
       Note that the index is incorrect for the 3rd format argument, it should be `2`, not `3`.

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(format)) != null)
   ```

##########
File path: src/Lucene.Net/Document/Document.cs
##########
@@ -262,9 +354,80 @@ public string Get(string name)
         {
             foreach (IIndexableField field in fields)
             {
-                if (field.Name.Equals(name, StringComparison.Ordinal) && field.GetStringValue() != null)
+                string fieldStringValue = field.GetStringValue();
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
                 {
-                    return field.GetStringValue();
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="format">A standard or custom numeric format string. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, string format)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(format);
+                if (field.Name.Equals(name, StringComparison.Ordinal) && fieldStringValue != null)
+                {
+                    return fieldStringValue;
+                }
+            }
+            return null;
+        }
+
+        /// <summary>
+        /// Returns the string value of the field with the given name if any exist in
+        /// this document, or <c>null</c>.  If multiple fields exist with this name, this
+        /// method returns the first value added. If only binary fields with this name
+        /// exist, returns <c>null</c>.
+        /// For <see cref="Int32Field"/>, <see cref="Int64Field"/>, 
+        /// <see cref="SingleField"/> and <seealso cref="DoubleField"/> it returns the string value of the number. If you want
+        /// the actual numeric field instance back, use <see cref="GetField(string)"/>.
+        /// </summary>
+        /// <param name="provider">An object that supplies culture-specific formatting information. This parameter has no effect if this field is non-numeric.</param>
+        public string Get(string name, IFormatProvider provider)
+        {
+            foreach (IIndexableField field in fields)
+            {
+                string fieldStringValue = field.GetStringValue(provider);

Review comment:
       Performance can be improved by using the following syntax:
   
   ```c#
   string fieldStringValue;
   if (field.Name.Equals(name, StringComparison.Ordinal) && (fieldStringValue = field.GetStringValue(provider)) != null)
   ```

##########
File path: src/Lucene.Net.Misc/Document/LazyDocument.cs
##########
@@ -356,6 +356,11 @@ public virtual TokenStream GetTokenStream(Analyzer analyzer)
             {
                 return GetRealValue().GetTokenStream(analyzer);
             }
+
+            public virtual string ToString(IFormatProvider provider)

Review comment:
       Please see my comment about supporting the other `ToString()` overloads here.

##########
File path: src/Lucene.Net/Index/IndexableField.cs
##########
@@ -201,5 +201,11 @@ public interface IIndexableField
         ///         a non-null value if the field is to be indexed </returns>
         /// <exception cref="IOException"> Can be thrown while creating the <see cref="TokenStream"/> </exception>
         TokenStream GetTokenStream(Analyzer analyzer);
+
+        /// <summary>

Review comment:
       Please see my comment about the leaky abstraction - ultimately this method can be removed by supporting `IFormattable` instead.

##########
File path: src/Lucene.Net.Tests/Index/TestIndexableField.cs
##########
@@ -225,6 +225,11 @@ public TokenStream GetTokenStream(Analyzer analyzer)
             {
                 return GetReaderValue() != null ? analyzer.GetTokenStream(Name, GetReaderValue()) : analyzer.GetTokenStream(Name, new StringReader(GetStringValue()));
             }
+
+            public virtual string ToString(IFormatProvider provider)

Review comment:
       Please see my comment about the leaky abstraction - ultimately this method can be removed after removing `IIndexWriter.ToString(IFormatProvider)`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message