|
| 1 | +using J2N.Globalization; |
1 | 2 | using J2N.Numerics; |
2 | 3 | using Lucene.Net.Analysis; |
| 4 | +using Lucene.Net.Attributes; |
3 | 5 | using Lucene.Net.Documents; |
4 | 6 | using Lucene.Net.Index; |
5 | 7 | using Lucene.Net.Index.Extensions; |
@@ -251,10 +253,10 @@ public override void SetUp() |
251 | 253 | )), LOCALE)) |
252 | 254 | ; |
253 | 255 |
|
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; |
| 256 | + randomNumberMap[nameof(NumericType.INT64)] = (J2N.Numerics.Int64)randomLong; |
| 257 | + randomNumberMap[nameof(NumericType.INT32)] = (J2N.Numerics.Int32)randomInt; |
| 258 | + randomNumberMap[nameof(NumericType.SINGLE)] = (J2N.Numerics.Single)randomFloat; |
| 259 | + randomNumberMap[nameof(NumericType.DOUBLE)] = (J2N.Numerics.Double)randomDouble; |
258 | 260 | randomNumberMap[DATE_FIELD_NAME] = (J2N.Numerics.Int64)randomDate; |
259 | 261 |
|
260 | 262 | RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap); |
@@ -510,6 +512,41 @@ public void TestSimpleNumericQuery() |
510 | 512 | AssertSimpleQuery(NumberType.NEGATIVE, 1); |
511 | 513 | } |
512 | 514 |
|
| 515 | + /// <summary> |
| 516 | + /// Tests the fix for Lucene.NET GitHub issue #846. |
| 517 | + /// Numeric values were failing for cultures that use a Unicode minus sign |
| 518 | + /// (U+2212) rather than a hyphen-minus (U+002D) in exponential notation. |
| 519 | + /// This was due to a bug in J2N (#128) that has since been fixed. |
| 520 | + /// </summary> |
| 521 | + /// <remarks> |
| 522 | + /// https://github.com/NightOwl888/J2N/issues/128 |
| 523 | + /// </remarks> |
| 524 | + [Test] |
| 525 | + [LuceneNetSpecific] |
| 526 | + public void TestInclusiveNumericRange_UnicodeMinus() |
| 527 | + { |
| 528 | + // Use a culture that uses a Unicode minus sign rather than a hyphen-minus |
| 529 | + // in exponential notation. |
| 530 | + LOCALE = new CultureInfo("sv-FI"); |
| 531 | + using (var cultureContext = new CultureContext(LOCALE)) |
| 532 | + { |
| 533 | + NUMBER_FORMAT = new MockNumberFormat(LOCALE); |
| 534 | + |
| 535 | + var randomNumberMap = new JCG.Dictionary<string, Number>(RANDOM_NUMBER_MAP!) |
| 536 | + { |
| 537 | + [nameof(NumericType.DOUBLE)] = J2N.Numerics.Double.GetInstance(1.0E-20), |
| 538 | + [nameof(NumericType.SINGLE)] = J2N.Numerics.Single.GetInstance(1.0E-20f) |
| 539 | + }; |
| 540 | + |
| 541 | + RANDOM_NUMBER_MAP = JCG.Extensions.DictionaryExtensions.AsReadOnly(randomNumberMap); |
| 542 | + |
| 543 | + qp!.NumericConfigMap[nameof(NumericType.DOUBLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.DOUBLE); |
| 544 | + qp.NumericConfigMap[nameof(NumericType.SINGLE)] = new NumericConfig(PRECISION_STEP, NUMBER_FORMAT, NumericType.SINGLE); |
| 545 | + |
| 546 | + AssertRangeQuery(NumberType.ZERO, NumberType.POSITIVE, true, true, 1); |
| 547 | + } |
| 548 | + } |
| 549 | + |
513 | 550 | public void AssertRangeQuery(NumberType? lowerType, NumberType? upperType, |
514 | 551 | bool lowerInclusive, bool upperInclusive, int expectedDocCount) |
515 | 552 | { |
|
0 commit comments