Skip to content

Commit bfbbc3b

Browse files
committed
Fix query parser failure with Unicode minus sign, #846
1 parent 6ed2050 commit bfbbc3b

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

.build/dependencies.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<IKVMPackageVersion>8.7.5</IKVMPackageVersion>
3939
<IKVMMavenSdkPackageVersion>1.6.7</IKVMMavenSdkPackageVersion>
4040
<!-- J2N will break binary compatibility in 3.0.0 to fix the APIs of collection types -->
41-
<J2NPackageVersion>[2.2.0-alpha-0021, 3.0.0)</J2NPackageVersion>
41+
<J2NPackageVersion>[2.2.0-alpha-0026, 3.0.0)</J2NPackageVersion>
4242
<LiquidTestReportsMarkdownPackageVersion>1.0.9</LiquidTestReportsMarkdownPackageVersion>
4343
<LuceneNetCodeAnalysisDevPackageVersion>1.0.0-alpha.6</LuceneNetCodeAnalysisDevPackageVersion>
4444
<MicrosoftAspNetCoreHttpAbstractionsPackageVersion>2.3.0</MicrosoftAspNetCoreHttpAbstractionsPackageVersion>

src/Lucene.Net.Tests.QueryParser/Flexible/Standard/TestNumericQueryParser.cs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using J2N.Numerics;
22
using Lucene.Net.Analysis;
3+
using Lucene.Net.Attributes;
34
using Lucene.Net.Documents;
45
using Lucene.Net.Index;
56
using Lucene.Net.Index.Extensions;
@@ -251,10 +252,10 @@ public override void SetUp()
251252
)), LOCALE))
252253
;
253254

254-
randomNumberMap[NumericType.INT64.ToString()] = (J2N.Numerics.Int64)randomLong;
255-
randomNumberMap[NumericType.INT32.ToString()] = (J2N.Numerics.Int32)randomInt;
256-
randomNumberMap[NumericType.SINGLE.ToString()] = (J2N.Numerics.Single)randomFloat;
257-
randomNumberMap[NumericType.DOUBLE.ToString()] = (J2N.Numerics.Double)randomDouble;
255+
randomNumberMap[nameof(NumericType.INT64)] = (J2N.Numerics.Int64)randomLong;
256+
randomNumberMap[nameof(NumericType.INT32)] = (J2N.Numerics.Int32)randomInt;
257+
randomNumberMap[nameof(NumericType.SINGLE)] = (J2N.Numerics.Single)randomFloat;
258+
randomNumberMap[nameof(NumericType.DOUBLE)] = (J2N.Numerics.Double)randomDouble;
258259
randomNumberMap[DATE_FIELD_NAME] = (J2N.Numerics.Int64)randomDate;
259260

260261
RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap);
@@ -510,6 +511,40 @@ public void TestSimpleNumericQuery()
510511
AssertSimpleQuery(NumberType.NEGATIVE, 1);
511512
}
512513

514+
/// <summary>
515+
/// Tests the fix for Lucene.NET GitHub issue #846.
516+
/// Numeric values were failing for cultures that use a Unicode minus sign
517+
/// (U+2212) rather than a hyphen-minus (U+002D) in exponential notation.
518+
/// This was due to a bug in J2N (#128) that has since been fixed.
519+
/// </summary>
520+
/// <remarks>
521+
/// https://github.com/NightOwl888/J2N/issues/128
522+
/// </remarks>
523+
[Test]
524+
[LuceneNetSpecific]
525+
public void TestInclusiveNumericRange_UnicodeMinus()
526+
{
527+
// Use a culture that uses a Unicode minus sign rather than a hyphen-minus
528+
// in exponential notation.
529+
LOCALE = new CultureInfo("sv-FI");
530+
CultureInfo.CurrentCulture = LOCALE;
531+
532+
NUMBER_FORMAT = new MockNumberFormat(LOCALE);
533+
534+
var randomNumberMap = new JCG.Dictionary<string, Number>(RANDOM_NUMBER_MAP!)
535+
{
536+
[nameof(NumericType.DOUBLE)] = J2N.Numerics.Double.GetInstance(1.0E-20),
537+
[nameof(NumericType.SINGLE)] = J2N.Numerics.Single.GetInstance(1.0E-20f)
538+
};
539+
540+
RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap);
541+
542+
qp!.NumericConfigMap[nameof(NumericType.DOUBLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.DOUBLE);
543+
qp.NumericConfigMap[nameof(NumericType.SINGLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.SINGLE);
544+
545+
AssertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, true, 1);
546+
}
547+
513548
public void AssertRangeQuery(NumberType? lowerType, NumberType? upperType,
514549
bool lowerInclusive, bool upperInclusive, int expectedDocCount)
515550
{

0 commit comments

Comments
 (0)