1
package org.apache.solr.analysis;
3
import java.io.IOException;
5
import org.apache.lucene.analysis.CharArraySet;
6
import org.apache.lucene.analysis.KeywordMarkerFilter;
7
import org.apache.lucene.analysis.TokenStream;
8
import org.apache.solr.common.ResourceLoader;
9
import org.apache.solr.util.plugin.ResourceLoaderAware;
12
* Licensed to the Apache Software Foundation (ASF) under one or more
13
* contributor license agreements. See the NOTICE file distributed with
14
* this work for additional information regarding copyright ownership.
15
* The ASF licenses this file to You under the Apache License, Version 2.0
16
* (the "License"); you may not use this file except in compliance with
17
* the License. You may obtain a copy of the License at
19
* http://www.apache.org/licenses/LICENSE-2.0
21
* Unless required by applicable law or agreed to in writing, software
22
* distributed under the License is distributed on an "AS IS" BASIS,
23
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
* See the License for the specific language governing permissions and
25
* limitations under the License.
29
* Factory for {@link KeywordMarkerFilter}.
30
* <pre class="prettyprint" >
31
* <fieldType name="text_keyword" class="solr.TextField" positionIncrementGap="100">
33
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
34
* <filter class="solr.KeywordMarkerFilterFactory" protected="protectedkeyword.txt" ignoreCase="false"/>
36
* </fieldType></pre>
39
public class KeywordMarkerFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
40
public static final String PROTECTED_TOKENS = "protected";
41
private CharArraySet protectedWords;
42
private boolean ignoreCase;
44
public void inform(ResourceLoader loader) {
45
String wordFiles = args.get(PROTECTED_TOKENS);
46
ignoreCase = getBoolean("ignoreCase", false);
47
if (wordFiles != null) {
49
protectedWords = getWordSet(loader, wordFiles, ignoreCase);
50
} catch (IOException e) {
51
throw new RuntimeException(e);
56
public boolean isIgnoreCase() {
60
public TokenStream create(TokenStream input) {
61
return protectedWords == null ? input : new KeywordMarkerFilter(input, protectedWords);