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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/KeepWordFilterFactory.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
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 
 * contributor license agreements.  See the NOTICE file distributed with
4
 
 * this work for additional information regarding copyright ownership.
5
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 
 * (the "License"); you may not use this file except in compliance with
7
 
 * the License.  You may obtain a copy of the License at
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 * Unless required by applicable law or agreed to in writing, software
12
 
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 * See the License for the specific language governing permissions and
15
 
 * limitations under the License.
16
 
 */
17
 
 
18
 
package org.apache.solr.analysis;
19
 
 
20
 
import org.apache.solr.common.ResourceLoader;
21
 
import org.apache.solr.util.plugin.ResourceLoaderAware;
22
 
import org.apache.lucene.analysis.StopFilter;
23
 
import org.apache.lucene.analysis.StopAnalyzer;
24
 
import org.apache.lucene.analysis.TokenStream;
25
 
import org.apache.lucene.analysis.CharArraySet;
26
 
 
27
 
import java.util.Map;
28
 
import java.util.Set;
29
 
import java.io.IOException;
30
 
 
31
 
/**
32
 
 * Factory for {@link KeepWordFilter}. 
33
 
 * <pre class="prettyprint" >
34
 
 * &lt;fieldType name="text_keepword" class="solr.TextField" positionIncrementGap="100"&gt;
35
 
 *   &lt;analyzer&gt;
36
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
37
 
 *     &lt;filter class="solr.KeepWordFilterFactory" words="keepwords.txt" ignoreCase="false" enablePositionIncrements="false"/&gt;
38
 
 *   &lt;/analyzer&gt;
39
 
 * &lt;/fieldType&gt;</pre> 
40
 
 * @version $Id: KeepWordFilterFactory.java 1073810 2011-02-23 16:27:55Z koji $
41
 
 */
42
 
public class KeepWordFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
43
 
 
44
 
  @Override
45
 
  public void init(Map<String,String> args) {
46
 
    super.init(args);
47
 
    assureMatchVersion();
48
 
  }
49
 
 
50
 
  public void inform(ResourceLoader loader) {
51
 
    String wordFiles = args.get("words");
52
 
    ignoreCase = getBoolean("ignoreCase", false);
53
 
    enablePositionIncrements = getBoolean("enablePositionIncrements",false);
54
 
 
55
 
    if (wordFiles != null) {
56
 
      try {
57
 
        words = getWordSet(loader, wordFiles, ignoreCase);
58
 
      } catch (IOException e) {
59
 
        throw new RuntimeException(e);
60
 
      }
61
 
    }
62
 
  }
63
 
 
64
 
  private CharArraySet words;
65
 
  private boolean ignoreCase;
66
 
  private boolean enablePositionIncrements;
67
 
 
68
 
  /**
69
 
   * Set the keep word list.
70
 
   * NOTE: if ignoreCase==true, the words are expected to be lowercase
71
 
   */
72
 
  public void setWords(Set<String> words) {
73
 
    this.words = new CharArraySet(luceneMatchVersion, words, ignoreCase);
74
 
  }
75
 
 
76
 
  public void setIgnoreCase(boolean ignoreCase) {    
77
 
    if (words != null && this.ignoreCase != ignoreCase) {
78
 
      words = new CharArraySet(luceneMatchVersion, words, ignoreCase);
79
 
    }
80
 
    this.ignoreCase = ignoreCase;
81
 
  }
82
 
 
83
 
  public boolean isEnablePositionIncrements() {
84
 
    return enablePositionIncrements;
85
 
  }
86
 
 
87
 
  public boolean isIgnoreCase() {
88
 
    return ignoreCase;
89
 
  }
90
 
 
91
 
  public CharArraySet getWords() {
92
 
    return words;
93
 
  }
94
 
 
95
 
  public KeepWordFilter create(TokenStream input) {
96
 
    return new KeepWordFilter(enablePositionIncrements, input, words);
97
 
  }
98
 
}