Skip to content

Stable Plugin API module and analysis interfaces#88775

Merged
pgomulka merged 19 commits intoelastic:mainfrom
pgomulka:stable_plugin_api
Aug 30, 2022
Merged

Stable Plugin API module and analysis interfaces#88775
pgomulka merged 19 commits intoelastic:mainfrom
pgomulka:stable_plugin_api

Conversation

@pgomulka
Copy link
Copy Markdown
Contributor

@pgomulka pgomulka commented Jul 25, 2022

This commit adds stable analysis plugin API with analysis components interfaces and annotations.
It does not contain any usage of it yet. Separate changes to introduce example plugins or refactoring to existing ones will follow later.

It contains two gradle modules. One plugin-api with two annotations Nameable and NamedComponent, which can be reused for plugins other than analysis.
And second analysis-plugin-api which contains analysis components (TokenFilterFactory, CharFilterFactory etc)

NamedComponent - used by plugin developer - indicates that a Nameable component will be registered under a given name.
Nameable - for analysis plugins it is only used by the stable analysis api designers (ES) - indicates that component have a name and should be declared with NamedComponent

additional tasks that will follow: #88980

This commit adds stable plugin API module and introduces
analysis components interfaces and annotations.
Stable plugin API is influenced by org.elasticserach.index.analysis
classes. It allows to remove the server dependency from plugins.
@pgomulka pgomulka added the :Core/Infra/Plugins Plugin API and infrastructure label Jul 25, 2022
@mark-vieira mark-vieira added v8.5.0 and removed v8.4.0 labels Jul 27, 2022
@pgomulka pgomulka mentioned this pull request Aug 1, 2022
25 tasks
@pgomulka pgomulka requested review from romseygeek and removed request for romseygeek August 1, 2022 11:47
@pgomulka pgomulka marked this pull request as ready for review August 1, 2022 14:12
@pgomulka pgomulka requested a review from romseygeek August 1, 2022 14:13
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Hi @pgomulka, I've created a changelog YAML for you.

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Aug 1, 2022
Copy link
Copy Markdown
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

The API looks sensible to me. Is the plan to add this to a branch and then start migrating our internal components to use these factories?

* Returns a lucene org.apache.lucene.analysis.Analyzer instance
*/
T create();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we'll need getAnalysisMode on here as well.

@pgomulka
Copy link
Copy Markdown
Contributor Author

pgomulka commented Aug 2, 2022

Is the plan to add this to a branch and then start migrating our internal components to use these factories?

@romseygeek we want merge this API and infrastructure to main branch. This will be followed by example plugins implementing this API and possibly some of analysis plugins we have in our repo (we did a PoC with nori)

@pgomulka pgomulka requested a review from romseygeek August 8, 2022 10:02
@pgomulka pgomulka requested a review from ChrisHegarty August 8, 2022 10:02
dependencies {
api "org.apache.lucene:lucene-core:${versions.lucene}"
api "org.apache.lucene:lucene-analysis-common:${versions.lucene}"
api "org.apache.lucene:lucene-analysis-common:${versions.lucene}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

duplicate api dependency?


module org.elasticsearch.analysis.plugin.api {
requires org.apache.lucene.core;
requires org.elasticsearch.plugin.api;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I noticed that there is no requires on lucene analysis common (which is in the Gradle dependencies)? Maybe it can be removed from the Gradle api dependency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, I am not sure why I needed this in the PoC branch. We can always add it back when needed

}
};

private String readableName;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this field can be final, right?

Reader create(Reader reader);

/**
* Normalize a tokenStream for use in multi-term queries
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we please end all sentences with a period/stop.

@Target({ ElementType.TYPE })
public @interface NamedComponent {
/**
* A name used for registration and lookup
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trivially, can we change this to the definitive article, "A name" -> "The name"

* <ul>
* <li> The root package is org.elasticsearch.plugin</li>
* <li> Specialised API jars have their name following the root package.
* i.e. org.elasticsearch.analysis
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should be org.elasticsearch.plugin.analysis, right?

* i.e. org.elasticsearch.analysis
* </li>
* <li> Interfaces and annotations used by plugin developers are in `api` package
* i.e org.elasticsearch.analysis.api or org.elasticsearch.api
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

o.e.plugin.analysis.api

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

somehow I missed those comments.. I will fix this in #89772

/**
* An analysis component used to create Analyzers.
*/
public interface AnalyzerFactory<T extends org.apache.lucene.analysis.Analyzer> extends Nameable {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need the generic parameter here? The other factories are just returning a base type, which I think should be enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

agree, I don't think we need a generic here

Copy link
Copy Markdown
Contributor

@romseygeek romseygeek left a comment

Choose a reason for hiding this comment

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

LGTM

@pgomulka pgomulka merged commit bc4c678 into elastic:main Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Plugins Plugin API and infrastructure >feature Team:Core/Infra Meta label for core/infra team v8.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants