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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/KeywordMarkerFilterFactory.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
 
import java.io.IOException;
4
 
 
5
 
import org.apache.lucene.analysis.CharArraySet;
6
 
import org.apache.lucene.analysis.KeywordMarkerFilter;
7
 
import org.apache.lucene.analysis.TokenStream;
8
 
import org.apache.solr.common.ResourceLoader;
9
 
import org.apache.solr.util.plugin.ResourceLoaderAware;
10
 
 
11
 
/**
12
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
13
 
 * contributor license agreements.  See the NOTICE file distributed with
14
 
 * this work for additional information regarding copyright ownership.
15
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
16
 
 * (the "License"); you may not use this file except in compliance with
17
 
 * the License.  You may obtain a copy of the License at
18
 
 *
19
 
 *     http://www.apache.org/licenses/LICENSE-2.0
20
 
 *
21
 
 * Unless required by applicable law or agreed to in writing, software
22
 
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 
 * See the License for the specific language governing permissions and
25
 
 * limitations under the License.
26
 
 */
27
 
 
28
 
/**
29
 
 * Factory for {@link KeywordMarkerFilter}.
30
 
 * <pre class="prettyprint" >
31
 
 * &lt;fieldType name="text_keyword" class="solr.TextField" positionIncrementGap="100"&gt;
32
 
 *   &lt;analyzer&gt;
33
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
34
 
 *     &lt;filter class="solr.KeywordMarkerFilterFactory" protected="protectedkeyword.txt" ignoreCase="false"/&gt;
35
 
 *   &lt;/analyzer&gt;
36
 
 * &lt;/fieldType&gt;</pre> 
37
 
 * @version $Id$
38
 
 */
39
 
public class KeywordMarkerFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
40
 
  public static final String PROTECTED_TOKENS = "protected";
41
 
  private CharArraySet protectedWords;
42
 
  private boolean ignoreCase;
43
 
  
44
 
  public void inform(ResourceLoader loader) {
45
 
    String wordFiles = args.get(PROTECTED_TOKENS);
46
 
    ignoreCase = getBoolean("ignoreCase", false);
47
 
    if (wordFiles != null) {  
48
 
      try {
49
 
        protectedWords = getWordSet(loader, wordFiles, ignoreCase);
50
 
      } catch (IOException e) {
51
 
        throw new RuntimeException(e);
52
 
      }
53
 
    }
54
 
  }
55
 
  
56
 
  public boolean isIgnoreCase() {
57
 
    return ignoreCase;
58
 
  }
59
 
 
60
 
  public TokenStream create(TokenStream input) {
61
 
    return protectedWords == null ? input : new KeywordMarkerFilter(input, protectedWords);
62
 
  }
63
 
}