KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > search > SmartAnalyzer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.search;
12
13 import java.io.*;
14
15 import org.apache.lucene.analysis.*;
16
17 /**
18  * Smart Analyzer. Chooses underlying implementation based on the field which
19  * text is analyzed.
20  */

21 public class SmartAnalyzer extends Analyzer {
22     Analyzer pluggedInAnalyzer;
23     Analyzer exactAnalyzer;
24
25     /**
26      * Constructor for SmartAnalyzer.
27      */

28     public SmartAnalyzer(String JavaDoc locale, Analyzer pluggedInAnalyzer) {
29         super();
30         this.pluggedInAnalyzer = pluggedInAnalyzer;
31         this.exactAnalyzer = new DefaultAnalyzer(locale);
32     }
33     /**
34      * Creates a TokenStream which tokenizes all the text in the provided
35      * Reader. Delegates to DefaultAnalyzer when field used to search for exact
36      * match, and to plugged-in analyzer for other fields.
37      */

38     public final TokenStream tokenStream(String JavaDoc fieldName, Reader reader) {
39         if (fieldName != null && fieldName.startsWith("exact_")) { //$NON-NLS-1$
40
return exactAnalyzer.tokenStream(fieldName, reader);
41         }
42         return pluggedInAnalyzer.tokenStream(fieldName, reader);
43     }
44 }
45
Popular Tags