lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [lucenenet] 02/04: Lucene.Net.Highlighter: Implemented IFormattable and added culture-aware ToString() overload to WeightedPhraseInfo and WeightedFragInfo
Date Sat, 24 Jul 2021 19:00:40 GMT
This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit d50da0e529536c93cc33402a833cdf32951b979f
Author: Shad Storhaug <shad@shadstorhaug.com>
AuthorDate: Sun Jul 11 21:48:43 2021 +0700

    Lucene.Net.Highlighter: Implemented IFormattable and added culture-aware ToString() overload
to WeightedPhraseInfo and WeightedFragInfo
---
 .../VectorHighlight/FieldFragList.cs               | 18 +++++++---
 .../VectorHighlight/FieldPhraseList.cs             | 13 +++++--
 .../VectorHighlight/FieldPhraseListTest.cs         | 41 +++++++++++-----------
 .../VectorHighlight/IndexTimeSynonymTest.cs        | 15 ++++----
 .../VectorHighlight/SimpleFragListBuilderTest.cs   | 41 +++++++++++-----------
 .../VectorHighlight/SingleFragListBuilderTest.cs   |  5 +--
 .../VectorHighlight/WeightedFragListBuilderTest.cs |  3 +-
 7 files changed, 79 insertions(+), 57 deletions(-)

diff --git a/src/Lucene.Net.Highlighter/VectorHighlight/FieldFragList.cs b/src/Lucene.Net.Highlighter/VectorHighlight/FieldFragList.cs
index 6dce798..3be0baa 100644
--- a/src/Lucene.Net.Highlighter/VectorHighlight/FieldFragList.cs
+++ b/src/Lucene.Net.Highlighter/VectorHighlight/FieldFragList.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using System.Text;
 using Float = J2N.Numerics.Single;
 using Toffs = Lucene.Net.Search.VectorHighlight.FieldPhraseList.WeightedPhraseInfo.Toffs;
@@ -57,7 +58,7 @@ namespace Lucene.Net.Search.VectorHighlight
         /// <summary>
         /// List of term offsets + weight for a frag info
         /// </summary>
-        public class WeightedFragInfo
+        public class WeightedFragInfo : IFormattable // LUCENENET specific - implemented
IFormattable for floating point representations
         {
             private readonly IList<SubInfo> subInfos; // LUCENENET: marked readonly
             private readonly float totalBoost; // LUCENENET: marked readonly
@@ -82,15 +83,24 @@ namespace Lucene.Net.Search.VectorHighlight
 
             public override string ToString()
             {
+                return ToString(null);
+            }
+
+            // LUCENENET specific: allow formatting the boost in the current culture.
+
+            public virtual string ToString(IFormatProvider provider)
+            {
                 StringBuilder sb = new StringBuilder();
                 sb.Append("subInfos=(");
                 foreach (SubInfo si in subInfos)
                     sb.Append(si.ToString());
-                // LUCENENET: intentionally using current culture here
-                sb.Append(")/").Append(Float.ToString(totalBoost)).Append('(').Append(startOffset).Append(',').Append(endOffset).Append(')');
+                // LUCENENET: allow formatting in the current culture
+                sb.Append(")/").Append(Float.ToString(totalBoost, provider)).Append('(').Append(startOffset).Append(',').Append(endOffset).Append(')');
                 return sb.ToString();
             }
 
+            string IFormattable.ToString(string format, IFormatProvider provider) => ToString(provider);
+
             /// <summary>
             /// Represents the list of term offsets for some text
             /// </summary>
diff --git a/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs b/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs
index 5ec2f99..bfb464f 100644
--- a/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs
+++ b/src/Lucene.Net.Highlighter/VectorHighlight/FieldPhraseList.cs
@@ -223,7 +223,7 @@ namespace Lucene.Net.Search.VectorHighlight
         /// <summary>
         /// Represents the list of term offsets and boost for some text
         /// </summary>
-        public class WeightedPhraseInfo : IComparable<WeightedPhraseInfo>
+        public class WeightedPhraseInfo : IComparable<WeightedPhraseInfo>, IFormattable
// LUCENENET specific - implemented IFormattable for floating point representations
         {
             private readonly List<Toffs> termsOffsets;   // usually termsOffsets.size()
== 1, // LUCENENET: marked readonly
                                                          // but if position-gap > 1 and
slop > 0 then size() could be greater than 1
@@ -378,9 +378,14 @@ namespace Lucene.Net.Search.VectorHighlight
 
             public override string ToString()
             {
+                return ToString(null);
+            }
+
+            public virtual string ToString(IFormatProvider provider)
+            {
                 StringBuilder sb = new StringBuilder();
-                // LUCENENET: intentionally using current culture here
-                sb.Append(GetText()).Append('(').Append(Float.ToString(boost)).Append(")(");
+                // LUCENENET: allow passing culture
+                sb.Append(GetText()).Append('(').Append(Float.ToString(boost, provider)).Append(")(");
                 foreach (Toffs to in termsOffsets)
                 {
                     sb.Append(to);
@@ -389,6 +394,8 @@ namespace Lucene.Net.Search.VectorHighlight
                 return sb.ToString();
             }
 
+            string IFormattable.ToString(string format, IFormatProvider provider) => ToString(provider);
+
             /// <summary>
             /// the seqnum
             /// </summary>
diff --git a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/FieldPhraseListTest.cs b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/FieldPhraseListTest.cs
index 477cd55..bc2e17a 100644
--- a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/FieldPhraseListTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/FieldPhraseListTest.cs
@@ -2,6 +2,7 @@
 using NUnit.Framework;
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using TermInfo = Lucene.Net.Search.VectorHighlight.FieldTermStack.TermInfo;
 using Toffs = Lucene.Net.Search.VectorHighlight.FieldPhraseList.WeightedPhraseInfo.Toffs;
 using WeightedPhraseInfo = Lucene.Net.Search.VectorHighlight.FieldPhraseList.WeightedPhraseInfo;
@@ -36,7 +37,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("a(1.0)((0,1))", fpl.PhraseList[0].toString());
+            assertEquals("a(1.0)((0,1))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             fq = new FieldQuery(tq("b"), true, true);
             stack = new FieldTermStack(reader, 0, F, fq);
@@ -53,8 +54,8 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(2, fpl.PhraseList.size());
-            assertEquals("a(1.0)((0,1))", fpl.PhraseList[0].toString());
-            assertEquals("a(1.0)((2,3))", fpl.PhraseList[1].toString());
+            assertEquals("a(1.0)((0,1))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("a(1.0)((2,3))", fpl.PhraseList[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -66,13 +67,13 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("ab(1.0)((0,3))", fpl.PhraseList[0].toString());
+            assertEquals("ab(1.0)((0,3))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             fq = new FieldQuery(tq("b"), true, true);
             stack = new FieldTermStack(reader, 0, F, fq);
             fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("b(1.0)((2,3))", fpl.PhraseList[0].toString());
+            assertEquals("b(1.0)((2,3))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -87,7 +88,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("baac(1.0)((2,5))", fpl.PhraseList[0].toString());
+            assertEquals("baac(1.0)((2,5))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -102,8 +103,8 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(2, fpl.PhraseList.size());
-            assertEquals("ab(1.0)((0,2))", fpl.PhraseList[0].toString());
-            assertEquals("ab(1.0)((2,4))", fpl.PhraseList[1].toString());
+            assertEquals("ab(1.0)((0,2))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("ab(1.0)((2,4))", fpl.PhraseList[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -116,15 +117,15 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("ab(1.0)((4,7))", fpl.PhraseList[0].toString());
+            assertEquals("ab(1.0)((4,7))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             // phraseHighlight = false
             fq = new FieldQuery(pqF("a", "b"), false, true);
             stack = new FieldTermStack(reader, 0, F, fq);
             fpl = new FieldPhraseList(stack, fq);
             assertEquals(2, fpl.PhraseList.size());
-            assertEquals("a(1.0)((2,3))", fpl.PhraseList[0].toString());
-            assertEquals("ab(1.0)((4,7))", fpl.PhraseList[1].toString());
+            assertEquals("a(1.0)((2,3))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("ab(1.0)((4,7))", fpl.PhraseList[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -136,7 +137,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("ac(2.0)((4,5)(8,9))", fpl.PhraseList[0].toString());
+            assertEquals("ac(2.0)((4,5)(8,9))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(4, fpl.PhraseList[0].StartOffset);
             assertEquals(9, fpl.PhraseList[0].EndOffset);
         }
@@ -153,7 +154,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("abc(1.0)((2,7))", fpl.PhraseList[0].toString());
+            assertEquals("abc(1.0)((2,7))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -165,7 +166,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("abc(1.0)((6,11))", fpl.PhraseList[0].toString());
+            assertEquals("abc(1.0)((6,11))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -180,8 +181,8 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(2, fpl.PhraseList.size());
-            assertEquals("ab(1.0)((2,5))", fpl.PhraseList[0].toString());
-            assertEquals("abc(1.0)((10,15))", fpl.PhraseList[1].toString());
+            assertEquals("ab(1.0)((2,5))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("abc(1.0)((10,15))", fpl.PhraseList[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -193,7 +194,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("d(1.0)((9,10))", fpl.PhraseList[0].toString());
+            assertEquals("d(1.0)((9,10))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -205,8 +206,8 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(2, fpl.PhraseList.size());
-            assertEquals("searchengines(1.0)((102,116))", fpl.PhraseList[0].toString());
-            assertEquals("searchengines(1.0)((157,171))", fpl.PhraseList[1].toString());
+            assertEquals("searchengines(1.0)((102,116))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("searchengines(1.0)((157,171))", fpl.PhraseList[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -218,7 +219,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("sppeeeed(1.0)((88,93))", fpl.PhraseList[0].toString());
+            assertEquals("sppeeeed(1.0)((88,93))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         /* This test shows a big speedup from limiting the number of analyzed phrases in

diff --git a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/IndexTimeSynonymTest.cs b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/IndexTimeSynonymTest.cs
index 5cc625b..d58ae36 100644
--- a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/IndexTimeSynonymTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/IndexTimeSynonymTest.cs
@@ -2,6 +2,7 @@
 using Lucene.Net.Analysis.TokenAttributes;
 using NUnit.Framework;
 using System;
+using System.Globalization;
 using System.IO;
 using TermInfo = Lucene.Net.Search.VectorHighlight.FieldTermStack.TermInfo;
 
@@ -167,7 +168,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("personalcomputer(1.0)((3,5))", fpl.PhraseList[0].toString());
+            assertEquals("personalcomputer(1.0)((3,5))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(5, fpl.PhraseList[0].EndOffset);
         }
@@ -181,7 +182,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("computer(1.0)((3,5))", fpl.PhraseList[0].toString());
+            assertEquals("computer(1.0)((3,5))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(5, fpl.PhraseList[0].EndOffset);
         }
@@ -198,7 +199,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertTrue(fpl.PhraseList[0].toString().IndexOf("(1.0)((3,5))", StringComparison.Ordinal)
> 0);
+            assertTrue(fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture).IndexOf("(1.0)((3,5))",
StringComparison.Ordinal) > 0); // LUCENENET specific: use invariant culture, since we
are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(5, fpl.PhraseList[0].EndOffset);
         }
@@ -212,7 +213,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("pc(1.0)((3,20))", fpl.PhraseList[0].toString());
+            assertEquals("pc(1.0)((3,20))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(20, fpl.PhraseList[0].EndOffset);
         }
@@ -226,7 +227,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("personalcomputer(1.0)((3,20))", fpl.PhraseList[0].toString());
+            assertEquals("personalcomputer(1.0)((3,20))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(20, fpl.PhraseList[0].EndOffset);
         }
@@ -240,7 +241,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertEquals("computer(1.0)((3,20))", fpl.PhraseList[0].toString());
+            assertEquals("computer(1.0)((3,20))", fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(20, fpl.PhraseList[0].EndOffset);
         }
@@ -257,7 +258,7 @@ namespace Lucene.Net.Search.VectorHighlight
             FieldTermStack stack = new FieldTermStack(reader, 0, F, fq);
             FieldPhraseList fpl = new FieldPhraseList(stack, fq);
             assertEquals(1, fpl.PhraseList.size());
-            assertTrue(fpl.PhraseList[0].toString().IndexOf("(1.0)((3,20))", StringComparison.Ordinal)
> 0);
+            assertTrue(fpl.PhraseList[0].ToString(CultureInfo.InvariantCulture).IndexOf("(1.0)((3,20))",
StringComparison.Ordinal) > 0); // LUCENENET specific: use invariant culture, since we
are culture-aware
             assertEquals(3, fpl.PhraseList[0].StartOffset);
             assertEquals(20, fpl.PhraseList[0].EndOffset);
         }
diff --git a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SimpleFragListBuilderTest.cs
b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SimpleFragListBuilderTest.cs
index 787aa8e..186184d 100644
--- a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SimpleFragListBuilderTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SimpleFragListBuilderTest.cs
@@ -1,6 +1,7 @@
 using Lucene.Net.Index;
 using NUnit.Framework;
 using System;
+using System.Globalization;
 using Console = Lucene.Net.Util.SystemConsole;
 
 namespace Lucene.Net.Search.VectorHighlight
@@ -52,7 +53,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "abcdefghijklmnopqrs")),
"abcdefghijklmnopqrs"), sflb.minFragCharSize);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(abcdefghijklmnopqrs((0,19)))/1.0(0,19)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(abcdefghijklmnopqrs((0,19)))/1.0(0,19)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -66,8 +67,8 @@ namespace Lucene.Net.Search.VectorHighlight
 
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(phraseQuery, "abcdefgh   jklmnopqrs"),
sflb.minFragCharSize);
             assertEquals(1, ffl.FragInfos.size());
-            if (Verbose) Console.WriteLine(ffl.FragInfos[0].toString());
-            assertEquals("subInfos=(abcdefghjklmnopqrs((0,21)))/1.0(0,21)", ffl.FragInfos[0].toString());
+            if (Verbose) Console.WriteLine(ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("subInfos=(abcdefghjklmnopqrs((0,21)))/1.0(0,21)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -76,7 +77,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")),
"a"), 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1)))/1.0(0,100)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1)))/1.0(0,100)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -85,15 +86,15 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")),
"a a"), 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1))a((2,3)))/2.0(0,100)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1))a((2,3)))/2.0(0,100)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")), "a b b b
b b b b b a"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1))a((18,19)))/2.0(0,20)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1))a((18,19)))/2.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")), "b b b b
a b b b b a"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((8,9))a((18,19)))/2.0(4,24)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((8,9))a((18,19)))/2.0(4,24)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -102,18 +103,18 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")),
"a b b b b b b b b b b b b b a"), 20);
             assertEquals(2, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].toString());
-            assertEquals("subInfos=(a((28,29)))/1.0(20,40)", ffl.FragInfos[1].toString());
+            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("subInfos=(a((28,29)))/1.0(20,40)", ffl.FragInfos[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")), "a b b b
b b b b b b b b b a"), 20);
             assertEquals(2, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].toString());
-            assertEquals("subInfos=(a((26,27)))/1.0(20,40)", ffl.FragInfos[1].toString());
+            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("subInfos=(a((26,27)))/1.0(20,40)", ffl.FragInfos[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")), "a b b b
b b b b b b a"), 20);
             assertEquals(2, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].toString());
-            assertEquals("subInfos=(a((20,21)))/1.0(20,40)", ffl.FragInfos[1].toString());
+            assertEquals("subInfos=(a((0,1)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
+            assertEquals("subInfos=(a((20,21)))/1.0(20,40)", ffl.FragInfos[1].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -130,11 +131,11 @@ namespace Lucene.Net.Search.VectorHighlight
 
             ffl = sflb.CreateFieldFragList(fpl(booleanQuery, "d b c"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(b((2,3)))/1.0(0,20)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(b((2,3)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             ffl = sflb.CreateFieldFragList(fpl(booleanQuery, "a b c"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1))b((2,3)))/2.0(0,20)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1))b((2,3)))/2.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -154,7 +155,7 @@ namespace Lucene.Net.Search.VectorHighlight
 
             ffl = sflb.CreateFieldFragList(fpl(phraseQuery, "a b c"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(ab((0,3)))/1.0(0,20)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(ab((0,3)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -169,7 +170,7 @@ namespace Lucene.Net.Search.VectorHighlight
 
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(phraseQuery, "a c b"), 20);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(ab((0,1)(4,5)))/1.0(0,20)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(ab((0,1)(4,5)))/1.0(0,20)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         private FieldPhraseList fpl(Query query, String indexValue)
@@ -191,7 +192,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(d((9,10)))/1.0(0,100)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(d((9,10)))/1.0(0,100)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -205,7 +206,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(searchengines((102,116))searchengines((157,171)))/2.0(87,187)",
ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(searchengines((102,116))searchengines((157,171)))/2.0(87,187)",
ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture)); // LUCENENET specific: use invariant
culture, since we are culture-aware
         }
 
         [Test]
@@ -219,7 +220,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SimpleFragListBuilder sflb = new SimpleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl, 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(sppeeeed((88,93)))/1.0(41,141)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(sppeeeed((88,93)))/1.0(41,141)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
     }
 }
diff --git a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SingleFragListBuilderTest.cs
b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SingleFragListBuilderTest.cs
index f487ab6..9f46041 100644
--- a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SingleFragListBuilderTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/SingleFragListBuilderTest.cs
@@ -1,6 +1,7 @@
 using Lucene.Net.Index;
 using NUnit.Framework;
 using System;
+using System.Globalization;
 
 namespace Lucene.Net.Search.VectorHighlight
 {
@@ -37,7 +38,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SingleFragListBuilder sflb = new SingleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")),
"a b c d"), 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1)))/1.0(0,2147483647)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1)))/1.0(0,2147483647)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         [Test]
@@ -46,7 +47,7 @@ namespace Lucene.Net.Search.VectorHighlight
             SingleFragListBuilder sflb = new SingleFragListBuilder();
             FieldFragList ffl = sflb.CreateFieldFragList(fpl(new TermQuery(new Term(F, "a")),
"a b c d", "a b c d e f g h i", "j k l m n o p q r s t u v w x y z a b c", "d e f g"), 100);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals("subInfos=(a((0,1))a((8,9))a((60,61)))/3.0(0,2147483647)", ffl.FragInfos[0].toString());
+            assertEquals("subInfos=(a((0,1))a((8,9))a((60,61)))/3.0(0,2147483647)", ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
         }
 
         private FieldPhraseList fpl(Query query, params String[] indexValues)
diff --git a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/WeightedFragListBuilderTest.cs
b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/WeightedFragListBuilderTest.cs
index a666ef1..6787020 100644
--- a/src/Lucene.Net.Tests.Highlighter/VectorHighlight/WeightedFragListBuilderTest.cs
+++ b/src/Lucene.Net.Tests.Highlighter/VectorHighlight/WeightedFragListBuilderTest.cs
@@ -1,5 +1,6 @@
 using NUnit.Framework;
 using System;
+using System.Globalization;
 using SubInfo = Lucene.Net.Search.VectorHighlight.FieldFragList.WeightedFragInfo.SubInfo;
 using WeightedFragInfo = Lucene.Net.Search.VectorHighlight.FieldFragList.WeightedFragInfo;
 
@@ -55,7 +56,7 @@ namespace Lucene.Net.Search.VectorHighlight
             WeightedFragListBuilder wflb = new WeightedFragListBuilder();
             FieldFragList ffl = wflb.CreateFieldFragList(fpl, fragCharSize);
             assertEquals(1, ffl.FragInfos.size());
-            assertEquals(expectedFragInfo, ffl.FragInfos[0].toString());
+            assertEquals(expectedFragInfo, ffl.FragInfos[0].ToString(CultureInfo.InvariantCulture));
// LUCENENET specific: use invariant culture, since we are culture-aware
 
             float totalSubInfoBoost = 0;
             foreach (WeightedFragInfo info in ffl.FragInfos)

Mime
View raw message