Exemple #1
0
 @Test
 public void testGetDynamicFieldsAccuracy() throws Exception {
   SchemaRequest.DynamicFields dynamicFieldsSchemaRequest = new SchemaRequest.DynamicFields();
   SchemaResponse.DynamicFieldsResponse dynamicFieldsResponse =
       dynamicFieldsSchemaRequest.process(getSolrClient());
   assertValidSchemaResponse(dynamicFieldsResponse);
   List<Map<String, Object>> fields = dynamicFieldsResponse.getDynamicFields();
   assertThat(fields.isEmpty(), is(false));
 }
Exemple #2
0
  @Test
  public void testAddDynamicFieldAccuracy() throws Exception {
    SchemaRequest.DynamicFields dynamicFieldsSchemaRequest = new SchemaRequest.DynamicFields();
    SchemaResponse.DynamicFieldsResponse initialDFieldsResponse =
        dynamicFieldsSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(initialDFieldsResponse);
    List<Map<String, Object>> initialDFields = initialDFieldsResponse.getDynamicFields();

    String dFieldName = "*_acc";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", dFieldName);
    fieldAttributes.put("type", "string");
    fieldAttributes.put("stored", false);
    fieldAttributes.put("indexed", true);
    // Dynamic fields cannot be required or have a default value
    SchemaRequest.AddDynamicField addFieldUpdateSchemaRequest =
        new SchemaRequest.AddDynamicField(fieldAttributes);
    SchemaResponse.UpdateResponse addFieldResponse =
        addFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);

    SchemaResponse.DynamicFieldsResponse currentDFieldsResponse =
        dynamicFieldsSchemaRequest.process(getSolrClient());
    assertEquals(0, currentDFieldsResponse.getStatus());
    List<Map<String, Object>> currentFields = currentDFieldsResponse.getDynamicFields();
    assertEquals(initialDFields.size() + 1, currentFields.size());

    SchemaRequest.DynamicField dFieldRequest = new SchemaRequest.DynamicField(dFieldName);
    SchemaResponse.DynamicFieldResponse newFieldResponse = dFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldResponse);
    Map<String, Object> newFieldAttributes = newFieldResponse.getDynamicField();
    assertThat(dFieldName, is(equalTo(newFieldAttributes.get("name"))));
    assertThat("string", is(equalTo(newFieldAttributes.get("type"))));
    assertThat(false, is(equalTo(newFieldAttributes.get("stored"))));
    assertThat(true, is(equalTo(newFieldAttributes.get("indexed"))));
  }