//This fails when ICU's data DLL is built without rules for the en-US locale. public void Create_LocaleWithICUCultureId() { using (var collator = Collator.Create("en_US")) { Assert.That(collator, Is.Not.Null); } }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_RootLocaleAsEmpty() { using (var collator = Collator.Create(string.Empty)) { Assert.That(collator, Is.Not.Null); } }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_RootLocale() { using (var collator = Collator.Create("root")) { Assert.That(collator, Is.Not.Null); } }
public void Create_nonexistentFallbackAllowed_fallsbackToUca() { using (var collator = Collator.Create("non-existent", Collator.Fallback.FallbackAllowed)) { Assert.That(collator, Is.Not.Null); } }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_NoPredefinedCollator_Throws() { Assert.That(() => { using (Collator.Create("my-MM")) {} }, Throws.ArgumentException); }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_PredefinedCollator_Works() { Assert.That(() => { using (Collator.Create("my")) {} }, Throws.Nothing); }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_NoPredefinedCollator_FallbackAllowed_Works() { Assert.That(() => { using (Collator.Create("my-MM", Collator.Fallback.FallbackAllowed)) {} }, Throws.Nothing); }
//This fails when ICU's data DLL is built without rules for the root locale. public void Create_PredefinedCollator_NoFallback_Works() { Assert.That(() => { using (Collator.Create("my", Collator.Fallback.NoFallback)) {} }, Throws.Nothing); }
//This fails when ICU's data DLL is built without rules for the en-US locale. public void Create_LocaleWithCultureInfo() { var cultureInfo = new CultureInfo("en-US"); using (var collator = Collator.Create(cultureInfo.Name)) { Assert.That(collator, Is.Not.Null); } }
public void SetCollatorStrengthToIdentical() { using (var collator = Collator.Create("zh")) { collator.Strength = CollationStrength.Identical; Assert.AreEqual(CollationStrength.Identical, collator.Strength); } }
/// <summary> /// Create a locale from language, with optional country and variant. /// Then return the appropriate collator for the locale. /// </summary> private Collator CreateFromLocale(string language, string country, string variant) { CultureInfo cultureInfo; if (language == null) { throw new ArgumentException("Language is required"); } if (language != null && country == null && variant != null) { throw new ArgumentException("To specify variant, country is required"); } if (country != null && variant != null) { cultureInfo = new CultureInfo(string.Concat(language, "-", country, "-", variant)); // LUCENENET TODO: This method won't work on .NET core - confirm the above solution works as expected. //cultureInfo = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Single(x => //{ // if (!x.TwoLetterISOLanguageName.Equals(language, StringComparison.OrdinalIgnoreCase) && // !x.ThreeLetterISOLanguageName.Equals(language, StringComparison.OrdinalIgnoreCase) && // !x.ThreeLetterWindowsLanguageName.Equals(language, StringComparison.OrdinalIgnoreCase)) // { // return false; // } // var region = new RegionInfo(x.Name); // if (!region.TwoLetterISORegionName.Equals(country, StringComparison.OrdinalIgnoreCase) && // !region.ThreeLetterISORegionName.Equals(country, StringComparison.OrdinalIgnoreCase) && // !region.ThreeLetterWindowsRegionName.Equals(country, StringComparison.OrdinalIgnoreCase) // ) // { // return false; // } // return x.Name // .Replace(x.TwoLetterISOLanguageName, string.Empty) // .Replace(region.TwoLetterISORegionName, string.Empty) // .Replace("-", string.Empty) // .Equals(variant, StringComparison.OrdinalIgnoreCase); //}); } else if (country != null) { cultureInfo = new CultureInfo(string.Concat(language, "-", country)); } else { cultureInfo = new CultureInfo(language); } return(Collator.Create(cultureInfo)); }
protected void EnsureCollator() { if (m_collator != null) { return; } string icuLocale = new Locale(m_stuLocale).Name; m_collator = Collator.Create(icuLocale); }
public virtual void TestThreadSafe() { var iters = 20 * LuceneTestCase.RANDOM_MULTIPLIER; for (var i = 0; i < iters; i++) { var collator = Collator.Create(new CultureInfo("de")); collator.Strength = CollationStrength.Primary; this.AssertThreadSafe(new CollationKeyAnalyzer(LuceneTestCase.TEST_VERSION_CURRENT, collator)); } }
public void TestThreadSafe() { int iters = 20 * RANDOM_MULTIPLIER; for (int i = 0; i < iters; i++) { CultureInfo locale = new CultureInfo("de"); Collator collator = Collator.Create(locale); collator.Strength = CollationStrength.Identical; AssertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator)); } }
public void TestThreadSafe() { #if NETSTANDARD fail("LUCENENET TODO: Fatal crash on NETSTANDARD"); #endif int iters = 20 * RANDOM_MULTIPLIER; for (int i = 0; i < iters; i++) { CultureInfo locale = new CultureInfo("de"); Collator collator = Collator.Create(locale); collator.Strength = CollationStrength.Identical; AssertThreadSafe(new ICUCollationKeyAnalyzer(TEST_VERSION_CURRENT, collator)); } }
internal static Analyzer CreateAnalyzer(CultureInfo locale, Implementation impl) { // LUCENENET specific - senseless to use reflection here because we only have one // collator. object collator = Collator.Create(locale, Collator.Fallback.FallbackAllowed); Type clazz = impl.GetAnalyzerType(); return((Analyzer)Activator.CreateInstance(clazz, #pragma warning disable 612, 618 LuceneVersion.LUCENE_CURRENT, #pragma warning restore 612, 618 collator)); }
/// <summary> /// LUCENENET /// Get the first available collator based on the given localeNames. /// icu.net may not have all the collation rules. /// </summary> private Collator GetCollator(params string[] localeNames) { var firstAvailableLocale = localeNames .Select(x => new Locale(x)) .FirstOrDefault(x => availableCollationLocales.Contains(x.Id)); if (firstAvailableLocale == default(Locale)) { throw new ArgumentException($"None of the locales are available: {string.Join(", ", localeNames)}"); } Collator collator = Collator.Create(firstAvailableLocale.Id); return(collator); }
public void TestCollationKeySort() { Analyzer usAnalyzer = new TestAnalyzer(Collator.Create(new CultureInfo("en-us"), Collator.Fallback.FallbackAllowed)); Analyzer franceAnalyzer = new TestAnalyzer(Collator.Create(new CultureInfo("fr"))); Analyzer swedenAnalyzer = new TestAnalyzer(Collator.Create(new CultureInfo("sv-se"), Collator.Fallback.FallbackAllowed)); Analyzer denmarkAnalyzer = new TestAnalyzer(Collator.Create(new CultureInfo("da-dk"), Collator.Fallback.FallbackAllowed)); // The ICU Collator and java.text.Collator implementations differ in their // orderings - "BFJHD" is the ordering for the ICU Collator for Locale.US. TestCollationKeySort (usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer, "BFJHD", "ECAGI", "BJDFH", "BJDHF"); }
public void TestRanges() { Directory dir = NewDirectory(); RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); Document doc = new Document(); Field field = NewField("field", "", StringField.TYPE_STORED); Collator collator = Collator.Create(CultureInfo.CurrentCulture, Collator.Fallback.FallbackAllowed); // uses -Dtests.locale if (Random().nextBoolean()) { collator.Strength = CollationStrength.Primary; } ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", collator); doc.Add(field); doc.Add(collationField); int numDocs = AtLeast(500); for (int i = 0; i < numDocs; i++) { String value = TestUtil.RandomSimpleString(Random()); field.SetStringValue(value); collationField.SetStringValue(value); iw.AddDocument(doc); } IndexReader ir = iw.Reader; iw.Dispose(); IndexSearcher @is = NewSearcher(ir); int numChecks = AtLeast(100); for (int i = 0; i < numChecks; i++) { String start = TestUtil.RandomSimpleString(Random()); String end = TestUtil.RandomSimpleString(Random()); BytesRef lowerVal = new BytesRef(collator.GetSortKey(start).KeyData); BytesRef upperVal = new BytesRef(collator.GetSortKey(end).KeyData); Query query = new ConstantScoreQuery(FieldCacheRangeFilter.NewBytesRefRange("collated", lowerVal, upperVal, true, true)); DoTestRanges(@is, start, end, query, collator); } ir.Dispose(); dir.Dispose(); }
public void TestBasic() { Directory dir = NewDirectory(); RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, Similarity, TimeZone); Document doc = new Document(); Field field = NewField("field", "", StringField.TYPE_STORED); ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", Collator.Create(new CultureInfo("en"))); doc.Add(field); doc.Add(collationField); field.SetStringValue("ABC"); collationField.SetStringValue("ABC"); iw.AddDocument(doc); field.SetStringValue("abc"); collationField.SetStringValue("abc"); iw.AddDocument(doc); IndexReader ir = iw.Reader; iw.Dispose(); IndexSearcher @is = NewSearcher(ir); SortField sortField = new SortField("collated", SortFieldType.STRING); TopDocs td = @is.Search(new MatchAllDocsQuery(), 5, new Sort(sortField)); assertEquals("abc", ir.Document(td.ScoreDocs[0].Doc).Get("field")); assertEquals("ABC", ir.Document(td.ScoreDocs[1].Doc).Get("field")); ir.Dispose(); dir.Dispose(); }
/// <summary> /// Create a locale from <paramref name="localeID"/>. /// Then return the appropriate collator for the locale. /// </summary> /// <param name="localeID"></param> /// <returns>The appropriate collator for the locale.</returns> private Collator CreateFromLocale(string localeID) { return(Collator.Create(localeID)); }
public void Create_NullCultureInfo() { Assert.That(() => Collator.Create((CultureInfo)null), Throws.TypeOf <ArgumentNullException>()); }
public void Create_NullString() { Assert.That(() => Collator.Create((string)null), Throws.TypeOf <ArgumentNullException>()); }
public void Create_nonexistent_throws() { Assert.That(() => Collator.Create("non-existent"), Throws.TypeOf <ArgumentException>()); }