diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java index 091189f361a..220e4448559 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/analysis/IcuCollationTokenFilterFactory.java @@ -84,7 +84,7 @@ public class IcuCollationTokenFilterFactory extends AbstractTokenFilterFactory { } collator = Collator.getInstance(locale); } else { - collator = Collator.getInstance(); + collator = Collator.getInstance(ULocale.ROOT); } } diff --git a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java index 655a6d32524..ea966c5fc3a 100644 --- a/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java +++ b/plugins/analysis-icu/src/main/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapper.java @@ -389,7 +389,7 @@ public class ICUCollationKeywordFieldMapper extends FieldMapper { } collator = Collator.getInstance(locale); } else { - collator = Collator.getInstance(); + collator = Collator.getInstance(ULocale.ROOT); } } diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuCollationTokenFilterTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuCollationTokenFilterTests.java index 8f9a38dc8f1..f0689bd1db9 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuCollationTokenFilterTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/analysis/SimpleIcuCollationTokenFilterTests.java @@ -38,6 +38,19 @@ import static org.hamcrest.Matchers.equalTo; // Tests borrowed from Solr's Icu collation key filter factory test. public class SimpleIcuCollationTokenFilterTests extends ESTestCase { + /* + * Tests usage where we do not provide a language or locale + */ + public void testDefaultUsage() throws Exception { + Settings settings = Settings.builder() + .put("index.analysis.filter.myCollator.type", "icu_collation") + .put("index.analysis.filter.myCollator.strength", "primary") + .build(); + TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin()); + + TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator"); + assertCollatesToSame(filterFactory, "FOO", "foo"); + } /* * Turkish has some funny casing. * This test shows how you can solve this kind of thing easily with collation. diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java index 94634fc79c8..0117caf1147 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/CollationFieldTypeTests.java @@ -78,7 +78,7 @@ public class CollationFieldTypeTests extends FieldTypeTestCase { ft.setName("field"); ft.setIndexOptions(IndexOptions.DOCS); - Collator collator = Collator.getInstance().freeze(); + Collator collator = Collator.getInstance(ULocale.ROOT).freeze(); ((CollationFieldType) ft).setCollator(collator); RawCollationKey fooKey = collator.getRawCollationKey("foo", null); @@ -126,7 +126,7 @@ public class CollationFieldTypeTests extends FieldTypeTestCase { ft.setName("field"); ft.setIndexOptions(IndexOptions.DOCS); - Collator collator = Collator.getInstance().freeze(); + Collator collator = Collator.getInstance(ULocale.ROOT).freeze(); ((CollationFieldType) ft).setCollator(collator); RawCollationKey aKey = collator.getRawCollationKey("a", null); diff --git a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java index 0d93b20881c..060a94a9d27 100644 --- a/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java +++ b/plugins/analysis-icu/src/test/java/org/elasticsearch/index/mapper/ICUCollationKeywordFieldMapperTests.java @@ -82,7 +82,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); - Collator collator = Collator.getInstance(); + Collator collator = Collator.getInstance(ULocale.ROOT); RawCollationKey key = collator.getRawCollationKey("1234", null); BytesRef expected = new BytesRef(key.bytes, 0, key.size); @@ -126,7 +126,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(2, fields.length); - Collator collator = Collator.getInstance(); + Collator collator = Collator.getInstance(ULocale.ROOT); RawCollationKey key = collator.getRawCollationKey("1234", null); BytesRef expected = new BytesRef(key.bytes, 0, key.size); @@ -189,7 +189,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { .bytes(), XContentType.JSON)); - Collator collator = Collator.getInstance(); + Collator collator = Collator.getInstance(ULocale.ROOT); RawCollationKey key = collator.getRawCollationKey("1234", null); BytesRef expected = new BytesRef(key.bytes, 0, key.size); @@ -284,7 +284,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { IndexableField[] fields = doc.rootDoc().getFields("field"); assertEquals(4, fields.length); - Collator collator = Collator.getInstance(); + Collator collator = Collator.getInstance(ULocale.ROOT); RawCollationKey key = collator.getRawCollationKey("1234", null); BytesRef expected = new BytesRef(key.bytes, 0, key.size); @@ -305,7 +305,7 @@ public class ICUCollationKeywordFieldMapperTests extends ESSingleNodeTestCase { assertThat(fieldType.indexOptions(), equalTo(IndexOptions.NONE)); assertEquals(DocValuesType.SORTED_SET, fieldType.docValuesType()); - collator = Collator.getInstance(); + collator = Collator.getInstance(ULocale.ROOT); key = collator.getRawCollationKey("5678", null); expected = new BytesRef(key.bytes, 0, key.size);