From 3401c21ca2e65f737d9339f265f6f2129c100fe1 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 28 Feb 2014 23:47:50 +0100 Subject: [PATCH] Can not upgrade kuromoji plugin from elasticsearch 0.90.5 Due to fix [3790](https://github.com/elasticsearch/elasticsearch/issues/3790) in core, upgrading an analyzer provided as a plugin now fails. See https://github.com/elasticsearch/elasticsearch/issues/5030 for details. Issue is in elasticsearch core code but can be fixed in plugins by overloading `PreBuiltAnalyzerProviderFactory`, `PreBuiltTokenFilterFactoryFactory`, `PreBuiltTokenizerFactoryFactory` or `PreBuiltCharFilterFactoryFactory ` when used. Closes #21 --- .../analysis/KuromojiIndicesAnalysis.java | 12 +++--- .../KurumojiCharFilterFactoryFactory.java | 38 +++++++++++++++++++ .../KurumojiTokenFilterFactoryFactory.java | 38 +++++++++++++++++++ .../KurumojiTokenizerFactoryFactory.java | 38 +++++++++++++++++++ 4 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 src/main/java/org/elasticsearch/indices/analysis/KurumojiCharFilterFactoryFactory.java create mode 100644 src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenFilterFactoryFactory.java create mode 100644 src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenizerFactoryFactory.java diff --git a/src/main/java/org/elasticsearch/indices/analysis/KuromojiIndicesAnalysis.java b/src/main/java/org/elasticsearch/indices/analysis/KuromojiIndicesAnalysis.java index 9264acd..7074fca 100644 --- a/src/main/java/org/elasticsearch/indices/analysis/KuromojiIndicesAnalysis.java +++ b/src/main/java/org/elasticsearch/indices/analysis/KuromojiIndicesAnalysis.java @@ -43,7 +43,7 @@ public KuromojiIndicesAnalysis(Settings settings, super(settings); indicesAnalysisService.charFilterFactories().put("kuromoji_iteration_mark", - new PreBuiltCharFilterFactoryFactory(new CharFilterFactory() { + new KurumojiCharFilterFactoryFactory(new CharFilterFactory() { @Override public String name() { return "kuromoji_iteration_mark"; @@ -58,7 +58,7 @@ public Reader create(Reader reader) { })); indicesAnalysisService.tokenizerFactories().put("kuromoji_tokenizer", - new PreBuiltTokenizerFactoryFactory(new TokenizerFactory() { + new KurumojiTokenizerFactoryFactory(new TokenizerFactory() { @Override public String name() { return "kuromoji_tokenizer"; @@ -72,7 +72,7 @@ public Tokenizer create(Reader reader) { })); indicesAnalysisService.tokenFilterFactories().put("kuromoji_baseform", - new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() { + new KurumojiTokenFilterFactoryFactory(new TokenFilterFactory() { @Override public String name() { return "kuromoji_baseform"; @@ -86,7 +86,7 @@ public TokenStream create(TokenStream tokenStream) { indicesAnalysisService.tokenFilterFactories().put( "kuromoji_part_of_speech", - new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() { + new KurumojiTokenFilterFactoryFactory(new TokenFilterFactory() { @Override public String name() { return "kuromoji_part_of_speech"; @@ -102,7 +102,7 @@ public TokenStream create(TokenStream tokenStream) { indicesAnalysisService.tokenFilterFactories().put( "kuromoji_readingform", - new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() { + new KurumojiTokenFilterFactoryFactory(new TokenFilterFactory() { @Override public String name() { return "kuromoji_readingform"; @@ -115,7 +115,7 @@ public TokenStream create(TokenStream tokenStream) { })); indicesAnalysisService.tokenFilterFactories().put("kuromoji_stemmer", - new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() { + new KurumojiTokenFilterFactoryFactory(new TokenFilterFactory() { @Override public String name() { return "kuromoji_stemmer"; diff --git a/src/main/java/org/elasticsearch/indices/analysis/KurumojiCharFilterFactoryFactory.java b/src/main/java/org/elasticsearch/indices/analysis/KurumojiCharFilterFactoryFactory.java new file mode 100644 index 0000000..3737d81 --- /dev/null +++ b/src/main/java/org/elasticsearch/indices/analysis/KurumojiCharFilterFactoryFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch (the "Author") under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Author 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.indices.analysis; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.analysis.CharFilterFactory; +import org.elasticsearch.index.analysis.PreBuiltCharFilterFactoryFactory; + +public class KurumojiCharFilterFactoryFactory extends PreBuiltCharFilterFactoryFactory { + private final CharFilterFactory charFilterFactory; + + public KurumojiCharFilterFactoryFactory(CharFilterFactory charFilterFactory) { + super(charFilterFactory); + this.charFilterFactory = charFilterFactory; + } + + @Override + public CharFilterFactory create(String name, Settings settings) { + return charFilterFactory; + } +} diff --git a/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenFilterFactoryFactory.java b/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenFilterFactoryFactory.java new file mode 100644 index 0000000..2efaa91 --- /dev/null +++ b/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenFilterFactoryFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch (the "Author") under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Author 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.indices.analysis; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.analysis.PreBuiltTokenFilterFactoryFactory; +import org.elasticsearch.index.analysis.TokenFilterFactory; + +public class KurumojiTokenFilterFactoryFactory extends PreBuiltTokenFilterFactoryFactory { + private final TokenFilterFactory tokenFilterFactory; + + public KurumojiTokenFilterFactoryFactory(TokenFilterFactory tokenFilterFactory) { + super(tokenFilterFactory); + this.tokenFilterFactory = tokenFilterFactory; + } + + @Override + public TokenFilterFactory create(String name, Settings settings) { + return tokenFilterFactory; + } +} diff --git a/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenizerFactoryFactory.java b/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenizerFactoryFactory.java new file mode 100644 index 0000000..6e55257 --- /dev/null +++ b/src/main/java/org/elasticsearch/indices/analysis/KurumojiTokenizerFactoryFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch (the "Author") under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Author 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.indices.analysis; + +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.index.analysis.PreBuiltTokenizerFactoryFactory; +import org.elasticsearch.index.analysis.TokenizerFactory; + +public class KurumojiTokenizerFactoryFactory extends PreBuiltTokenizerFactoryFactory { + private final TokenizerFactory tokenizerFactory; + + public KurumojiTokenizerFactoryFactory(TokenizerFactory tokenizerFactory) { + super(tokenizerFactory); + this.tokenizerFactory = tokenizerFactory; + } + + @Override + public TokenizerFactory create(String name, Settings settings) { + return tokenizerFactory; + } +}