1
package org.apache.solr.analysis;
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 java.io.IOException;
21
import java.util.List;
23
import org.apache.lucene.analysis.CharArrayMap;
24
import org.apache.lucene.analysis.TokenStream;
25
import org.apache.lucene.analysis.miscellaneous.StemmerOverrideFilter;
26
import org.apache.solr.common.ResourceLoader;
27
import org.apache.solr.common.util.StrUtils;
28
import org.apache.solr.util.plugin.ResourceLoaderAware;
31
* Factory for {@link StemmerOverrideFilter}.
32
* <pre class="prettyprint" >
33
* <fieldType name="text_dicstem" class="solr.TextField" positionIncrementGap="100">
35
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
36
* <filter class="solr.StemmerOverrideFilterFactory" dictionary="dictionary.txt" ignoreCase="false"/>
38
* </fieldType></pre>
41
public class StemmerOverrideFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
42
private CharArrayMap<String> dictionary = null;
43
private boolean ignoreCase;
45
public void inform(ResourceLoader loader) {
46
String dictionaryFiles = args.get("dictionary");
47
ignoreCase = getBoolean("ignoreCase", false);
48
if (dictionaryFiles != null) {
50
List<String> files = StrUtils.splitFileNames(dictionaryFiles);
52
if (files.size() > 0) {
53
dictionary = new CharArrayMap<String>(luceneMatchVersion,
54
files.size() * 10, ignoreCase);
55
for (String file : files) {
56
List<String> list = loader.getLines(file.trim());
57
for (String line : list) {
58
String[] mapping = line.split("\t", 2);
59
dictionary.put(mapping[0], mapping[1]);
63
} catch (IOException e) {
64
throw new RuntimeException(e);
69
public boolean isIgnoreCase() {
73
public TokenStream create(TokenStream input) {
74
return dictionary == null ? input : new StemmerOverrideFilter(luceneMatchVersion, input, dictionary);