-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When an analysis plugins provides default index settings using `PreBuiltAnalyzerProviderFactory`, `PreBuiltTokenFilterFactoryFactory` or `PreBuiltTokenizerFactoryFactory` it fails when upgrading it with elasticsearch superior or equal to 0.90.5. Related issue: #4936 Fix is needed in core. But, in the meantime, analysis plugins developers can fix that issue by overloading default prebuilt factories. For example: ```java public class StempelAnalyzerProviderFactory extends PreBuiltAnalyzerProviderFactory { private final PreBuiltAnalyzerProvider analyzerProvider; public StempelAnalyzerProviderFactory(String name, AnalyzerScope scope, Analyzer analyzer) { super(name, scope, analyzer); analyzerProvider = new PreBuiltAnalyzerProvider(name, scope, analyzer); } @OverRide public AnalyzerProvider create(String name, Settings settings) { return analyzerProvider; } public Analyzer analyzer() { return analyzerProvider.get(); } } ``` And instead of: ```java @Inject public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) { super(settings); indicesAnalysisService.analyzerProviderFactories().put("polish", new PreBuiltAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION))); } ``` do ```java @Inject public PolishIndicesAnalysis(Settings settings, IndicesAnalysisService indicesAnalysisService) { super(settings); indicesAnalysisService.analyzerProviderFactories().put("polish", new StempelAnalyzerProviderFactory("polish", AnalyzerScope.INDICES, new PolishAnalyzer(Lucene.ANALYZER_VERSION))); } ``` Closes #5030
- Loading branch information
Showing
18 changed files
with
478 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisBinderProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.index.analysis.AnalysisModule; | ||
|
||
/** | ||
*/ | ||
public class DummyAnalysisBinderProcessor extends AnalysisModule.AnalysisBinderProcessor { | ||
|
||
@Override | ||
public void processAnalyzers(AnalyzersBindings analyzersBindings) { | ||
analyzersBindings.processAnalyzer("dummy", DummyAnalyzerProvider.class); | ||
} | ||
|
||
@Override | ||
public void processTokenFilters(TokenFiltersBindings tokenFiltersBindings) { | ||
tokenFiltersBindings.processTokenFilter("dummy_token_filter", DummyTokenFilterFactory.class); | ||
} | ||
|
||
@Override | ||
public void processTokenizers(TokenizersBindings tokenizersBindings) { | ||
tokenizersBindings.processTokenizer("dummy_tokenizer", DummyTokenizerFactory.class); | ||
} | ||
|
||
@Override | ||
public void processCharFilters(CharFiltersBindings charFiltersBindings) { | ||
charFiltersBindings.processCharFilter("dummy_char_filter", DummyCharFilterFactory.class); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/org/elasticsearch/indices/analysis/DummyAnalysisPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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 com.google.common.collect.ImmutableList; | ||
import org.elasticsearch.common.inject.Module; | ||
import org.elasticsearch.index.analysis.AnalysisModule; | ||
import org.elasticsearch.plugins.AbstractPlugin; | ||
|
||
import java.util.Collection; | ||
|
||
public class DummyAnalysisPlugin extends AbstractPlugin { | ||
/** | ||
* The name of the plugin. | ||
*/ | ||
@Override | ||
public String name() { | ||
return "analysis-dummy"; | ||
} | ||
|
||
/** | ||
* The description of the plugin. | ||
*/ | ||
@Override | ||
public String description() { | ||
return "Analysis Dummy Plugin"; | ||
} | ||
|
||
@Override | ||
public Collection<Class<? extends Module>> modules() { | ||
return ImmutableList.<Class<? extends Module>>of(DummyIndicesAnalysisModule.class); | ||
} | ||
|
||
public void onModule(AnalysisModule module) { | ||
module.addProcessor(new DummyAnalysisBinderProcessor()); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/org/elasticsearch/indices/analysis/DummyAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.apache.lucene.analysis.util.StopwordAnalyzerBase; | ||
import org.apache.lucene.util.Version; | ||
|
||
import java.io.Reader; | ||
|
||
public class DummyAnalyzer extends StopwordAnalyzerBase { | ||
|
||
protected DummyAnalyzer(Version version) { | ||
super(version); | ||
} | ||
|
||
@Override | ||
protected TokenStreamComponents createComponents(String fieldName, Reader reader) { | ||
return null; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/org/elasticsearch/indices/analysis/DummyAnalyzerProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.lucene.Lucene; | ||
import org.elasticsearch.index.analysis.AnalyzerProvider; | ||
import org.elasticsearch.index.analysis.AnalyzerScope; | ||
|
||
public class DummyAnalyzerProvider implements AnalyzerProvider<DummyAnalyzer> { | ||
@Override | ||
public String name() { | ||
return "dummy"; | ||
} | ||
|
||
@Override | ||
public AnalyzerScope scope() { | ||
return AnalyzerScope.INDICES; | ||
} | ||
|
||
@Override | ||
public DummyAnalyzer get() { | ||
return new DummyAnalyzer(Lucene.ANALYZER_VERSION); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/org/elasticsearch/indices/analysis/DummyCharFilterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch 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.index.analysis.CharFilterFactory; | ||
|
||
import java.io.Reader; | ||
|
||
public class DummyCharFilterFactory implements CharFilterFactory { | ||
@Override | ||
public String name() { | ||
return "dummy_char_filter"; | ||
} | ||
|
||
@Override | ||
public Reader create(Reader reader) { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.