Search in sources :

Example 6 with AnalyzerDefinition

use of org.apache.solr.client.solrj.request.schema.AnalyzerDefinition in project lucene-solr by apache.

the class SchemaTest method addFieldTypeWithAnalyzerClassAccuracy.

@Test
public void addFieldTypeWithAnalyzerClassAccuracy() throws Exception {
    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    String fieldTypeName = "nameText";
    fieldTypeAttributes.put("name", fieldTypeName);
    fieldTypeAttributes.put("class", "solr.TextField");
    FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
    fieldTypeDefinition.setAttributes(fieldTypeAttributes);
    Map<String, Object> analyzerAttributes = new LinkedHashMap<>();
    analyzerAttributes.put("class", "org.apache.lucene.analysis.core.WhitespaceAnalyzer");
    analyzerAttributes.put("luceneMatchVersion", "5.0.0");
    AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
    analyzerDefinition.setAttributes(analyzerAttributes);
    fieldTypeDefinition.setAnalyzer(analyzerDefinition);
    SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition);
    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldTypeResponse);
    SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName);
    SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldTypeResponse);
    FieldTypeRepresentation newFieldTypeRepresentation = newFieldTypeResponse.getFieldType();
    assertThat(fieldTypeName, is(equalTo(newFieldTypeRepresentation.getAttributes().get("name"))));
    assertThat(analyzerAttributes.get("class"), is(equalTo(newFieldTypeRepresentation.getAnalyzer().getAttributes().get("class"))));
    assertThat(analyzerAttributes.get("luceneMatchVersion"), is(equalTo(newFieldTypeRepresentation.getAnalyzer().getAttributes().get("luceneMatchVersion"))));
}
Also used : SchemaRequest(org.apache.solr.client.solrj.request.schema.SchemaRequest) FieldTypeRepresentation(org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation) LinkedHashMap(java.util.LinkedHashMap) FieldTypeDefinition(org.apache.solr.client.solrj.request.schema.FieldTypeDefinition) AnalyzerDefinition(org.apache.solr.client.solrj.request.schema.AnalyzerDefinition) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) Test(org.junit.Test)

Aggregations

AnalyzerDefinition (org.apache.solr.client.solrj.request.schema.AnalyzerDefinition)6 LinkedHashMap (java.util.LinkedHashMap)5 FieldTypeDefinition (org.apache.solr.client.solrj.request.schema.FieldTypeDefinition)4 SchemaRequest (org.apache.solr.client.solrj.request.schema.SchemaRequest)3 FieldTypeRepresentation (org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation)3 SchemaResponse (org.apache.solr.client.solrj.response.schema.SchemaResponse)3 Test (org.junit.Test)3 NamedList (org.apache.solr.common.util.NamedList)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1