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 2025/10/06 10:51:51 UTC
(lucenenet) branch master updated: Fix query parser failure with Unicode minus sign, #846 (#1205)
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
The following commit(s) were added to refs/heads/master by this push:
new 2abc12029 Fix query parser failure with Unicode minus sign, #846 (#1205)
2abc12029 is described below
commit 2abc12029094478f55df6c10ed53193582d3e25c
Author: Paul Irwin <pa...@gmail.com>
AuthorDate: Mon Oct 6 04:51:45 2025 -0600
Fix query parser failure with Unicode minus sign, #846 (#1205)
* Fix query parser failure with Unicode minus sign, #846
* Lucene.Net.QueryParsers.Flexible.Standard.TestNumericQueryParser::TestInclusiveNumericRange_UnicodeMinus(): Use CultureContext to ensure the temporary culture assigned to the current thread is reverted at the end of the test.
---------
Co-authored-by: Shad Storhaug <sh...@shadstorhaug.com>
---
.build/dependencies.props | 2 +-
.../Flexible/Standard/TestNumericQueryParser.cs | 45 ++++++++++++++++++++--
2 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/.build/dependencies.props b/.build/dependencies.props
index dc36207cf..92707f01f 100644
--- a/.build/dependencies.props
+++ b/.build/dependencies.props
@@ -38,7 +38,7 @@
<IKVMPackageVersion>8.7.5</IKVMPackageVersion>
<IKVMMavenSdkPackageVersion>1.6.7</IKVMMavenSdkPackageVersion>
<!-- J2N will break binary compatibility in 3.0.0 to fix the APIs of collection types -->
- <J2NPackageVersion>[2.2.0-alpha-0021, 3.0.0)</J2NPackageVersion>
+ <J2NPackageVersion>[2.2.0-alpha-0026, 3.0.0)</J2NPackageVersion>
<LiquidTestReportsMarkdownPackageVersion>1.0.9</LiquidTestReportsMarkdownPackageVersion>
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.18</LuceneNetCodeAnalysisDevPackageVersion>
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.3.0</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>
diff --git a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
index ff43717f8..981a19ee0 100644
--- a/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
+++ b/src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs
@@ -1,5 +1,7 @@
+using J2N.Globalization;
using J2N.Numerics;
using Lucene.Net.Analysis;
+using Lucene.Net.Attributes;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Index.Extensions;
@@ -251,10 +253,10 @@ public override void SetUp()
)), LOCALE))
;
- randomNumberMap[NumericType.INT64.ToString()] = (J2N.Numerics.Int64)randomLong;
- randomNumberMap[NumericType.INT32.ToString()] = (J2N.Numerics.Int32)randomInt;
- randomNumberMap[NumericType.SINGLE.ToString()] = (J2N.Numerics.Single)randomFloat;
- randomNumberMap[NumericType.DOUBLE.ToString()] = (J2N.Numerics.Double)randomDouble;
+ randomNumberMap[nameof(NumericType.INT64)] = (J2N.Numerics.Int64)randomLong;
+ randomNumberMap[nameof(NumericType.INT32)] = (J2N.Numerics.Int32)randomInt;
+ randomNumberMap[nameof(NumericType.SINGLE)] = (J2N.Numerics.Single)randomFloat;
+ randomNumberMap[nameof(NumericType.DOUBLE)] = (J2N.Numerics.Double)randomDouble;
randomNumberMap[DATE_FIELD_NAME] = (J2N.Numerics.Int64)randomDate;
RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap);
@@ -510,6 +512,41 @@ public void TestSimpleNumericQuery()
AssertSimpleQuery(NumberType.NEGATIVE, 1);
}
+ /// <summary>
+ /// Tests the fix for Lucene.NET GitHub issue #846.
+ /// Numeric values were failing for cultures that use a Unicode minus sign
+ /// (U+2212) rather than a hyphen-minus (U+002D) in exponential notation.
+ /// This was due to a bug in J2N (#128) that has since been fixed.
+ /// </summary>
+ /// <remarks>
+ /// https://github.com/NightOwl888/J2N/issues/128
+ /// </remarks>
+ [Test]
+ [LuceneNetSpecific]
+ public void TestInclusiveNumericRange_UnicodeMinus()
+ {
+ // Use a culture that uses a Unicode minus sign rather than a hyphen-minus
+ // in exponential notation.
+ LOCALE = new CultureInfo("sv-FI");
+ using (var cultureContext = new CultureContext(LOCALE))
+ {
+ NUMBER_FORMAT = new MockNumberFormat(LOCALE);
+
+ var randomNumberMap = new JCG.Dictionary<string, Number>(RANDOM_NUMBER_MAP!)
+ {
+ [nameof(NumericType.DOUBLE)] = J2N.Numerics.Double.GetInstance(1.0E-20),
+ [nameof(NumericType.SINGLE)] = J2N.Numerics.Single.GetInstance(1.0E-20f)
+ };
+
+ RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap);
+
+ qp!.NumericConfigMap[nameof(NumericType.DOUBLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.DOUBLE);
+ qp.NumericConfigMap[nameof(NumericType.SINGLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.SINGLE);
+
+ AssertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, true, 1);
+ }
+ }
+
public void AssertRangeQuery(NumberType? lowerType, NumberType? upperType,
bool lowerInclusive, bool upperInclusive, int expectedDocCount)
{