Search in sources :

Example 1 with FieldTypeRepresentation

use of org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation in project lucene-solr by apache.

the class SchemaTest method addFieldTypeWithSimilarityAccuracy.

@Test
public void addFieldTypeWithSimilarityAccuracy() throws Exception {
    FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    String fieldTypeName = "fullClassNames";
    fieldTypeAttributes.put("name", fieldTypeName);
    fieldTypeAttributes.put("class", "org.apache.solr.schema.TextField");
    fieldTypeDefinition.setAttributes(fieldTypeAttributes);
    AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
    Map<String, Object> charFilterAttributes = new LinkedHashMap<>();
    charFilterAttributes.put("class", "solr.PatternReplaceCharFilterFactory");
    charFilterAttributes.put("replacement", "$1$1");
    charFilterAttributes.put("pattern", "([a-zA-Z])\\\\1+");
    analyzerDefinition.setCharFilters(Collections.singletonList(charFilterAttributes));
    Map<String, Object> tokenizerAttributes = new LinkedHashMap<>();
    tokenizerAttributes.put("class", "solr.WhitespaceTokenizerFactory");
    analyzerDefinition.setTokenizer(tokenizerAttributes);
    fieldTypeDefinition.setAnalyzer(analyzerDefinition);
    Map<String, Object> similarityAttributes = new LinkedHashMap<>();
    similarityAttributes.put("class", "org.apache.lucene.misc.SweetSpotSimilarity");
    fieldTypeDefinition.setSimilarity(similarityAttributes);
    SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition);
    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldTypeResponse);
    // similarity is not shown by default for the fieldType
    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(similarityAttributes.get("class"), is(equalTo(newFieldTypeRepresentation.getSimilarity().get("class"))));
}
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)

Example 2 with FieldTypeRepresentation

use of org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation in project lucene-solr by apache.

the class SchemaTest method testGetFieldTypeAccuracy.

@Test
public void testGetFieldTypeAccuracy() throws Exception {
    String fieldType = "string";
    SchemaRequest.FieldType fieldTypeSchemaRequest = new SchemaRequest.FieldType(fieldType);
    SchemaResponse.FieldTypeResponse fieldTypeResponse = fieldTypeSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(fieldTypeResponse);
    FieldTypeRepresentation fieldTypeDefinition = fieldTypeResponse.getFieldType();
    assertThat(fieldType, is(equalTo(fieldTypeDefinition.getAttributes().get("name"))));
    assertThat("solr.StrField", is(equalTo(fieldTypeDefinition.getAttributes().get("class"))));
}
Also used : SchemaRequest(org.apache.solr.client.solrj.request.schema.SchemaRequest) FieldTypeRepresentation(org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) Test(org.junit.Test)

Example 3 with FieldTypeRepresentation

use of org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation in project lucene-solr by apache.

the class SchemaTest method testReplaceFieldTypeAccuracy.

@Test
public void testReplaceFieldTypeAccuracy() throws Exception {
    // Given
    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    String fieldTypeName = "replaceInt";
    fieldTypeAttributes.put("name", fieldTypeName);
    fieldTypeAttributes.put("class", "solr.TrieIntField");
    fieldTypeAttributes.put("precisionStep", 0);
    fieldTypeAttributes.put("omitNorms", true);
    fieldTypeAttributes.put("positionIncrementGap", 0);
    FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
    fieldTypeDefinition.setAttributes(fieldTypeAttributes);
    SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition);
    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldTypeResponse);
    // When : update the field definition
    fieldTypeAttributes.put("precisionStep", 1);
    fieldTypeAttributes.put("omitNorms", false);
    FieldTypeDefinition replaceFieldTypeDefinition = new FieldTypeDefinition();
    replaceFieldTypeDefinition.setAttributes(fieldTypeAttributes);
    SchemaRequest.ReplaceFieldType replaceFieldTypeRequest = new SchemaRequest.ReplaceFieldType(replaceFieldTypeDefinition);
    SchemaResponse.UpdateResponse replaceFieldTypeResponse = replaceFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(replaceFieldTypeResponse);
    // Then
    SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName);
    SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldTypeResponse);
    FieldTypeRepresentation replacedFieldTypeRepresentation = newFieldTypeResponse.getFieldType();
    Map<String, Object> replacedFieldTypeAttributes = replacedFieldTypeRepresentation.getAttributes();
    assertThat(fieldTypeName, is(equalTo(replacedFieldTypeAttributes.get("name"))));
    assertThat("solr.TrieIntField", is(equalTo(replacedFieldTypeAttributes.get("class"))));
    assertThat(false, is(equalTo(replacedFieldTypeAttributes.get("omitNorms"))));
    assertThat("1", is(equalTo(replacedFieldTypeAttributes.get("precisionStep"))));
    assertThat("0", is(equalTo(replacedFieldTypeAttributes.get("positionIncrementGap"))));
}
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) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) Test(org.junit.Test)

Example 4 with FieldTypeRepresentation

use of org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation in project lucene-solr by apache.

the class SchemaTest method testMultipleUpdateRequestAccuracy.

@Test
public void testMultipleUpdateRequestAccuracy() throws Exception {
    String fieldTypeName = "accuracyTextField";
    SchemaRequest.AddFieldType addFieldTypeRequest = createFieldTypeRequest(fieldTypeName);
    String field1Name = "accuracyField1";
    String field2Name = "accuracyField2";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", field1Name);
    fieldAttributes.put("type", fieldTypeName);
    fieldAttributes.put("stored", true);
    fieldAttributes.put("indexed", true);
    SchemaRequest.AddField addFieldName1Request = new SchemaRequest.AddField(fieldAttributes);
    fieldAttributes.put("name", field2Name);
    SchemaRequest.AddField addFieldName2Request = new SchemaRequest.AddField(fieldAttributes);
    List<SchemaRequest.Update> list = new ArrayList<>(3);
    list.add(addFieldTypeRequest);
    list.add(addFieldName1Request);
    list.add(addFieldName2Request);
    SchemaRequest.MultiUpdate multiUpdateRequest = new SchemaRequest.MultiUpdate(list);
    SchemaResponse.UpdateResponse multipleUpdatesResponse = multiUpdateRequest.process(getSolrClient());
    assertValidSchemaResponse(multipleUpdatesResponse);
    SchemaRequest.FieldType fieldTypeSchemaRequest = new SchemaRequest.FieldType(fieldTypeName);
    SchemaResponse.FieldTypeResponse fieldTypeResponse = fieldTypeSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(fieldTypeResponse);
    FieldTypeRepresentation fieldTypeRepresentation = fieldTypeResponse.getFieldType();
    assertThat(fieldTypeName, is(equalTo(fieldTypeRepresentation.getAttributes().get("name"))));
    SchemaRequest.Field field1SchemaRequest = new SchemaRequest.Field(field1Name);
    SchemaResponse.FieldResponse field1Response = field1SchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(field1Response);
    Map<String, ?> field1Attributes = field1Response.getField();
    assertThat(field1Name, is(equalTo(field1Attributes.get("name"))));
    assertThat(fieldTypeName, is(equalTo(field1Attributes.get("type"))));
    assertThat(true, is(equalTo(field1Attributes.get("stored"))));
    assertThat(true, is(equalTo(field1Attributes.get("indexed"))));
    SchemaRequest.Field field2SchemaRequest = new SchemaRequest.Field(field1Name);
    SchemaResponse.FieldResponse field2Response = field2SchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(field2Response);
    Map<String, ?> field2Attributes = field2Response.getField();
    assertThat(field1Name, is(equalTo(field2Attributes.get("name"))));
    assertThat(fieldTypeName, is(equalTo(field2Attributes.get("type"))));
    assertThat(true, is(equalTo(field2Attributes.get("stored"))));
    assertThat(true, is(equalTo(field2Attributes.get("indexed"))));
}
Also used : SchemaRequest(org.apache.solr.client.solrj.request.schema.SchemaRequest) ArrayList(java.util.ArrayList) FieldTypeRepresentation(org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation) LinkedHashMap(java.util.LinkedHashMap) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) Test(org.junit.Test)

Example 5 with FieldTypeRepresentation

use of org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation in project lucene-solr by apache.

the class SchemaTest method testAddFieldTypeAccuracy.

@Test
public void testAddFieldTypeAccuracy() throws Exception {
    SchemaRequest.FieldTypes fieldTypesRequest = new SchemaRequest.FieldTypes();
    SchemaResponse.FieldTypesResponse initialFieldTypesResponse = fieldTypesRequest.process(getSolrClient());
    assertValidSchemaResponse(initialFieldTypesResponse);
    List<FieldTypeRepresentation> initialFieldTypes = initialFieldTypesResponse.getFieldTypes();
    FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    String fieldTypeName = "accuracyTextField";
    fieldTypeAttributes.put("name", fieldTypeName);
    fieldTypeAttributes.put("class", "solr.TextField");
    fieldTypeAttributes.put("positionIncrementGap", "100");
    fieldTypeDefinition.setAttributes(fieldTypeAttributes);
    AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
    Map<String, Object> charFilterAttributes = new LinkedHashMap<>();
    charFilterAttributes.put("class", "solr.PatternReplaceCharFilterFactory");
    charFilterAttributes.put("replacement", "$1$1");
    charFilterAttributes.put("pattern", "([a-zA-Z])\\\\1+");
    analyzerDefinition.setCharFilters(Collections.singletonList(charFilterAttributes));
    Map<String, Object> tokenizerAttributes = new LinkedHashMap<>();
    tokenizerAttributes.put("class", "solr.WhitespaceTokenizerFactory");
    analyzerDefinition.setTokenizer(tokenizerAttributes);
    Map<String, Object> filterAttributes = new LinkedHashMap<>();
    filterAttributes.put("class", "solr.WordDelimiterGraphFilterFactory");
    filterAttributes.put("preserveOriginal", "0");
    analyzerDefinition.setFilters(Collections.singletonList(filterAttributes));
    fieldTypeDefinition.setAnalyzer(analyzerDefinition);
    SchemaRequest.AddFieldType addFieldTypeRequest = new SchemaRequest.AddFieldType(fieldTypeDefinition);
    SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldTypeResponse);
    SchemaResponse.FieldTypesResponse currentFieldTypesResponse = fieldTypesRequest.process(getSolrClient());
    assertEquals(0, currentFieldTypesResponse.getStatus());
    List<FieldTypeRepresentation> currentFieldTypes = currentFieldTypesResponse.getFieldTypes();
    assertEquals(initialFieldTypes.size() + 1, currentFieldTypes.size());
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    String fieldName = "accuracyField";
    fieldAttributes.put("name", fieldName);
    fieldAttributes.put("type", fieldTypeName);
    SchemaRequest.AddField addFieldRequest = new SchemaRequest.AddField(fieldAttributes);
    SchemaResponse.UpdateResponse addFieldResponse = addFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);
    Map<String, Object> dynamicFieldAttributes = new LinkedHashMap<>();
    String dynamicFieldName = "*_accuracy";
    dynamicFieldAttributes.put("name", dynamicFieldName);
    dynamicFieldAttributes.put("type", fieldTypeName);
    SchemaRequest.AddDynamicField addDynamicFieldRequest = new SchemaRequest.AddDynamicField(dynamicFieldAttributes);
    SchemaResponse.UpdateResponse addDynamicFieldResponse = addDynamicFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(addDynamicFieldResponse);
    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("solr.TextField", is(equalTo(newFieldTypeRepresentation.getAttributes().get("class"))));
    assertThat(analyzerDefinition.getTokenizer().get("class"), is(equalTo(newFieldTypeRepresentation.getAnalyzer().getTokenizer().get("class"))));
}
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

SchemaRequest (org.apache.solr.client.solrj.request.schema.SchemaRequest)7 FieldTypeRepresentation (org.apache.solr.client.solrj.response.schema.FieldTypeRepresentation)7 SchemaResponse (org.apache.solr.client.solrj.response.schema.SchemaResponse)7 Test (org.junit.Test)7 LinkedHashMap (java.util.LinkedHashMap)6 FieldTypeDefinition (org.apache.solr.client.solrj.request.schema.FieldTypeDefinition)5 AnalyzerDefinition (org.apache.solr.client.solrj.request.schema.AnalyzerDefinition)3 ArrayList (java.util.ArrayList)1 SolrClient (org.apache.solr.client.solrj.SolrClient)1 SolrException (org.apache.solr.common.SolrException)1