예제 #1
0
  @Test
  public void testDeleteFieldAccuracy() throws Exception {
    String fieldName = "fieldToBeDeleted";
    Map<String, Object> fieldAttributesRequest = new LinkedHashMap<>();
    fieldAttributesRequest.put("name", fieldName);
    fieldAttributesRequest.put("type", "string");
    SchemaRequest.AddField addFieldUpdateSchemaRequest =
        new SchemaRequest.AddField(fieldAttributesRequest);
    SchemaResponse.UpdateResponse addFieldResponse =
        addFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);

    SchemaRequest.Field fieldSchemaRequest = new SchemaRequest.Field(fieldName);
    SchemaResponse.FieldResponse initialFieldResponse = fieldSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(initialFieldResponse);
    Map<String, Object> fieldAttributesResponse = initialFieldResponse.getField();
    assertThat(fieldName, is(equalTo(fieldAttributesResponse.get("name"))));

    SchemaRequest.DeleteField deleteFieldRequest = new SchemaRequest.DeleteField(fieldName);
    SchemaResponse.UpdateResponse deleteFieldResponse = deleteFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(deleteFieldResponse);

    try {
      fieldSchemaRequest.process(getSolrClient());
      fail(
          String.format(
              Locale.ROOT,
              "after removal, the field %s shouldn't be anymore available over Schema API",
              fieldName));
    } catch (SolrException e) {
      // success
    }
  }
예제 #2
0
 @Test
 public void testGetFieldAccuracy() throws Exception {
   String fieldName = "signatureField";
   SchemaRequest.Field fieldSchemaRequest = new SchemaRequest.Field(fieldName);
   SchemaResponse.FieldResponse fieldResponse = fieldSchemaRequest.process(getSolrClient());
   assertValidSchemaResponse(fieldResponse);
   Map<String, Object> fieldAttributes = fieldResponse.getField();
   assertThat(fieldName, is(equalTo(fieldAttributes.get("name"))));
   assertThat("string", is(equalTo(fieldAttributes.get("type"))));
 }
예제 #3
0
  @Test
  public void testMultipleUpdateRequestAccuracy() throws Exception {
    String fieldTypeName = "accuracyTextField";
    SchemaRequest.AddFieldType addFieldTypeRequest = createFieldTypeRequest(fieldTypeName);

    String field1Name = "accuracyField1";
    String field2Name = "accuracyField2";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", field1Name);
    fieldAttributes.put("type", fieldTypeName);
    fieldAttributes.put("stored", true);
    fieldAttributes.put("indexed", true);
    SchemaRequest.AddField addFieldName1Request = new SchemaRequest.AddField(fieldAttributes);
    fieldAttributes.put("name", field2Name);
    SchemaRequest.AddField addFieldName2Request = new SchemaRequest.AddField(fieldAttributes);

    List<SchemaRequest.Update> list = new ArrayList<>(3);
    list.add(addFieldTypeRequest);
    list.add(addFieldName1Request);
    list.add(addFieldName2Request);
    SchemaRequest.MultiUpdate multiUpdateRequest = new SchemaRequest.MultiUpdate(list);
    SchemaResponse.UpdateResponse multipleUpdatesResponse =
        multiUpdateRequest.process(getSolrClient());
    assertValidSchemaResponse(multipleUpdatesResponse);

    SchemaRequest.FieldType fieldTypeSchemaRequest = new SchemaRequest.FieldType(fieldTypeName);
    SchemaResponse.FieldTypeResponse fieldTypeResponse =
        fieldTypeSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(fieldTypeResponse);
    FieldTypeRepresentation fieldTypeRepresentation = fieldTypeResponse.getFieldType();
    assertThat(fieldTypeName, is(equalTo(fieldTypeRepresentation.getAttributes().get("name"))));

    SchemaRequest.Field field1SchemaRequest = new SchemaRequest.Field(field1Name);
    SchemaResponse.FieldResponse field1Response = field1SchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(field1Response);
    Map<String, ?> field1Attributes = field1Response.getField();
    assertThat(field1Name, is(equalTo(field1Attributes.get("name"))));
    assertThat(fieldTypeName, is(equalTo(field1Attributes.get("type"))));
    assertThat(true, is(equalTo(field1Attributes.get("stored"))));
    assertThat(true, is(equalTo(field1Attributes.get("indexed"))));

    SchemaRequest.Field field2SchemaRequest = new SchemaRequest.Field(field1Name);
    SchemaResponse.FieldResponse field2Response = field2SchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(field2Response);
    Map<String, ?> field2Attributes = field2Response.getField();
    assertThat(field1Name, is(equalTo(field2Attributes.get("name"))));
    assertThat(fieldTypeName, is(equalTo(field2Attributes.get("type"))));
    assertThat(true, is(equalTo(field2Attributes.get("stored"))));
    assertThat(true, is(equalTo(field2Attributes.get("indexed"))));
  }
예제 #4
0
  @Test
  public void testAddFieldAccuracy() throws Exception {
    SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields();
    SchemaResponse.FieldsResponse initialFieldsResponse =
        fieldsSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(initialFieldsResponse);
    List<Map<String, Object>> initialFields = initialFieldsResponse.getFields();

    String fieldName = "accuracyField";
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    fieldAttributes.put("name", fieldName);
    fieldAttributes.put("type", "string");
    fieldAttributes.put("stored", false);
    fieldAttributes.put("indexed", true);
    fieldAttributes.put("default", "accuracy");
    fieldAttributes.put("required", true);
    SchemaRequest.AddField addFieldUpdateSchemaRequest =
        new SchemaRequest.AddField(fieldAttributes);
    SchemaResponse.UpdateResponse addFieldResponse =
        addFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);

    SchemaResponse.FieldsResponse currentFieldsResponse =
        fieldsSchemaRequest.process(getSolrClient());
    assertEquals(0, currentFieldsResponse.getStatus());
    List<Map<String, Object>> currentFields = currentFieldsResponse.getFields();
    assertEquals(initialFields.size() + 1, currentFields.size());

    SchemaRequest.Field fieldSchemaRequest = new SchemaRequest.Field(fieldName);
    SchemaResponse.FieldResponse newFieldResponse = fieldSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldResponse);
    Map<String, Object> newFieldAttributes = newFieldResponse.getField();
    assertThat(fieldName, 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"))));
    assertThat("accuracy", is(equalTo(newFieldAttributes.get("default"))));
    assertThat(true, is(equalTo(newFieldAttributes.get("required"))));
  }
예제 #5
0
  @Test
  public void testReplaceFieldAccuracy() throws Exception {
    // Given
    Map<String, Object> fieldAttributes = new LinkedHashMap<>();
    String fieldName = "accuracyField";
    fieldAttributes.put("name", fieldName);
    fieldAttributes.put("type", "string");
    fieldAttributes.put("stored", false);
    fieldAttributes.put("indexed", true);
    fieldAttributes.put("required", true);
    SchemaRequest.AddField addFieldUpdateSchemaRequest =
        new SchemaRequest.AddField(fieldAttributes);
    SchemaResponse.UpdateResponse addFieldResponse =
        addFieldUpdateSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(addFieldResponse);

    // When : update the field definition
    fieldAttributes.put("stored", true);
    fieldAttributes.put("indexed", false);
    SchemaRequest.ReplaceField replaceFieldRequest =
        new SchemaRequest.ReplaceField(fieldAttributes);
    SchemaResponse.UpdateResponse replaceFieldResponse =
        replaceFieldRequest.process(getSolrClient());
    assertValidSchemaResponse(replaceFieldResponse);

    // Then
    SchemaRequest.Field fieldSchemaRequest = new SchemaRequest.Field(fieldName);
    SchemaResponse.FieldResponse newFieldResponse = fieldSchemaRequest.process(getSolrClient());
    assertValidSchemaResponse(newFieldResponse);
    Map<String, Object> newFieldAttributes = newFieldResponse.getField();
    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"))));
    assertThat(true, is(equalTo(newFieldAttributes.get("required"))));
  }