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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/StemmerOverrideFilterFactory.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
 
package org.apache.solr.analysis;
2
 
 
3
 
/**
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
10
 
 *
11
 
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 
 *
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.
18
 
 */
19
 
 
20
 
import java.io.IOException;
21
 
import java.util.List;
22
 
 
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;
29
 
 
30
 
/**
31
 
 * Factory for {@link StemmerOverrideFilter}.
32
 
 * <pre class="prettyprint" >
33
 
 * &lt;fieldType name="text_dicstem" class="solr.TextField" positionIncrementGap="100"&gt;
34
 
 *   &lt;analyzer&gt;
35
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
36
 
 *     &lt;filter class="solr.StemmerOverrideFilterFactory" dictionary="dictionary.txt" ignoreCase="false"/&gt;
37
 
 *   &lt;/analyzer&gt;
38
 
 * &lt;/fieldType&gt;</pre>
39
 
 * @version $Id
40
 
 */
41
 
public class StemmerOverrideFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
42
 
  private CharArrayMap<String> dictionary = null;
43
 
  private boolean ignoreCase;
44
 
 
45
 
  public void inform(ResourceLoader loader) {
46
 
    String dictionaryFiles = args.get("dictionary");
47
 
    ignoreCase = getBoolean("ignoreCase", false);
48
 
    if (dictionaryFiles != null) {
49
 
      assureMatchVersion();
50
 
      List<String> files = StrUtils.splitFileNames(dictionaryFiles);
51
 
      try {
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]);
60
 
            }
61
 
          }
62
 
        }
63
 
      } catch (IOException e) {
64
 
        throw new RuntimeException(e);
65
 
      }
66
 
    }
67
 
  }
68
 
 
69
 
  public boolean isIgnoreCase() {
70
 
    return ignoreCase;
71
 
  }
72
 
 
73
 
  public TokenStream create(TokenStream input) {
74
 
    return dictionary == null ? input : new StemmerOverrideFilter(luceneMatchVersion, input, dictionary);
75
 
  }
76
 
}