Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Analysis / PerFieldAnalyzerWrapper.cs
blob4dd27e767c11d766135dc68dc68cf2580a512f42
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
16 using System;
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.
24 /// </summary>
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.
32 ///
33 /// </summary>
34 /// <param name="defaultAnalyzer">Any fields not specifically
35 /// defined to use a different analyzer will use the one provided here.
36 /// </param>
37 public PerFieldAnalyzerWrapper(Analyzer defaultAnalyzer)
39 this.defaultAnalyzer = defaultAnalyzer;
42 /// <summary> Defines an analyzer to use for the specified Field.
43 ///
44 /// </summary>
45 /// <param name="fieldName">Field name requiring a non-default analyzer.
46 /// </param>
47 /// <param name="analyzer">non-default analyzer to use for Field
48 /// </param>
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];
57 if (analyzer == null)
59 analyzer = defaultAnalyzer;
62 return analyzer.TokenStream(fieldName, reader);