2010-02-21 10:28:11 +02:00
|
|
|
/*
|
|
|
|
* Licensed to Elastic Search and Shay Banon under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. Elastic Search licenses this
|
|
|
|
* file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.elasticsearch.index.analysis;
|
|
|
|
|
|
|
|
import org.apache.lucene.analysis.Analyzer;
|
|
|
|
import org.apache.lucene.analysis.TokenStream;
|
|
|
|
import org.apache.lucene.document.Fieldable;
|
2010-06-15 17:28:05 +03:00
|
|
|
import org.elasticsearch.common.util.concurrent.Immutable;
|
2010-02-21 10:28:11 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.Reader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Named analyzer is an analyzer wrapper around an actual analyzer ({@link #analyzer} that is associated
|
|
|
|
* with a name ({@link #name()}.
|
|
|
|
*
|
|
|
|
* @author kimchy (shay.banon)
|
|
|
|
*/
|
|
|
|
@Immutable
|
2011-04-04 12:54:14 +03:00
|
|
|
public final class NamedAnalyzer extends Analyzer {
|
2010-02-21 10:28:11 +02:00
|
|
|
|
|
|
|
private final String name;
|
|
|
|
|
2010-05-20 00:55:31 +03:00
|
|
|
private final AnalyzerScope scope;
|
|
|
|
|
2010-02-21 10:28:11 +02:00
|
|
|
private final Analyzer analyzer;
|
|
|
|
|
|
|
|
public NamedAnalyzer(String name, Analyzer analyzer) {
|
2010-05-20 00:55:31 +03:00
|
|
|
this(name, AnalyzerScope.INDEX, analyzer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NamedAnalyzer(String name, AnalyzerScope scope, Analyzer analyzer) {
|
2010-02-21 10:28:11 +02:00
|
|
|
this.name = name;
|
2010-05-20 00:55:31 +03:00
|
|
|
this.scope = scope;
|
2010-02-21 10:28:11 +02:00
|
|
|
this.analyzer = analyzer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The name of the analyzer.
|
|
|
|
*/
|
|
|
|
public String name() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
2010-05-20 00:55:31 +03:00
|
|
|
/**
|
|
|
|
* The scope of the analyzer.
|
|
|
|
*/
|
|
|
|
public AnalyzerScope scope() {
|
|
|
|
return this.scope;
|
|
|
|
}
|
|
|
|
|
2010-02-21 10:28:11 +02:00
|
|
|
/**
|
|
|
|
* The actual analyzer.
|
|
|
|
*/
|
|
|
|
public Analyzer analyzer() {
|
|
|
|
return this.analyzer;
|
|
|
|
}
|
|
|
|
|
2011-04-04 12:54:14 +03:00
|
|
|
@Override public final TokenStream tokenStream(String fieldName, Reader reader) {
|
2010-02-21 10:28:11 +02:00
|
|
|
return analyzer.tokenStream(fieldName, reader);
|
|
|
|
}
|
|
|
|
|
2011-04-04 12:54:14 +03:00
|
|
|
@Override public final TokenStream reusableTokenStream(String fieldName, Reader reader) throws IOException {
|
2010-02-21 10:28:11 +02:00
|
|
|
return analyzer.reusableTokenStream(fieldName, reader);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public int getPositionIncrementGap(String fieldName) {
|
|
|
|
return analyzer.getPositionIncrementGap(fieldName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public int getOffsetGap(Fieldable field) {
|
|
|
|
return analyzer.getOffsetGap(field);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override public void close() {
|
|
|
|
analyzer.close();
|
|
|
|
}
|
2010-06-17 23:23:53 +03:00
|
|
|
|
|
|
|
@Override public String toString() {
|
|
|
|
return "analyzer name[" + name + "], analyzer [" + analyzer + "]";
|
|
|
|
}
|
2010-02-21 10:28:11 +02:00
|
|
|
}
|