I need to create a schema which will containt few enums. I'm trying to do that using SolrJ. I've found this link DefininganEnumFieldinschema but I couldn't find any examples using Schema API or SolrJ.
Here is my enum:
public enum Attributes {
SPONSORED("sponsored"),
TOP_RATED("top-rated"),
GENERIC("generic"),
PROMOTION("promotion"),
QUICK_ORDER("quick-order");
private String value;
Attributes(String value) {
this.value = value;
}
@Override
@JsonValue
public String toString() {
return String.valueOf(value);
}
@JsonCreator
public static Attributes fromValue(String text) {
for (Attributes b : Attributes.values()) {
if (String.valueOf(b.value).equals(text)) {
return b;
}
}
return null;
}
}
And I want to add a field to my schema using SolrJ:
Map<String, Object> fieldAttributes = new LinkedHashMap<>();
fieldAttributes.put("name", "address.**attributes**");
fieldAttributes.put("type", "**attributesEnum**");
fieldAttributes.put("stored", true);
SchemaRequest.AddField addFieldRequest = new SchemaRequest.AddField(fieldAttributes);
addFieldRequest.process(client);