3
* Licensed to the Apache Software Foundation (ASF) under one or more
4
* contributor license agreements. See the NOTICE file distributed with
5
* this work for additional information regarding copyright ownership.
6
* The ASF licenses this file to You under the Apache License, Version 2.0
7
* (the "License"); you may not use this file except in compliance with
8
* the License. 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.
20
package org.apache.solr.analysis;
21
import org.apache.lucene.analysis.CharArraySet;
22
import org.apache.lucene.analysis.compound.*;
23
import org.apache.solr.util.plugin.ResourceLoaderAware;
24
import org.apache.solr.common.ResourceLoader;
25
import org.apache.solr.common.SolrException;
26
import org.apache.lucene.analysis.TokenStream;
28
import java.io.IOException;
31
* Factory for {@link DictionaryCompoundWordTokenFilter}.
32
* <pre class="prettyprint" >
33
* <fieldType name="text_dictcomp" class="solr.TextField" positionIncrementGap="100">
35
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
36
* <filter class="solr.DictionaryCompoundWordTokenFilterFactory" dictionary="dictionary.txt"
37
* minWordSize="5" minSubwordSize="2" maxSubwordSize="15" onlyLongestMatch="true"/>
39
* </fieldType></pre>
40
* @version $Id: DictionaryCompoundWordTokenFilterFactory.java 1073344 2011-02-22 14:35:02Z koji $
42
public class DictionaryCompoundWordTokenFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
43
private CharArraySet dictionary;
44
private String dictFile;
45
private int minWordSize;
46
private int minSubwordSize;
47
private int maxSubwordSize;
48
private boolean onlyLongestMatch;
50
public void init(Map<String, String> args) {
53
dictFile = args.get("dictionary");
54
if (null == dictFile) {
55
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
56
"Missing required parameter: dictionary");
59
minWordSize= getInt("minWordSize",CompoundWordTokenFilterBase.DEFAULT_MIN_WORD_SIZE);
60
minSubwordSize= getInt("minSubwordSize",CompoundWordTokenFilterBase.DEFAULT_MIN_SUBWORD_SIZE);
61
maxSubwordSize= getInt("maxSubwordSize",CompoundWordTokenFilterBase.DEFAULT_MAX_SUBWORD_SIZE);
62
onlyLongestMatch = getBoolean("onlyLongestMatch",true);
64
public void inform(ResourceLoader loader) {
66
dictionary = super.getWordSet(loader, dictFile, false);
67
} catch (IOException e) {
68
throw new RuntimeException(e);
71
public DictionaryCompoundWordTokenFilter create(TokenStream input) {
72
return new DictionaryCompoundWordTokenFilter(luceneMatchVersion,input,dictionary,minWordSize,minSubwordSize,maxSubwordSize,onlyLongestMatch);