Defining a new analyzer provider forces pakcage name of the provider to begin with org.elasticsearch

My elasticsearch properties define my own type:
index.analysis.analyzer.my_analyzer.type=org.me.index.analysis.MyWonderfulAnalyzerProvider
When I run it I get a
org.elasticsearch.common.settings.SettingsException:
Caused by: org.elasticsearch.common.settings.SettingsException:
Component [org.me.index.analysis.MyWonderfulAnalyzerProvider] does not
start with prefix [org.elasticsearch]
at
org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:
91)
at
org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:
85)
at
org.elasticsearch.index.AbstractIndexComponent.(AbstractIndexComponent.java:
46)
at
org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider.(AbstractIndexAnalyzerProvider.java:
36)
...
ImmutableSettings.java:
@Override public Settings getComponentSettings(Class component) {
return getComponentSettings("org.elasticsearch", component);
}

@Override public Settings getComponentSettings(String prefix,

Class component) {
String type = component.getName();
if (!type.startsWith(prefix)) {
throw new SettingsException("Component [" + type + "] does
not start with prefix [" + prefix + "]");
}
String settingPrefix = type.substring(prefix.length() + 1); //
1 for the '.'
settingPrefix = settingPrefix.substring(0,
settingPrefix.length() - component.getSimpleName().length()); //
remove the simple class name (keep the dot)
return getByPrefix(settingPrefix);
}
If I change my provider's package to begin with org.elasticsearch then
everything works fine. However this kind of restriction is suspicious
in nature. Why should I be required to define this class in this
package and not in my own packages?

You're right, its annoying. The idea here is that the class is used to
derive the component settings for that specific component by removing from
the FQN of the class name the org.elasticsearch prefix, and removing at the
end the simple class name. Then, its simpler to get the component settings
for it.

I have just pushed a fix to simplify extension, if the prefix is not
org.elasticsearch, then just the first part of the package will be used as
the prefix (org / com / net). Also, I have added another constructor
to AbstractIndexAnalyzerProvider that allows you to pass your own settings
prefix (like org.me).

-shay.banon

On Wed, Dec 29, 2010 at 4:55 PM, ezb erezmazor@gmail.com wrote:

My elasticsearch properties define my own type:

index.analysis.analyzer.my_analyzer.type=org.me.index.analysis.MyWonderfulAnalyzerProvider
When I run it I get a
org.elasticsearch.common.settings.SettingsException:
Caused by: org.elasticsearch.common.settings.SettingsException:
Component [org.me.index.analysis.MyWonderfulAnalyzerProvider] does not
start with prefix [org.elasticsearch]
at

org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:
91)
at

org.elasticsearch.common.settings.ImmutableSettings.getComponentSettings(ImmutableSettings.java:
85)
at

org.elasticsearch.index.AbstractIndexComponent.(AbstractIndexComponent.java:
46)
at

org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider.(AbstractIndexAnalyzerProvider.java:
36)
...
ImmutableSettings.java:
@Override public Settings getComponentSettings(Class component) {
return getComponentSettings("org.elasticsearch", component);
}

@Override public Settings getComponentSettings(String prefix,
Class component) {
String type = component.getName();
if (!type.startsWith(prefix)) {
throw new SettingsException("Component [" + type + "] does
not start with prefix [" + prefix + "]");
}
String settingPrefix = type.substring(prefix.length() + 1); //
1 for the '.'
settingPrefix = settingPrefix.substring(0,
settingPrefix.length() - component.getSimpleName().length()); //
remove the simple class name (keep the dot)
return getByPrefix(settingPrefix);
}
If I change my provider's package to begin with org.elasticsearch then
everything works fine. However this kind of restriction is suspicious
in nature. Why should I be required to define this class in this
package and not in my own packages?