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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/SynonymFilterFactory.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.util.Map;
4
 
 
5
 
import org.apache.lucene.analysis.TokenStream;
6
 
import org.apache.lucene.analysis.synonym.SynonymFilter;
7
 
import org.apache.lucene.util.Version;
8
 
import org.apache.solr.common.ResourceLoader;
9
 
import org.apache.solr.util.plugin.ResourceLoaderAware;
10
 
 
11
 
/**
12
 
 * Factory for {@link SynonymFilter}.
13
 
 * <pre class="prettyprint" >
14
 
 * &lt;fieldType name="text_synonym" class="solr.TextField" positionIncrementGap="100"&gt;
15
 
 *   &lt;analyzer&gt;
16
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
17
 
 *     &lt;filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" 
18
 
 *             format="solr" ignoreCase="false" expand="true" 
19
 
 *             tokenizerFactory="solr.WhitespaceTokenizerFactory"/&gt;
20
 
 *   &lt;/analyzer&gt;
21
 
 * &lt;/fieldType&gt;</pre>
22
 
 */
23
 
public class SynonymFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
24
 
  private BaseTokenFilterFactory delegator;
25
 
 
26
 
  @Override
27
 
  public void init(Map<String,String> args) {
28
 
    super.init(args);
29
 
    assureMatchVersion();
30
 
    if (luceneMatchVersion.onOrAfter(Version.LUCENE_34)) {
31
 
      delegator = new FSTSynonymFilterFactory();
32
 
    } else {
33
 
      // check if you use the new optional arg "format". this makes no sense for the old one, 
34
 
      // as its wired to solr's synonyms format only.
35
 
      if (args.containsKey("format") && !args.get("format").equals("solr")) {
36
 
        throw new IllegalArgumentException("You must specify luceneMatchVersion >= 3.4 to use alternate synonyms formats");
37
 
      }
38
 
      delegator = new SlowSynonymFilterFactory();
39
 
    }
40
 
    delegator.init(args);
41
 
  }
42
 
 
43
 
  public TokenStream create(TokenStream input) {
44
 
    assert delegator != null : "init() was not called!";
45
 
    return delegator.create(input);
46
 
  }
47
 
 
48
 
  public void inform(ResourceLoader loader) {
49
 
    assert delegator != null : "init() was not called!";
50
 
    ((ResourceLoaderAware) delegator).inform(loader);
51
 
  }
52
 
}