2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 namespace Lucene
.Net
.Analysis
20 /// <summary> This analyzer is used to facilitate scenarios where different
21 /// fields require different analysis techniques. Use {@link #addAnalyzer}
22 /// to add a non-default analyzer on a Field name basis.
23 /// See TestPerFieldAnalyzerWrapper.java for example usage.
25 public class PerFieldAnalyzerWrapper
:Analyzer
27 private Analyzer defaultAnalyzer
;
28 private System
.Collections
.IDictionary analyzerMap
= new System
.Collections
.Hashtable();
31 /// <summary> Constructs with default analyzer.
34 /// <param name="defaultAnalyzer">Any fields not specifically
35 /// defined to use a different analyzer will use the one provided here.
37 public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer
)
39 this.defaultAnalyzer
= defaultAnalyzer
;
42 /// <summary> Defines an analyzer to use for the specified Field.
45 /// <param name="fieldName">Field name requiring a non-default analyzer.
47 /// <param name="analyzer">non-default analyzer to use for Field
49 public virtual void AddAnalyzer(System
.String fieldName
, Analyzer analyzer
)
51 analyzerMap
[fieldName
] = analyzer
;
54 public override TokenStream
TokenStream(System
.String fieldName
, System
.IO
.TextReader reader
)
56 Analyzer analyzer
= (Analyzer
) analyzerMap
[fieldName
];
59 analyzer
= defaultAnalyzer
;
62 return analyzer
.TokenStream(fieldName
, reader
);