1
package org.apache.solr.analysis;
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
10
* http://www.apache.org/licenses/LICENSE-2.0
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.
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;
34
* Factory for {@link DelimitedPayloadTokenFilter}.
35
* <pre class="prettyprint" >
36
* <fieldType name="text_dlmtd" class="solr.TextField" positionIncrementGap="100">
38
* <tokenizer class="solr.WhitespaceTokenizerFactory"/>
39
* <filter class="solr.DelimitedPayloadTokenFilterFactory" encoder="float" delimiter="|"/>
41
* </fieldType></pre>
45
public class DelimitedPayloadTokenFilterFactory extends BaseTokenFilterFactory implements ResourceLoaderAware {
46
public static final String ENCODER_ATTR = "encoder";
47
public static final String DELIMITER_ATTR = "delimiter";
49
private PayloadEncoder encoder;
50
private char delimiter = '|';
52
public DelimitedPayloadTokenFilter create(TokenStream input) {
53
return new DelimitedPayloadTokenFilter(input, delimiter, encoder);
57
public void init(Map<String, String> args) {
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();
70
encoder = (PayloadEncoder) loader.newInstance(encoderClass);
73
String delim = args.get(DELIMITER_ATTR);
75
if (delim.length() == 1) {
76
delimiter = delim.charAt(0);
78
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Delimiter must be one character only");
b'\\ No newline at end of file'