01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.solr.analysis;
17:
18: import org.apache.lucene.analysis.Analyzer;
19: import org.apache.lucene.analysis.TokenStream;
20: import org.apache.solr.analysis.TokenizerFactory;
21:
22: import java.io.Reader;
23:
24: /**
25: * @author yonik
26: * @version $Id: TokenizerChain.java 472574 2006-11-08 18:25:52Z yonik $
27: */
28:
29: //
30: // An analyzer that uses a tokenizer and a list of token filters to
31: // create a TokenStream.
32: //
33: public class TokenizerChain extends SolrAnalyzer {
34: final private TokenizerFactory tokenizer;
35: final private TokenFilterFactory[] filters;
36:
37: public TokenizerChain(TokenizerFactory tokenizer,
38: TokenFilterFactory[] filters) {
39: this .tokenizer = tokenizer;
40: this .filters = filters;
41: }
42:
43: public TokenizerFactory getTokenizerFactory() {
44: return tokenizer;
45: }
46:
47: public TokenFilterFactory[] getTokenFilterFactories() {
48: return filters;
49: }
50:
51: public TokenStream tokenStream(String fieldName, Reader reader) {
52: TokenStream ts = tokenizer.create(reader);
53: for (int i = 0; i < filters.length; i++) {
54: ts = filters[i].create(ts);
55: }
56: return ts;
57: }
58:
59: public String toString() {
60: StringBuilder sb = new StringBuilder("TokenizerChain(");
61: sb.append(tokenizer);
62: for (TokenFilterFactory filter : filters) {
63: sb.append(", ");
64: sb.append(filter);
65: }
66: sb.append(')');
67: return sb.toString();
68: }
69:
70: }
|