Java Code Examples for org.apache.solr.client.solrj.response.schema.SchemaResponse#getSchemaRepresentation()

The following examples show how to use org.apache.solr.client.solrj.response.schema.SchemaResponse#getSchemaRepresentation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrSchemaChecker.java    From vind with Apache License 2.0 5 votes vote down vote up
public static void checkSchema(InputStream solrSchemaPath, SchemaResponse response) throws IOException, SchemaValidationException {
    // read the local schema.xml
    final Document local;
    try {
        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        final DocumentBuilder builder = factory.newDocumentBuilder();

        local = builder.parse(solrSchemaPath);
    } catch (ParserConfigurationException | SAXException e) {
        log.error("Error checking schema.xml: {}", e.getMessage(), e);
        throw new IOException(e);
    }

    final SchemaRepresentation remote = response.getSchemaRepresentation();
    final Element schema = local.getDocumentElement();
    // check the field-types
    final NodeList fieldTypes = schema.getElementsByTagName("fieldType");
    final Set<String> fieldTypeNames = remote.getFieldTypes().stream()
            .map(FieldTypeDefinition::getAttributes)
            .map(m -> m.get("name"))
            .filter(Objects::nonNull)
            .map(String::valueOf)
            .collect(Collectors.toSet());
    for (int i = 0; i < fieldTypes.getLength(); i++) {
        final Node fieldType = fieldTypes.item(i);
        final String fieldTypeName = fieldType.getAttributes().getNamedItem("name").getNodeValue();
        if (! fieldTypeNames.contains(fieldTypeName)) {
            throw new SchemaValidationException(String.format("Missing <fieldType name='%s' />", fieldTypeName));
        }
    }
// TODO: check local -> remote.

}
 
Example 2
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchemaRequestAccuracy() throws Exception {
  SchemaRequest schemaRequest = new SchemaRequest();
  SchemaResponse schemaResponse = schemaRequest.process(getSolrClient());
  assertValidSchemaResponse(schemaResponse);
  SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
  assertNotNull(schemaRepresentation);
  assertEquals("test", schemaRepresentation.getName());
  assertEquals(1.6, schemaRepresentation.getVersion(), 0.001f);
  assertEquals("id", schemaRepresentation.getUniqueKey());
  assertFalse(schemaRepresentation.getFields().isEmpty());
  assertFalse(schemaRepresentation.getDynamicFields().isEmpty());
  assertFalse(schemaRepresentation.getFieldTypes().isEmpty());
  assertFalse(schemaRepresentation.getCopyFields().isEmpty());
}
 
Example 3
Source File: SolrTarget07.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void getRequiredFieldNames() throws SolrServerException, IOException {
  SchemaRequest schemaRequest = new SchemaRequest();
  SchemaResponse schemaResponse = schemaRequest.process(solrClient);
  SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
  List<Map<String, Object>> fields = schemaRepresentation.getFields();
  for (Map<String, Object> field : fields) {
    if (field.containsKey(REQUIRED) && field.get(REQUIRED).equals(true)) {
      requiredFieldNamesMap.add(field.get(NAME).toString());
    }
  }
}
 
Example 4
Source File: SolrTarget07.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void getOptionalFieldNames() throws SolrServerException, IOException {
  SchemaRequest schemaRequest = new SchemaRequest();
  SchemaResponse schemaResponse = schemaRequest.process(solrClient);
  SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
  List<Map<String, Object>> fields = schemaRepresentation.getFields();
  for (Map<String, Object> field : fields) {
    if (!field.containsKey(REQUIRED) || field.get(REQUIRED).equals(false)) {
      requiredFieldNamesMap.add(field.get(NAME).toString());
    }
  }
}
 
Example 5
Source File: SolrTarget06.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void getRequiredFieldNames() throws SolrServerException, IOException {
  SchemaRequest schemaRequest = new SchemaRequest();
  SchemaResponse schemaResponse = schemaRequest.process(solrClient);
  SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
  List<Map<String, Object>> fields = schemaRepresentation.getFields();
  for (Map<String, Object> field : fields) {
    if (field.containsKey(REQUIRED) && field.get(REQUIRED).equals(true)) {
      requiredFieldNamesMap.add(field.get(NAME).toString());
    }
  }
}
 
Example 6
Source File: SolrTarget06.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void getOptionalFieldNames() throws SolrServerException, IOException {
  SchemaRequest schemaRequest = new SchemaRequest();
  SchemaResponse schemaResponse = schemaRequest.process(solrClient);
  SchemaRepresentation schemaRepresentation = schemaResponse.getSchemaRepresentation();
  List<Map<String, Object>> fields = schemaRepresentation.getFields();
  for (Map<String, Object> field : fields) {
    if (!field.containsKey(REQUIRED) || field.get(REQUIRED).equals(false)) {
      optionalFieldNamesMap.add(field.get(NAME).toString());
    }
  }
}