Skip to content

Commit f6a1131

Browse files
committed
make settings prefix simpler and not bail when not prefixed with org.elasticsearch, allow to provide settings prefix for analyzer provider
1 parent bbe9988 commit f6a1131

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/ImmutableSettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ private ImmutableSettings(Map<String, String> settings, ClassLoader classLoader)
7676
}
7777

7878
@Override public Settings getComponentSettings(Class component) {
79-
return getComponentSettings("org.elasticsearch", component);
79+
if (component.getName().startsWith("org.elasticsearch")) {
80+
return getComponentSettings("org.elasticsearch", component);
81+
}
82+
// not starting with org.elasticsearch, just remove the first package part (probably org/net/com)
83+
return getComponentSettings(component.getName().substring(0, component.getName().indexOf('.')), component);
8084
}
8185

8286
@Override public Settings getComponentSettings(String prefix, Class component) {

modules/elasticsearch/src/main/java/org/elasticsearch/common/settings/Settings.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public interface Settings {
4141

4242
/**
4343
* Component settings for a specific component. Returns all the settings for the given class, where the
44-
* FQN of the class is used, without the <tt>org.elasticsearch<tt> prefix.
44+
* FQN of the class is used, without the <tt>org.elasticsearch<tt> prefix. If there is no <tt>org.elasticsearch</tt>
45+
* prefix, then the prefix used is the first part of the package name (<tt>org</tt> / <tt>com</tt> / ...)
4546
*/
4647
Settings getComponentSettings(Class component);
4748

modules/elasticsearch/src/main/java/org/elasticsearch/index/AbstractIndexComponent.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public abstract class AbstractIndexComponent implements IndexComponent {
4040

4141
protected final Settings componentSettings;
4242

43+
/**
44+
* Constructs a new index component, with the index name and its settings.
45+
*
46+
* @param index The index name
47+
* @param indexSettings The index settings
48+
*/
4349
protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings) {
4450
this.index = index;
4551
this.indexSettings = indexSettings;
@@ -48,6 +54,13 @@ protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSetti
4854
this.logger = Loggers.getLogger(getClass(), indexSettings, index);
4955
}
5056

57+
/**
58+
* Constructs a new index component, with the index name and its settings, as well as settings prefix.
59+
*
60+
* @param index The index name
61+
* @param indexSettings The index settings
62+
* @param prefixSettings A settings prefix (like "com.mycompany") to simplify extracting the component settings
63+
*/
5164
protected AbstractIndexComponent(Index index, @IndexSettings Settings indexSettings, String prefixSettings) {
5265
this.index = index;
5366
this.indexSettings = indexSettings;

modules/elasticsearch/src/main/java/org/elasticsearch/index/analysis/AbstractIndexAnalyzerProvider.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,31 @@ public abstract class AbstractIndexAnalyzerProvider<T extends Analyzer> extends
3232

3333
private final String name;
3434

35+
/**
36+
* Constructs a new analyzer component, with the index name and its settings and the analyzer name.
37+
*
38+
* @param index The index name
39+
* @param indexSettings The index settings
40+
* @param name The analyzer name
41+
*/
3542
public AbstractIndexAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, String name) {
3643
super(index, indexSettings);
3744
this.name = name;
3845
}
3946

47+
/**
48+
* Constructs a new analyzer component, with the index name and its settings and the analyzer name.
49+
*
50+
* @param index The index name
51+
* @param indexSettings The index settings
52+
* @param prefixSettings A settings prefix (like "com.mycompany") to simplify extracting the component settings
53+
* @param name The analyzer name
54+
*/
55+
public AbstractIndexAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, String prefixSettings, String name) {
56+
super(index, indexSettings, prefixSettings);
57+
this.name = name;
58+
}
59+
4060
@Override public String name() {
4161
return this.name;
4262
}

0 commit comments

Comments
 (0)