1 package org.apache.lucene.analysis.cjk;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import org.apache.lucene.analysis.Analyzer;
21 import org.apache.lucene.analysis.CharArraySet;
22 import org.apache.lucene.analysis.StopFilter;
23 import org.apache.lucene.analysis.StopwordAnalyzerBase;
24 import org.apache.lucene.analysis.Tokenizer;
25 import org.apache.lucene.util.Version;
27 import java.io.Reader;
28 import java.util.Arrays;
33 * An {@link Analyzer} that tokenizes text with {@link CJKTokenizer} and
34 * filters with {@link StopFilter}
37 public final class CJKAnalyzer extends StopwordAnalyzerBase {
38 //~ Static fields/initializers ---------------------------------------------
41 * An array containing some common English words that are not usually
42 * useful for searching and some double-byte interpunctions.
43 * @deprecated use {@link #getDefaultStopSet()} instead
46 public final static String[] STOP_WORDS = {
47 "a", "and", "are", "as", "at", "be",
48 "but", "by", "for", "if", "in",
49 "into", "is", "it", "no", "not",
50 "of", "on", "or", "s", "such", "t",
51 "that", "the", "their", "then",
52 "there", "these", "they", "this",
53 "to", "was", "will", "with", "",
57 //~ Instance fields --------------------------------------------------------
60 * Returns an unmodifiable instance of the default stop-words set.
61 * @return an unmodifiable instance of the default stop-words set.
63 public static Set<?> getDefaultStopSet(){
64 return DefaultSetHolder.DEFAULT_STOP_SET;
67 private static class DefaultSetHolder {
68 static final Set<?> DEFAULT_STOP_SET = CharArraySet
69 .unmodifiableSet(new CharArraySet(Version.LUCENE_CURRENT, Arrays.asList(STOP_WORDS),
73 //~ Constructors -----------------------------------------------------------
76 * Builds an analyzer which removes words in {@link #getDefaultStopSet()}.
78 public CJKAnalyzer(Version matchVersion) {
79 this(matchVersion, DefaultSetHolder.DEFAULT_STOP_SET);
83 * Builds an analyzer with the given stop words
86 * lucene compatibility version
90 public CJKAnalyzer(Version matchVersion, Set<?> stopwords){
91 super(matchVersion, stopwords);
95 * Builds an analyzer which removes words in the provided array.
97 * @param stopWords stop word array
98 * @deprecated use {@link #CJKAnalyzer(Version, Set)} instead
101 public CJKAnalyzer(Version matchVersion, String... stopWords) {
102 super(matchVersion, StopFilter.makeStopSet(matchVersion, stopWords));
105 //~ Methods ----------------------------------------------------------------
108 protected TokenStreamComponents createComponents(String fieldName,
110 final Tokenizer source = new CJKTokenizer(reader);
111 return new TokenStreamComponents(source, new StopFilter(matchVersion, source, stopwords));