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"))));
}
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"))));
}
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"));
}
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);
}
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;
}
Aggregations