~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/DictionaryCompoundWordTokenFilterFactory.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/**
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
9
 
 *
10
 
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 
 *
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.
17
 
 */
18
 
 
19
 
 
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;
27
 
import java.util.Map;
28
 
import java.io.IOException;
29
 
 
30
 
/** 
31
 
 * Factory for {@link DictionaryCompoundWordTokenFilter}. 
32
 
 * <pre class="prettyprint" >
33
 
 * &lt;fieldType name="text_dictcomp" class="solr.TextField" positionIncrementGap="100"&gt;
34
 
 *   &lt;analyzer&gt;
35
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
36
 
 *     &lt;filter class="solr.DictionaryCompoundWordTokenFilterFactory" dictionary="dictionary.txt"
37
 
 *           minWordSize="5" minSubwordSize="2" maxSubwordSize="15" onlyLongestMatch="true"/&gt;
38
 
 *   &lt;/analyzer&gt;
39
 
 * &lt;/fieldType&gt;</pre>
40
 
 * @version $Id: DictionaryCompoundWordTokenFilterFactory.java 1073344 2011-02-22 14:35:02Z koji $
41
 
 */
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;
49
 
  @Override
50
 
  public void init(Map<String, String> args) {
51
 
    super.init(args);
52
 
    assureMatchVersion();
53
 
    dictFile = args.get("dictionary");
54
 
    if (null == dictFile) {
55
 
      throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, 
56
 
                               "Missing required parameter: dictionary");
57
 
    }
58
 
 
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);
63
 
  }
64
 
  public void inform(ResourceLoader loader) {
65
 
    try {
66
 
      dictionary = super.getWordSet(loader, dictFile, false);
67
 
    } catch (IOException e) {
68
 
      throw new RuntimeException(e);
69
 
    }
70
 
  }
71
 
  public DictionaryCompoundWordTokenFilter create(TokenStream input) {
72
 
    return new DictionaryCompoundWordTokenFilter(luceneMatchVersion,input,dictionary,minWordSize,minSubwordSize,maxSubwordSize,onlyLongestMatch);
73
 
  }
74
 
}
75