1 package org.apache.lucene.analysis.th;
4 * Copyright 2006 The Apache Software Foundation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import java.io.Reader;
21 import org.apache.lucene.analysis.ReusableAnalyzerBase;
22 import org.apache.lucene.analysis.Analyzer;
23 import org.apache.lucene.analysis.StopAnalyzer;
24 import org.apache.lucene.analysis.StopFilter;
25 import org.apache.lucene.analysis.LowerCaseFilter;
26 import org.apache.lucene.analysis.TokenStream;
27 import org.apache.lucene.analysis.Tokenizer;
28 import org.apache.lucene.analysis.standard.StandardAnalyzer;
29 import org.apache.lucene.analysis.standard.StandardFilter;
30 import org.apache.lucene.analysis.standard.StandardTokenizer;
31 import org.apache.lucene.util.Version;
34 * {@link Analyzer} for Thai language. It uses {@link java.text.BreakIterator} to break words.
37 * <p><b>NOTE</b>: This class uses the same {@link Version}
38 * dependent settings as {@link StandardAnalyzer}.</p>
40 public final class ThaiAnalyzer extends ReusableAnalyzerBase {
41 private final Version matchVersion;
43 public ThaiAnalyzer(Version matchVersion) {
44 this.matchVersion = matchVersion;
49 * {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
50 * used to tokenize all the text in the provided {@link Reader}.
52 * @return {@link org.apache.lucene.analysis.ReusableAnalyzerBase.TokenStreamComponents}
53 * built from a {@link StandardTokenizer} filtered with
54 * {@link StandardFilter}, {@link LowerCaseFilter}, {@link ThaiWordFilter}, and
58 protected TokenStreamComponents createComponents(String fieldName,
60 final Tokenizer source = new StandardTokenizer(matchVersion, reader);
61 TokenStream result = new StandardFilter(matchVersion, source);
62 if (matchVersion.onOrAfter(Version.LUCENE_31))
63 result = new LowerCaseFilter(matchVersion, result);
64 result = new ThaiWordFilter(matchVersion, result);
65 return new TokenStreamComponents(source, new StopFilter(matchVersion,
66 result, StopAnalyzer.ENGLISH_STOP_WORDS_SET));