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; }
@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 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; }
@SuppressWarnings("unchecked") private static FieldTypeRepresentation createFieldTypeRepresentation(NamedList<Object> fieldTypeNamedList) { FieldTypeRepresentation fieldTypeRepresentation = new FieldTypeRepresentation(); fillFieldTypeDefinition(fieldTypeRepresentation, fieldTypeNamedList); List<String> fields = (List<String>) fieldTypeNamedList.get("fields"); if (fields != null) fieldTypeRepresentation.setFields(fields); List<String> dynamicFields = (List<String>) fieldTypeNamedList.get("dynamicFields"); if (dynamicFields != null) fieldTypeRepresentation.setDynamicFields(dynamicFields); return fieldTypeRepresentation; }
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; }
@Override protected SchemaResponse.SchemaNameResponse createResponse(SolrClient client) { return new SchemaResponse.SchemaNameResponse(); } }
@Override protected SchemaResponse.SchemaVersionResponse createResponse(SolrClient client) { return new SchemaResponse.SchemaVersionResponse(); } }
@Override protected SchemaResponse.CopyFieldsResponse createResponse(SolrClient client) { return new SchemaResponse.CopyFieldsResponse(); } }
@Override protected SchemaResponse.FieldTypesResponse createResponse(SolrClient client) { return new SchemaResponse.FieldTypesResponse(); } }
@Override protected SchemaResponse.GlobalSimilarityResponse createResponse(SolrClient client) { return new SchemaResponse.GlobalSimilarityResponse(); } }
@Override protected SchemaResponse.FieldsResponse createResponse(SolrClient client) { return new SchemaResponse.FieldsResponse(); } }
@Override protected SchemaResponse.DynamicFieldResponse createResponse(SolrClient client) { return new SchemaResponse.DynamicFieldResponse(); } }
@Override protected SchemaResponse.FieldTypeResponse createResponse(SolrClient client) { return new SchemaResponse.FieldTypeResponse(); } }
@Override protected SchemaResponse.UniqueKeyResponse createResponse(SolrClient client) { return new SchemaResponse.UniqueKeyResponse(); } }
@Override protected SchemaResponse.UpdateResponse createResponse(SolrClient client) { return new SchemaResponse.UpdateResponse(); } }
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; }
@Override protected SchemaResponse.SchemaNameResponse createResponse(SolrClient client) { return new SchemaResponse.SchemaNameResponse(); } }
@Override protected SchemaResponse.SchemaVersionResponse createResponse(SolrClient client) { return new SchemaResponse.SchemaVersionResponse(); } }
@Override protected SchemaResponse.CopyFieldsResponse createResponse(SolrClient client) { return new SchemaResponse.CopyFieldsResponse(); } }