Skip to content

Commit 913f9bd

Browse files
committed
Can not upgrade stempel plugin from elasticsearch 0.90.5
Due to fix [3790](#3790) in core, upgrading an analyzer provided as a plugin now fails. See #4936 for details. Issue is in elasticsearch core code but can be fixed in plugins by overloading `PreBuiltTokenFilterFactoryFactory` and `PreBuiltAnalyzerProviderFactory`. Closes #18. (cherry picked from commit fc68d81)
1 parent 4d6d7a0 commit 913f9bd

File tree

3 files changed

+91
-10
lines changed

3 files changed

+91
-10
lines changed

src/main/java/org/elasticsearch/indices/analysis/pl/PolishIndicesAnalysis.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,18 @@
1919

2020
package org.elasticsearch.indices.analysis.pl;
2121

22+
import org.apache.lucene.analysis.TokenStream;
2223
import org.apache.lucene.analysis.pl.PolishAnalyzer;
24+
import org.apache.lucene.analysis.stempel.StempelFilter;
25+
import org.apache.lucene.analysis.stempel.StempelStemmer;
26+
import org.egothor.stemmer.Trie;
2327
import org.elasticsearch.common.component.AbstractComponent;
2428
import org.elasticsearch.common.inject.Inject;
2529
import org.elasticsearch.common.lucene.Lucene;
2630
import org.elasticsearch.common.settings.Settings;
2731
import org.elasticsearch.index.analysis.AnalyzerScope;
28-
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory;
29-
import org.elasticsearch.index.analysis.PreBuiltTokenFilterFactoryFactory;
30-
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
3132
import org.elasticsearch.index.analysis.TokenFilterFactory;
32-
33-
import org.apache.lucene.analysis.TokenStream;
34-
import org.apache.lucene.analysis.stempel.StempelFilter;
35-
import org.apache.lucene.analysis.stempel.StempelStemmer;
36-
import org.egothor.stemmer.Trie;
33+
import org.elasticsearch.indices.analysis.IndicesAnalysisService;
3734

3835
import java.io.IOException;
3936

@@ -46,9 +43,9 @@ public class PolishIndicesAnalysis extends AbstractComponent {
4643
@Inject
4744
public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) {
4845
super(settings);
49-
indicesAnalysisService.analyzerProviderFactories().put("polish", new PreBuiltAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
46+
indicesAnalysisService.analyzerProviderFactories().put("polish", new StempelAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION)));
5047

51-
indicesAnalysisService.tokenFilterFactories().put("polish_stem", new PreBuiltTokenFilterFactoryFactory(new TokenFilterFactory() {
48+
indicesAnalysisService.tokenFilterFactories().put("polish_stem", new StempelTokenFilterFactoryFactory(new TokenFilterFactory() {
5249
@Override public String name() {
5350
return "polish_stem";
5451
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to Elasticsearch (the "Author") under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Author licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.indices.analysis.pl;
21+
22+
import org.apache.lucene.analysis.Analyzer;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.index.analysis.AnalyzerProvider;
25+
import org.elasticsearch.index.analysis.AnalyzerScope;
26+
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProvider;
27+
import org.elasticsearch.index.analysis.PreBuiltAnalyzerProviderFactory;
28+
29+
public class StempelAnalyzerProviderFactory extends PreBuiltAnalyzerProviderFactory {
30+
31+
private final PreBuiltAnalyzerProvider analyzerProvider;
32+
33+
public StempelAnalyzerProviderFactory(String name, AnalyzerScope scope, Analyzer analyzer) {
34+
super(name, scope, analyzer);
35+
analyzerProvider = new PreBuiltAnalyzerProvider(name, scope, analyzer);
36+
}
37+
38+
@Override
39+
public AnalyzerProvider create(String name, Settings settings) {
40+
return analyzerProvider;
41+
}
42+
43+
public Analyzer analyzer() {
44+
return analyzerProvider.get();
45+
}
46+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to Elasticsearch (the "Author") under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. Author licenses this
6+
* file to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.indices.analysis.pl;
21+
22+
import org.elasticsearch.common.settings.Settings;
23+
import org.elasticsearch.index.analysis.PreBuiltTokenFilterFactoryFactory;
24+
import org.elasticsearch.index.analysis.TokenFilterFactory;
25+
26+
public class StempelTokenFilterFactoryFactory extends PreBuiltTokenFilterFactoryFactory {
27+
private final TokenFilterFactory tokenFilterFactory;
28+
29+
public StempelTokenFilterFactoryFactory(TokenFilterFactory tokenFilterFactory) {
30+
super(tokenFilterFactory);
31+
this.tokenFilterFactory = tokenFilterFactory;
32+
}
33+
34+
@Override
35+
public TokenFilterFactory create(String name, Settings settings) {
36+
return tokenFilterFactory;
37+
}
38+
}

0 commit comments

Comments
 (0)