Search in sources :

Example 1 with FieldFlag

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++;
                    }
                }
            }
        }
    }
}
Also used : LukeRequest(org.apache.solr.client.solrj.request.LukeRequest) LukeResponse(org.apache.solr.client.solrj.response.LukeResponse) Table(org.teiid.metadata.Table) FieldFlag(org.apache.solr.common.luke.FieldFlag) Column(org.teiid.metadata.Column) FieldInfo(org.apache.solr.client.solrj.response.LukeResponse.FieldInfo)

Aggregations

LukeRequest (org.apache.solr.client.solrj.request.LukeRequest)1 LukeResponse (org.apache.solr.client.solrj.response.LukeResponse)1 FieldInfo (org.apache.solr.client.solrj.response.LukeResponse.FieldInfo)1 FieldFlag (org.apache.solr.common.luke.FieldFlag)1 Column (org.teiid.metadata.Column)1 Table (org.teiid.metadata.Table)1