Example usage for org.apache.solr.client.solrj.request.schema AnalyzerDefinition setAttributes

List of usage examples for org.apache.solr.client.solrj.request.schema AnalyzerDefinition setAttributes

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.request.schema AnalyzerDefinition setAttributes.

Prototype

public void setAttributes(Map<String, Object> attributes) 

Source Link

Usage

From source file:org.phenotips.vocabulary.translation.AbstractXliffTranslatedSolrVocabularyExtension.java

License:Open Source License

/**
 * Adds (or replaces) a type definition for the {@link #addFields() fields used by this translation}.
 *
 * @throws SolrServerException if communicating with the Solr server failed
 * @throws IOException if communicating with the Solr server failed
 *///from   w w  w  .j  av  a  2  s.  co m
protected void addFieldType() throws SolrServerException, IOException {
    FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();

    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    String name = "text_general_" + getTargetLocale().toString();
    fieldTypeAttributes.put("name", name);
    fieldTypeAttributes.put("class", "solr.TextField");
    fieldTypeDefinition.setAttributes(fieldTypeAttributes);

    AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
    analyzerDefinition.setAttributes(Collections.<String, Object>singletonMap("class", getAnalyzerType()));
    fieldTypeDefinition.setAnalyzer(analyzerDefinition);

    try {
        // The current version (5.5) of SolrJ/EmbeddedSolrServer doesn't support getting schema information,
        // so we do this the ugly way: try to add, check for errors, try to replace
        UpdateResponse response = new SchemaRequest.AddFieldType(fieldTypeDefinition).process(getClient());
        if (response.getResponse().get("errors") != null) {
            response = new SchemaRequest.ReplaceFieldType(fieldTypeDefinition).process(getClient());
        }
        this.logger.debug(response.toString());
    } catch (Exception ex) {
    }
}