@Override public void buildSchema() throws IOException { SolrClient solrClient = null; try { solrClient = new CloudSolrClient(solrConfig.getZkHostString()); SchemaRequest schemaRequest = new SchemaRequest(); logger.debug("Downloading schema for collection: {}", collection); SchemaResponse schemaResponse = schemaRequest.process(solrClient, collection); logger.debug("SchemaResponse Schema: {}", schemaResponse); SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation(); schema.setName(schemaRepresentation.getName()); schema.setVersion(Float.toString(schemaRepresentation.getVersion())); schema.setUniqueKey(schemaRepresentation.getUniqueKey()); schema.setFieldTypes(getFieldTypes(schemaRepresentation)); schema.setFields(getFields(schemaRepresentation.getFields())); schema.setDynamicFields(getFields(schemaRepresentation.getDynamicFields())); schema.setCopyFields(getCopyFields(schemaRepresentation)); } catch (SolrServerException e) { logger.error("Error while getting schema for collection: {}", collection, e); throw new IOException("Error while getting schema for collection :" + collection, e); } finally { if (solrClient != null) { solrClient.close(); } } }
private List<CopyField> getCopyFields(SchemaRepresentation schemaRepresentation) { List<CopyField> copyFields = new LinkedList<>(); for (Map<String, Object> map : schemaRepresentation.getCopyFields()) { CopyField cp = new CopyField(); cp.setSource((String) map.get("source")); cp.setDest((String) map.get("dest")); copyFields.add(cp); } return copyFields; }
private List<FieldType> getFieldTypes(SchemaRepresentation schemaRepresentation) { List<FieldType> fieldTypes = new LinkedList<>(); for (FieldTypeDefinition fd : schemaRepresentation.getFieldTypes()) { FieldType ft = new FieldType(); ft.setName((String) fd.getAttributes().get("name")); ft.setClazz((String) fd.getAttributes().get("class")); Object multiValued = fd.getAttributes().get("multiValued"); if (multiValued != null) { ft.setMultiValued((Boolean) multiValued); } fieldTypes.add(ft); } return fieldTypes; }
private static SchemaRepresentation createSchemaConfiguration(Map schemaObj) { SchemaRepresentation schemaRepresentation = new SchemaRepresentation(); schemaRepresentation.setName(getSchemaName(schemaObj)); schemaRepresentation.setVersion(getSchemaVersion(schemaObj)); schemaRepresentation.setUniqueKey(getSchemaUniqueKey(schemaObj)); schemaRepresentation.setSimilarity(getSimilarity(schemaObj)); schemaRepresentation.setFields(getFields(schemaObj)); schemaRepresentation.setDynamicFields(getDynamicFields(schemaObj)); schemaRepresentation.setFieldTypes(getFieldTypeDefinitions(schemaObj)); schemaRepresentation.setCopyFields(getCopyFields(schemaObj)); return schemaRepresentation; }
@Override public SchemaDefinition readSchema() { SchemaRepresentation representation = template .execute(solrClient -> new SchemaRequest().process(solrClient, collection).getSchemaRepresentation()); SchemaDefinition sd = new SchemaDefinition(collection); for (Map<String, Object> fieldValueMap : representation.getFields()) { sd.addFieldDefinition(FieldDefinition.fromMap(fieldValueMap)); } for (Map<String, Object> fieldValueMap : representation.getCopyFields()) { CopyFieldDefinition cf = CopyFieldDefinition.fromMap(fieldValueMap); sd.addCopyField(cf); if (sd.getFieldDefinition(cf.getSource()) != null) { sd.getFieldDefinition(cf.getSource()).setCopyFields(cf.getDestination()); } } return sd; }
protected List<Map<String, Object>> getIndexFields(String index) throws IOException, SolrServerException { List<Map<String, Object>> indexFields = new ArrayList<>(); // Get all the fields in use, including dynamic fields LukeRequest lukeRequest = new LukeRequest(); LukeResponse lukeResponse = lukeRequest.process(client, index); for (Entry<String, LukeResponse.FieldInfo> field : lukeResponse.getFieldInfo().entrySet()) { Map<String, Object> fieldData = new HashMap<>(); fieldData.put("name", field.getValue().getName()); fieldData.put("type", field.getValue().getType()); indexFields.add(fieldData); } // Get all the schema fields SchemaRepresentation schemaRepresentation = new SchemaRequest().process(client, index) .getSchemaRepresentation(); indexFields.addAll(schemaRepresentation.getFields()); return indexFields; }
private static SchemaRepresentation createSchemaConfiguration(NamedList<Object> schemaNamedList) { SchemaRepresentation schemaRepresentation = new SchemaRepresentation(); schemaRepresentation.setName(getSchemaName(schemaNamedList)); schemaRepresentation.setVersion(getSchemaVersion(schemaNamedList)); schemaRepresentation.setUniqueKey(getSchemaUniqueKey(schemaNamedList)); schemaRepresentation.setDefaultSearchField(getDefaultSearchField(schemaNamedList)); schemaRepresentation.setDefaultOperator(getDefaultOperator(schemaNamedList)); schemaRepresentation.setSimilarity(getSimilarity(schemaNamedList)); schemaRepresentation.setFields(getFields(schemaNamedList)); schemaRepresentation.setDynamicFields(getDynamicFields(schemaNamedList)); schemaRepresentation.setFieldTypes(getFieldTypeDefinitions(schemaNamedList)); schemaRepresentation.setCopyFields(getCopyFields(schemaNamedList)); return schemaRepresentation; }
final Set<String> fieldTypeNames = remote.getFieldTypes().stream() .map(FieldTypeDefinition::getAttributes) .map(m -> m.get("name"))