2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.analysis;
20
import org.apache.solr.common.ResourceLoader;
21
import org.apache.solr.util.plugin.ResourceLoaderAware;
22
import org.apache.lucene.analysis.StopFilter;
23
import org.apache.lucene.analysis.StopAnalyzer;
24
import org.apache.lucene.analysis.TokenStream;
25
import org.apache.lucene.analysis.CharArraySet;
29
import java.io.IOException;
32
* Factory for {@link KeepWordFilter}.
33
* <pre class="prettyprint" >
34
* <fieldType name="text_keepword" class="solr.TextField" positionIncrementGap="100">
36
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
37
* <filter class="solr.KeepWordFilterFactory" words="keepwords.txt" ignoreCase="false" enablePositionIncrements="false"/>
39
* </fieldType></pre>
40
* @version $Id: KeepWordFilterFactory.java 1073810 2011-02-23 16:27:55Z koji $
42
public class KeepWordFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
45
public void init(Map<String,String> args) {
50
public void inform(ResourceLoader loader) {
51
String wordFiles = args.get("words");
52
ignoreCase = getBoolean("ignoreCase", false);
53
enablePositionIncrements = getBoolean("enablePositionIncrements",false);
55
if (wordFiles != null) {
57
words = getWordSet(loader, wordFiles, ignoreCase);
58
} catch (IOException e) {
59
throw new RuntimeException(e);
64
private CharArraySet words;
65
private boolean ignoreCase;
66
private boolean enablePositionIncrements;
69
* Set the keep word list.
70
* NOTE: if ignoreCase==true, the words are expected to be lowercase
72
public void setWords(Set<String> words) {
73
this.words = new CharArraySet(luceneMatchVersion, words, ignoreCase);
76
public void setIgnoreCase(boolean ignoreCase) {
77
if (words != null && this.ignoreCase != ignoreCase) {
78
words = new CharArraySet(luceneMatchVersion, words, ignoreCase);
80
this.ignoreCase = ignoreCase;
83
public boolean isEnablePositionIncrements() {
84
return enablePositionIncrements;
87
public boolean isIgnoreCase() {
91
public CharArraySet getWords() {
95
public KeepWordFilter create(TokenStream input) {
96
return new KeepWordFilter(enablePositionIncrements, input, words);