1 package org.apache.lucene.collation;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 import com.ibm.icu.text.Collator;
23 import org.apache.lucene.analysis.Analyzer;
24 import org.apache.lucene.analysis.CollationTestBase;
26 import java.util.Locale;
29 public class TestICUCollationKeyAnalyzer extends CollationTestBase {
31 private Collator collator = Collator.getInstance(new Locale("fa"));
32 private Analyzer analyzer = new ICUCollationKeyAnalyzer(collator);
34 private String firstRangeBeginning = encodeCollationKey
35 (collator.getCollationKey(firstRangeBeginningOriginal).toByteArray());
36 private String firstRangeEnd = encodeCollationKey
37 (collator.getCollationKey(firstRangeEndOriginal).toByteArray());
38 private String secondRangeBeginning = encodeCollationKey
39 (collator.getCollationKey(secondRangeBeginningOriginal).toByteArray());
40 private String secondRangeEnd = encodeCollationKey
41 (collator.getCollationKey(secondRangeEndOriginal).toByteArray());
43 public void testFarsiRangeFilterCollating() throws Exception {
44 testFarsiRangeFilterCollating(analyzer, firstRangeBeginning, firstRangeEnd,
45 secondRangeBeginning, secondRangeEnd);
48 public void testFarsiRangeQueryCollating() throws Exception {
49 testFarsiRangeQueryCollating(analyzer, firstRangeBeginning, firstRangeEnd,
50 secondRangeBeginning, secondRangeEnd);
53 public void testFarsiTermRangeQuery() throws Exception {
54 testFarsiTermRangeQuery
55 (analyzer, firstRangeBeginning, firstRangeEnd,
56 secondRangeBeginning, secondRangeEnd);
59 // Test using various international locales with accented characters (which
60 // sort differently depending on locale)
62 // Copied (and slightly modified) from
63 // org.apache.lucene.search.TestSort.testInternationalSort()
65 public void testCollationKeySort() throws Exception {
66 Analyzer usAnalyzer = new ICUCollationKeyAnalyzer
67 (Collator.getInstance(Locale.US));
68 Analyzer franceAnalyzer = new ICUCollationKeyAnalyzer
69 (Collator.getInstance(Locale.FRANCE));
70 Analyzer swedenAnalyzer = new ICUCollationKeyAnalyzer
71 (Collator.getInstance(new Locale("sv", "se")));
72 Analyzer denmarkAnalyzer = new ICUCollationKeyAnalyzer
73 (Collator.getInstance(new Locale("da", "dk")));
75 // The ICU Collator and java.text.Collator implementations differ in their
76 // orderings - "BFJHD" is the ordering for the ICU Collator for Locale.US.
78 (usAnalyzer, franceAnalyzer, swedenAnalyzer, denmarkAnalyzer,
79 "BFJHD", "ECAGI", "BJDFH", "BJDHF");
82 public void testThreadSafe() throws Exception {
83 int iters = 20 * RANDOM_MULTIPLIER;
84 for (int i = 0; i < iters; i++) {
85 Locale locale = Locale.GERMAN;
86 Collator collator = Collator.getInstance(locale);
87 collator.setStrength(Collator.IDENTICAL);
88 assertThreadSafe(new ICUCollationKeyAnalyzer(collator));