11// Lucene version compatibility level 4.8.1
2- #if FEATURE_COLLATION
3- using Icu . Collation ;
42using Lucene . Net . Analysis ;
53using Lucene . Net . Analysis . Core ;
64using Lucene . Net . Util ;
75using System ;
6+ using System . Globalization ;
87using System . IO ;
98
109namespace Lucene . Net . Collation
@@ -37,41 +36,37 @@ namespace Lucene.Net.Collation
3736 /// it to be stored as an index term.
3837 /// </para>
3938 /// <para>
40- /// <strong>WARNING:</strong> Make sure you use exactly the same <see cref="Collator "/> at
39+ /// <strong>WARNING:</strong> Make sure you use exactly the same <see cref="CompareInfo "/> at
4140 /// index and query time -- <see cref="System.Globalization.SortKey"/> are only comparable when produced by
42- /// the same <see cref="Collator "/>. Since <c>java.text.RuleBasedCollators</c> are not
41+ /// the same <see cref="CompareInfo "/>. Since the platform collator is not
4342 /// independently versioned, it is unsafe to search against stored
4443 /// <see cref="System.Globalization.SortKey"/> unless the following are exactly the same (best practice is
4544 /// to store this information with the index and check that they remain the
4645 /// same at query time):
4746 /// </para>
4847 /// <list type="number">
49- /// <item><description>JVM vendor</description></item>
50- /// <item><description>JVM version, including patch version</description></item>
48+ /// <item><description>The .NET runtime version</description></item>
5149 /// <item><description>
52- /// The language (and country and variant, if specified) of the Locale
53- /// used when constructing the collator via
54- /// <see cref="Collator.Create(System.Globalization.CultureInfo)"/>.
50+ /// The <see cref="CultureInfo"/> of the <see cref="CompareInfo"/> obtained via
51+ /// <see cref="CompareInfo.GetCompareInfo(string)"/>.
5552 /// </description></item>
5653 /// <item><description>
57- /// The collation strength used - see <see cref="Collator.Strength"/>
54+ /// The <see cref="CompareOptions"/> used - which control the collation strength
55+ /// and Unicode normalization.
5856 /// </description></item>
5957 /// </list>
6058 /// <para>
61- /// The <c>ICUCollationKeyAnalyzer</c> in the analysis-icu package
62- /// uses ICU4J's Collator, which makes its
63- /// its version available, thus allowing collation to be versioned
64- /// independently from the JVM. ICUCollationKeyAnalyzer is also significantly
65- /// faster and generates significantly shorter keys than CollationKeyAnalyzer.
66- /// See <a href="http://site.icu-project.org/charts/collation-icu4j-sun"
67- /// >http://site.icu-project.org/charts/collation-icu4j-sun</a> for key
68- /// generation timing and key length comparisons between ICU4J and
69- /// <see cref="Collator"/> over several languages.
59+ /// The <c>ICUCollationKeyAnalyzer</c> in the Lucene.Net.ICU package
60+ /// uses ICU4N's Collator, which makes its
61+ /// version available, thus allowing collation to be versioned
62+ /// independently from the .NET runtime. ICUCollationKeyAnalyzer
63+ /// generates significantly shorter keys than <see cref="CollationKeyAnalyzer"/> and
64+ /// exposes tailoring/custom rules that the platform collator does not support.
7065 /// </para>
7166 /// <para>
72- /// CollationKeys generated by <see cref="Collator "/> are not compatible
73- /// with those those generated by ICU Collators. Specifically, if you use
74- /// CollationKeyAnalyzer to generate index terms, do not use
67+ /// <see cref="System.Globalization.SortKey "/>s generated by the platform collator are not compatible
68+ /// with those generated by ICU Collators. Specifically, if you use
69+ /// <see cref=" CollationKeyAnalyzer"/> to generate index terms, do not use
7570 /// ICUCollationKeyAnalyzer on the query side, or vice versa.
7671 /// </para>
7772 /// <para>You must specify the required <see cref="LuceneVersion"/>
@@ -84,7 +79,8 @@ namespace Lucene.Net.Collation
8479 /// </summary>
8580 public sealed class CollationKeyAnalyzer : Analyzer
8681 {
87- private readonly Collator collator ;
82+ private readonly CompareInfo collator ;
83+ private readonly CompareOptions options ;
8884 private readonly CollationAttributeFactory factory ;
8985 private readonly LuceneVersion matchVersion ;
9086
@@ -93,20 +89,33 @@ public sealed class CollationKeyAnalyzer : Analyzer
9389 /// </summary>
9490 /// <param name="matchVersion"> See <see cref="CollationKeyAnalyzer"/> </param>
9591 /// <param name="collator"> <see cref="System.Globalization.SortKey"/> generator </param>
96- public CollationKeyAnalyzer ( LuceneVersion matchVersion , Collator collator )
92+ public CollationKeyAnalyzer ( LuceneVersion matchVersion , CompareInfo collator )
93+ : this ( matchVersion , collator , CompareOptions . None )
94+ {
95+ }
96+
97+ /// <summary>
98+ /// Create a new <see cref="CollationKeyAnalyzer"/>, using the specified collator.
99+ /// </summary>
100+ /// <param name="matchVersion"> See <see cref="CollationKeyAnalyzer"/> </param>
101+ /// <param name="collator"> <see cref="System.Globalization.SortKey"/> generator </param>
102+ /// <param name="options"> Collation options that control the collation strength and
103+ /// Unicode normalization (decomposition) of the generated sort key. </param>
104+ public CollationKeyAnalyzer ( LuceneVersion matchVersion , CompareInfo collator , CompareOptions options )
97105 {
98106 this . matchVersion = matchVersion ;
99107 this . collator = collator ;
100- this . factory = new CollationAttributeFactory ( collator ) ;
108+ this . options = options ;
109+ this . factory = new CollationAttributeFactory ( collator , options ) ;
101110 }
102111
103- [ Obsolete ( "Use <seealso cref= \" CollationKeyAnalyzer# CollationKeyAnalyzer(LuceneVersion, Collator) \" /> and specify a version instead. This ctor will be removed in Lucene 5.0" ) ]
104- public CollationKeyAnalyzer ( Collator collator )
105- : this ( LuceneVersion . LUCENE_31 , collator )
112+ [ Obsolete ( "Use CollationKeyAnalyzer. CollationKeyAnalyzer(LuceneVersion, CompareInfo) and specify a version instead. This ctor will be removed in Lucene 5.0" ) ]
113+ public CollationKeyAnalyzer ( CompareInfo collator )
114+ : this ( LuceneVersion . LUCENE_31 , collator , CompareOptions . None )
106115 {
107116 }
108117
109- protected override TokenStreamComponents CreateComponents ( string fieldName , TextReader reader )
118+ protected internal override TokenStreamComponents CreateComponents ( string fieldName , TextReader reader )
110119 {
111120#pragma warning disable 612 , 618
112121 if ( this . matchVersion . OnOrAfter ( LuceneVersion . LUCENE_40 ) )
@@ -120,10 +129,9 @@ protected override TokenStreamComponents CreateComponents(string fieldName, Text
120129 var tokenizer = new KeywordTokenizer ( reader ) ;
121130 return new TokenStreamComponents ( tokenizer ,
122131#pragma warning disable 612 , 618
123- new CollationKeyFilter ( tokenizer , this . collator ) ) ;
132+ new CollationKeyFilter ( tokenizer , this . collator , this . options ) ) ;
124133#pragma warning restore 612 , 618
125134 }
126135 }
127136 }
128137}
129- #endif
0 commit comments