コード例 #1
0
ファイル: SchemaTest.java プロジェクト: apache/lucene-solr
 @Test
 public void testGetFieldTypesAccuracy() throws Exception {
   SchemaRequest.FieldTypes fieldTypesRequest = new SchemaRequest.FieldTypes();
   SchemaResponse.FieldTypesResponse fieldTypesResponse =
       fieldTypesRequest.process(getSolrClient());
   assertValidSchemaResponse(fieldTypesResponse);
   List<FieldTypeRepresentation> fieldTypes = fieldTypesResponse.getFieldTypes();
   assertThat(fieldTypes.isEmpty(), is(false));
 }
コード例 #2
0
ファイル: SchemaTest.java プロジェクト: apache/lucene-solr
  @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.WordDelimiterFilterFactory");
    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"))));
  }