use of org.apache.solr.common.luke.FieldFlag in project teiid by teiid.
the class SolrMetadataProcessor method getConnectorMetadata.
public void getConnectorMetadata(SolrConnection conn, MetadataFactory metadataFactory) throws TranslatorException {
int count = 0;
LukeRequest request = new LukeRequest();
request.setShowSchema(true);
LukeResponse response = conn.metadata(request);
Map<String, FieldInfo> fields = response.getFieldInfo();
Table table = metadataFactory.addTable(conn.getCoreName());
table.setSupportsUpdate(true);
for (String name : fields.keySet()) {
FieldInfo field = fields.get(name);
EnumSet<FieldFlag> flags = field.getFlags();
if ((!name.startsWith("_") && !name.endsWith("_")) || name.startsWith("*") || name.endsWith("*")) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
if (flags.contains(FieldFlag.INDEXED) && flags.contains(FieldFlag.STORED)) {
Column column = null;
// array type
if (flags.contains(FieldFlag.MULTI_VALUED)) {
// $NON-NLS-1$
column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()) + "[]", table);
} else {
column = metadataFactory.addColumn(field.getName(), resolveType(field.getType()), table);
}
column.setUpdatable(true);
column.setSearchType(SearchType.Searchable);
// create primary key; and unique keys
if (field.getDistinct() > 0 || field.getName().equals("id")) {
// $NON-NLS-1$
if (table.getPrimaryKey() == null) {
// $NON-NLS-1$
metadataFactory.addPrimaryKey("PK0", Arrays.asList(field.getName()), table);
} else {
// $NON-NLS-1$
metadataFactory.addIndex("UI" + count, true, Arrays.asList(field.getName()), table);
count++;
}
}
}
}
}
}
Aggregations