Search in sources :

Example 1 with FieldTypeDefinition

use of org.apache.solr.client.solrj.request.schema.FieldTypeDefinition 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 FieldTypeDefinition

use of org.apache.solr.client.solrj.request.schema.FieldTypeDefinition 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 3 with FieldTypeDefinition

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

the class SchemaTest method addFieldTypeShouldntBeCalledTwiceWithTheSameName.

@Test
public void addFieldTypeShouldntBeCalledTwiceWithTheSameName() throws Exception {
    Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
    fieldTypeAttributes.put("name", "failureInt");
    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 addFieldTypeFirstResponse = addFieldTypeRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldTypeFirstResponse);
    SchemaResponse.UpdateResponse addFieldTypeSecondResponse = addFieldTypeRequest.process(getSolrClient());
    assertEquals(0, addFieldTypeSecondResponse.getStatus());
    assertNotNull(addFieldTypeSecondResponse.getResponse().get("errors"));
}
Also used : SchemaRequest(org.apache.solr.client.solrj.request.schema.SchemaRequest) FieldTypeDefinition(org.apache.solr.client.solrj.request.schema.FieldTypeDefinition) SchemaResponse(org.apache.solr.client.solrj.response.schema.SchemaResponse) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with FieldTypeDefinition

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

the class FieldProps method getType.

private static AddFieldType getType(String... args) {
    FieldTypeDefinition ftd = new FieldTypeDefinition();
    Map<String, Object> ftas = new LinkedHashMap<>();
    for (int idx = 0; idx < args.length; idx += 2) {
        ftas.put(args[idx], args[idx + 1]);
    }
    ftd.setAttributes(ftas);
    return new SchemaRequest.AddFieldType(ftd);
}
Also used : FieldTypeDefinition(org.apache.solr.client.solrj.request.schema.FieldTypeDefinition) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with FieldTypeDefinition

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

the class SchemaResponse method getFieldTypeDefinitions.

@SuppressWarnings("unchecked")
private static List<FieldTypeDefinition> getFieldTypeDefinitions(Map schemaNamedList) {
    List<FieldTypeDefinition> fieldTypeDefinitions = new LinkedList<>();
    List<NamedList<Object>> fieldsResponse = (List<NamedList<Object>>) schemaNamedList.get("fieldTypes");
    for (NamedList<Object> fieldNamedList : fieldsResponse) {
        FieldTypeDefinition fieldTypeDefinition = createFieldTypeDefinition(fieldNamedList);
        fieldTypeDefinitions.add(fieldTypeDefinition);
    }
    return fieldTypeDefinitions;
}
Also used : FieldTypeDefinition(org.apache.solr.client.solrj.request.schema.FieldTypeDefinition) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) LinkedList(java.util.LinkedList) NamedList(org.apache.solr.common.util.NamedList) LinkedList(java.util.LinkedList)

Aggregations

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