add a test for custom type class name in token filter factory

This commit is contained in:
kimchy 2011-01-21 02:07:02 +02:00
parent 9801ddeb0d
commit 3907c8c680
4 changed files with 67 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import org.elasticsearch.common.lucene.analysis.HTMLStripCharFilter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexNameModule;
import org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory;
import org.elasticsearch.index.analysis.phonetic.PhoneticTokenFilterFactory;
import org.elasticsearch.index.settings.IndexSettingsModule;
import org.testng.annotations.Test;
@ -84,10 +85,17 @@ public class AnalysisModuleTests {
analyzer = analysisService.analyzer("alias1").analyzer();
assertThat(analyzer, instanceOf(StandardAnalyzer.class));
// check phonetic
analyzer = analysisService.analyzer("custom3").analyzer();
assertThat(analyzer, instanceOf(CustomAnalyzer.class));
CustomAnalyzer custom3 = (CustomAnalyzer) analyzer;
PhoneticTokenFilterFactory metaphone = (PhoneticTokenFilterFactory) custom3.tokenFilters()[0];
assertThat(custom3.tokenFilters()[0], instanceOf(PhoneticTokenFilterFactory.class));
// check custom class name (my)
analyzer = analysisService.analyzer("custom4").analyzer();
assertThat(analyzer, instanceOf(CustomAnalyzer.class));
CustomAnalyzer custom4 = (CustomAnalyzer) analyzer;
assertThat(custom4.tokenFilters()[0], instanceOf(MyFilterTokenFilterFactory.class));
// verify Czech stemmer
analyzer = analysisService.analyzer("czechAnalyzerWithStemmer").analyzer();

View File

@ -0,0 +1,46 @@
/*
* 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.
*/
/*
* Created by IntelliJ IDEA.
* User: kimchy
* Date: 1/21/11
* Time: 2:02 AM
*/
package org.elasticsearch.index.analysis.filter1;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.analysis.AbstractTokenFilterFactory;
import org.elasticsearch.index.settings.IndexSettings;
public class MyFilterTokenFilterFactory extends AbstractTokenFilterFactory {
@Inject public MyFilterTokenFilterFactory(Index index, @IndexSettings Settings indexSettings, String name) {
super(index, indexSettings, name);
}
@Override public TokenStream create(TokenStream tokenStream) {
return new StopFilter(true, tokenStream, StopAnalyzer.ENGLISH_STOP_WORDS_SET);
}
}

View File

@ -25,6 +25,9 @@
"metaphone" : {
"type" : "phonetic",
"encoder" : "metaphone"
},
"my" : {
"type" : "org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory"
}
},
"analyzer" : {
@ -46,6 +49,10 @@
"tokenizer" : "standard",
"filter" : ["metaphone"]
},
"custom4" : {
"tokenizer" : "standard",
"filter" : ["my"]
},
"czechAnalyzerWithStemmer" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "stop", "czech_stem"]

View File

@ -18,6 +18,8 @@ index :
metaphone :
type : phonetic
encoder : metaphone
my :
type : org.elasticsearch.index.analysis.filter1.MyFilterTokenFilterFactory
analyzer :
standard :
alias: alias1,alias2
@ -33,6 +35,9 @@ index :
custom3 :
tokenizer : standard
filter : [metaphone]
custom4 :
tokenizer : standard
filter : [my]
czechAnalyzerWithStemmer :
tokenizer : standard
filter : [standard, lowercase, stop, czech_stem]