예제 #1
0
 @Test
 public void testGetDynamicFieldAccuracy() throws Exception {
   String dynamicFieldName = "*_i";
   SchemaRequest.DynamicField dynamicFieldSchemaRequest =
       new SchemaRequest.DynamicField(dynamicFieldName);
   SchemaResponse.DynamicFieldResponse dynamicFieldResponse =
       dynamicFieldSchemaRequest.process(getSolrClient());
   assertValidSchemaResponse(dynamicFieldResponse);
   Map<String, Object> dynamicFieldAttributes = dynamicFieldResponse.getDynamicField();
   assertThat(dynamicFieldName, is(equalTo(dynamicFieldAttributes.get("name"))));
   assertThat("int", is(equalTo(dynamicFieldAttributes.get("type"))));
 }
예제 #2
0
  @Test
  public void testReplaceDynamicFieldAccuracy() throws Exception {
    // Given
    String fieldName = "*_replace";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", fieldName);
    fieldAttributes.put("type", "string");
    fieldAttributes.put("stored", false);
    fieldAttributes.put("indexed", true);
    SchemaRequest.AddDynamicField addDFieldUpdateSchemaRequest =
        new SchemaRequest.AddDynamicField(fieldAttributes);
    SchemaResponse.UpdateResponse addFieldResponse =
        addDFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);

    // When : update the field definition
    Map<String, Object> replaceFieldAttributes = new LinkedHashMap<>(fieldAttributes);
    replaceFieldAttributes.put("stored", true);
    replaceFieldAttributes.put("indexed", false);
    SchemaRequest.ReplaceDynamicField replaceFieldRequest =
        new SchemaRequest.ReplaceDynamicField(replaceFieldAttributes);
    SchemaResponse.UpdateResponse replaceFieldResponse =
        replaceFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(replaceFieldResponse);

    // Then
    SchemaRequest.DynamicField dynamicFieldSchemaRequest =
        new SchemaRequest.DynamicField(fieldName);
    SchemaResponse.DynamicFieldResponse newFieldResponse =
        dynamicFieldSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldResponse);
    Map<String, Object> newFieldAttributes = newFieldResponse.getDynamicField();
    assertThat(fieldName, is(equalTo(newFieldAttributes.get("name"))));
    assertThat("string", is(equalTo(newFieldAttributes.get("type"))));
    assertThat(true, is(equalTo(newFieldAttributes.get("stored"))));
    assertThat(false, is(equalTo(newFieldAttributes.get("indexed"))));
  }
예제 #3
0
  @Test
  public void testDeleteDynamicFieldAccuracy() throws Exception {
    String dynamicFieldName = "*_del";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", dynamicFieldName);
    fieldAttributes.put("type", "string");
    SchemaRequest.AddDynamicField addFieldUpdateSchemaRequest =
        new SchemaRequest.AddDynamicField(fieldAttributes);
    SchemaResponse.UpdateResponse addDynamicFieldResponse =
        addFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addDynamicFieldResponse);

    SchemaRequest.DynamicField dynamicFieldSchemaRequest =
        new SchemaRequest.DynamicField(dynamicFieldName);
    SchemaResponse.DynamicFieldResponse initialDFieldResponse =
        dynamicFieldSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(initialDFieldResponse);
    Map<String, Object> fieldAttributesResponse = initialDFieldResponse.getDynamicField();
    assertThat(dynamicFieldName, is(equalTo(fieldAttributesResponse.get("name"))));

    SchemaRequest.DeleteDynamicField deleteFieldRequest =
        new SchemaRequest.DeleteDynamicField(dynamicFieldName);
    SchemaResponse.UpdateResponse deleteDynamicFieldResponse =
        deleteFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(deleteDynamicFieldResponse);

    try {
      dynamicFieldSchemaRequest.process(getSolrClient());
      fail(
          String.format(
              Locale.ROOT,
              "after removal, the dynamic field %s shouldn't be anymore available over Schema API",
              dynamicFieldName));
    } catch (SolrException e) {
      // success
    }
  }
예제 #4
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"))));
  }