org.apache.solr.client.solrj.response.schema.SchemaRepresentation Java Examples

The following examples show how to use org.apache.solr.client.solrj.response.schema.SchemaRepresentation. 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: SolrColumnMetadataDao.java    From metron with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
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 #7
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());
    }
  }
}