mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-25 00:39:12 +01:00
Add support for enum fields during indexing (#1792)
* Add support for enum fields during indexing * Add missing value extractor for enums
This commit is contained in:
@@ -73,6 +73,8 @@ class IndexableFields {
|
||||
return new BooleanFieldFactory(indexType);
|
||||
} else if (isInstant(fieldType)) {
|
||||
return new InstantFieldFactory(indexType);
|
||||
} else if (fieldType.isEnum()) {
|
||||
return new EnumFieldFactory(indexType);
|
||||
} else {
|
||||
throw new UnsupportedTypeOfFieldException(fieldType, field.getName());
|
||||
}
|
||||
@@ -169,4 +171,23 @@ class IndexableFields {
|
||||
}
|
||||
}
|
||||
|
||||
private static class EnumFieldFactory implements IndexableFieldFactory {
|
||||
|
||||
private final Indexed.Type type;
|
||||
|
||||
public EnumFieldFactory(Indexed.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<IndexableField> create(String name, Object value) {
|
||||
String stringValue = value.toString();
|
||||
if (type.isSearchable()) {
|
||||
return singleton(new StringField(name, stringValue, Store.YES));
|
||||
} else {
|
||||
return singleton(new StoredField(name, stringValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,11 +45,18 @@ final class ValueExtractors {
|
||||
return booleanExtractor(name);
|
||||
} else if (TypeCheck.isInstant(type)) {
|
||||
return instantExtractor(name);
|
||||
} else if (type.isEnum()) {
|
||||
return enumExtractor(name, type);
|
||||
} else {
|
||||
throw new UnsupportedTypeOfFieldException(type, name);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static ValueExtractor enumExtractor(String name, Class type) {
|
||||
return doc -> Enum.valueOf(type, doc.get(name));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static ValueExtractor stringExtractor(String name) {
|
||||
return doc -> doc.get(name);
|
||||
|
||||
Reference in New Issue
Block a user