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

« back to all changes in this revision

Viewing changes to solr/core/src/java/org/apache/solr/analysis/DelimitedPayloadTokenFilterFactory.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
 
 * 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
 
import org.apache.lucene.analysis.TokenStream;
20
 
import org.apache.lucene.analysis.payloads.DelimitedPayloadTokenFilter;
21
 
import org.apache.lucene.analysis.payloads.PayloadEncoder;
22
 
import org.apache.lucene.analysis.payloads.FloatEncoder;
23
 
import org.apache.lucene.analysis.payloads.IntegerEncoder;
24
 
import org.apache.lucene.analysis.payloads.IdentityEncoder;
25
 
import org.apache.solr.common.ResourceLoader;
26
 
import org.apache.solr.common.SolrException;
27
 
import org.apache.solr.util.plugin.ResourceLoaderAware;
28
 
 
29
 
import java.util.Map;
30
 
 
31
 
 
32
 
/**
33
 
 *
34
 
 * Factory for {@link DelimitedPayloadTokenFilter}.
35
 
 * <pre class="prettyprint" >
36
 
 * &lt;fieldType name="text_dlmtd" class="solr.TextField" positionIncrementGap="100"&gt;
37
 
 *   &lt;analyzer&gt;
38
 
 *     &lt;tokenizer class="solr.WhitespaceTokenizerFactory"/&gt;
39
 
 *     &lt;filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float" delimiter="|"/&gt;
40
 
 *   &lt;/analyzer&gt;
41
 
 * &lt;/fieldType&gt;</pre>
42
 
 * @version $Id$
43
 
 * 
44
 
 */
45
 
public class DelimitedPayloadTokenFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
46
 
  public static final String ENCODER_ATTR = "encoder";
47
 
  public static final String DELIMITER_ATTR = "delimiter";
48
 
 
49
 
  private PayloadEncoder encoder;
50
 
  private char delimiter = '|';
51
 
 
52
 
  public DelimitedPayloadTokenFilter create(TokenStream input) {
53
 
    return new DelimitedPayloadTokenFilter(input, delimiter, encoder);
54
 
  }
55
 
 
56
 
  @Override
57
 
  public void init(Map<String, String> args) {
58
 
    super.init(args);
59
 
  }
60
 
 
61
 
  public void inform(ResourceLoader loader) {
62
 
    String encoderClass = args.get(ENCODER_ATTR);
63
 
    if (encoderClass.equals("float")){
64
 
      encoder = new FloatEncoder();
65
 
    } else if (encoderClass.equals("integer")){
66
 
      encoder = new IntegerEncoder();
67
 
    } else if (encoderClass.equals("identity")){
68
 
      encoder = new IdentityEncoder();
69
 
    } else {
70
 
      encoder = (PayloadEncoder) loader.newInstance(encoderClass);
71
 
    }
72
 
 
73
 
    String delim = args.get(DELIMITER_ATTR);
74
 
    if (delim != null){
75
 
      if (delim.length() == 1) {
76
 
        delimiter = delim.charAt(0);
77
 
      } else{
78
 
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Delimiter must be one character only");
79
 
      }
80
 
    }
81
 
  }
82
 
}
 
 
b'\\ No newline at end of file'