IndexModule: Support other index type through string-based getter
As opposed to previously relying on the type enum, which would throw an IllegalArgumentException exception when compared with another configured index type. Include a TODO about this change being only a stable enough fix. A more sustainable (likely larger) solution is to be considered for upstream branches. Change-Id: Ib5f8e4d6e69df5737e42650807d3a5051cb8fe86
This commit is contained in:
@@ -85,12 +85,20 @@ public class IndexModule extends LifecycleModule {
|
||||
|
||||
/** Type of secondary index. */
|
||||
public static IndexType getIndexType(Injector injector) {
|
||||
return getIndexType(injector.getInstance(Key.get(Config.class, GerritServerConfig.class)));
|
||||
Config cfg = injector.getInstance(Key.get(Config.class, GerritServerConfig.class));
|
||||
if (cfg != null) {
|
||||
return cfg.getEnum("index", null, "type", IndexType.LUCENE);
|
||||
}
|
||||
return IndexType.LUCENE;
|
||||
}
|
||||
|
||||
/** Type of secondary index. */
|
||||
public static IndexType getIndexType(@Nullable Config cfg) {
|
||||
return cfg != null ? cfg.getEnum("index", null, "type", IndexType.LUCENE) : IndexType.LUCENE;
|
||||
// TODO: stop relying on this method fostering error-prone string comparisons.
|
||||
public static String getIndexType(@Nullable Config cfg) {
|
||||
if (cfg != null) {
|
||||
return cfg.getString("index", null, "type");
|
||||
}
|
||||
return IndexType.LUCENE.name();
|
||||
}
|
||||
|
||||
private final int threads;
|
||||
|
||||
@@ -742,7 +742,8 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
@Operator
|
||||
public Predicate<ChangeData> extension(String ext) throws QueryParseException {
|
||||
if (args.getSchema().hasField(ChangeField.EXTENSION)) {
|
||||
if (ext.isEmpty() && IndexModule.getIndexType(cfg).equals(IndexType.ELASTICSEARCH)) {
|
||||
if (ext.isEmpty()
|
||||
&& IndexModule.getIndexType(cfg).equalsIgnoreCase(IndexType.ELASTICSEARCH.name())) {
|
||||
return new FileWithNoExtensionInElasticPredicate();
|
||||
}
|
||||
return new FileExtensionPredicate(ext);
|
||||
@@ -784,7 +785,7 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData, ChangeQueryBuil
|
||||
return new RegexDirectoryPredicate(directory);
|
||||
}
|
||||
|
||||
if (IndexModule.getIndexType(cfg).equals(IndexType.ELASTICSEARCH)
|
||||
if (IndexModule.getIndexType(cfg).equalsIgnoreCase(IndexType.ELASTICSEARCH.name())
|
||||
&& (directory.isEmpty() || directory.equals("/"))) {
|
||||
return Predicate.any();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user