Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PreBuiltAnalyzerProviderFactory plugable via AnalysisPlugin and #31095

Conversation

martijnvg
Copy link
Member

move finger_print, pattern and standard_html_strip analyzers
to analysis-common module. (both AnalysisProvider and PreBuiltAnalyzerProvider)

Changed PreBuiltAnalyzerProviderFactory to extend from PreConfiguredAnalysisComponent and
changed to make sure that predefined analyzers are always instantiated with the current
ES version and if an instance is requested for a different version then delegate to PreBuiltCache.
This is similar to the behaviour that exists today in AnalysisRegistry.PreBuiltAnalysis and
PreBuiltAnalyzerProviderFactory.

Relates to #23658

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few minor things but I'm marking this "request changes" because I'm confused about how closing works with PreBuiltAnalyzers.

Map<String, PreConfiguredTokenFilter> preConfiguredTokenFilters,
Map<String, PreConfiguredTokenizer> preConfiguredTokenizers) {
Map<String, PreBuiltAnalyzerProviderFactory> analyzerProviderFactories = new HashMap<>();
Map<String, PreConfiguredCharFilter> preConfiguredCharFilters,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old indentation was better here.

return new PreBuiltAnalyzerProvider(name, AnalyzerScope.INDICES, analyzer);
}
public PreBuiltAnalyzerProviderFactory(String name, Function<Version, Analyzer> create) {
this(name, PreBuiltCacheFactory.CachingStrategy.LUCENE, create);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be nice to remove this second ctor so we're explicit every time.

}

public Analyzer analyzer() {
return analyzerProvider.get();
private static class PreBuiltAnalyzersDelegateCache implements PreBuiltCacheFactory.PreBuiltCache<AnalyzerProvider<?>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is worth some javadoc and comments to explain why we do it. It makes sense but things like an empty put method will confuse future me when I read this class in six months.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be super nice to explain that we only need this because of PreBuiltAnalyzers.

throws IOException {
return create(name, settings);
public void close() throws IOException {
IOUtils.close((Closeable) cache.values().stream().map(AnalyzerProvider::get));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me like this will hit a NullPointerException.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you use it with an instance of PreBuiltAnalyzers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch. I will fix that.

@@ -162,6 +161,16 @@ public AnalysisRegistry getAnalysisRegistry() {
return tokenFilters;
}

static Map<String, PreBuiltAnalyzerProviderFactory> setPreBuiltAnalyzerProviderFactory(List<AnalysisPlugin> plugins) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupPreBuiltAnalyzerProviderFactories?

@martijnvg
Copy link
Member Author

Thanks @nik9000 for reviewing. I've updated this PR.

move `finger_print`, `pattern` and `standard_html_strip` analyzers
to analysis-common module. (both AnalysisProvider and PreBuiltAnalyzerProvider)

Changed PreBuiltAnalyzerProviderFactory to extend from PreConfiguredAnalysisComponent and
changed to make sure that predefined analyzers are always instantiated with the current
ES version and if an instance is requested for a different version then delegate to PreBuiltCache.
This is similar to the behaviour that exists today in AnalysisRegistry.PreBuiltAnalysis and
PreBuiltAnalyzerProviderFactory.

Relates to elastic#23658
@martijnvg martijnvg force-pushed the make_PreBuiltAnalyzerProviderFactory_pluggable branch from 506bdcc to 97f7539 Compare June 5, 2018 18:06
@martijnvg martijnvg merged commit 735d0e6 into elastic:master Jun 6, 2018
martijnvg added a commit that referenced this pull request Jun 6, 2018
move `finger_print`, `pattern` and `standard_html_strip` analyzers
to analysis-common module. (both AnalysisProvider and PreBuiltAnalyzerProvider)

Changed PreBuiltAnalyzerProviderFactory to extend from PreConfiguredAnalysisComponent and
changed to make sure that predefined analyzers are always instantiated with the current
ES version and if an instance is requested for a different version then delegate to PreBuiltCache.
This is similar to the behaviour that exists today in AnalysisRegistry.PreBuiltAnalysis and
PreBuiltAnalyzerProviderFactory. (#31095)

Relates to #23658
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants