Exemple #1
0
 @Test
 public void testGetFieldsAccuracy() throws Exception {
   SchemaRequest.Fields fieldsSchemaRequest = new SchemaRequest.Fields();
   SchemaResponse.FieldsResponse fieldsResponse = fieldsSchemaRequest.process(getSolrClient());
   assertValidSchemaResponse(fieldsResponse);
   List<Map<String, Object>> fields = fieldsResponse.getFields();
   assertThat(fields.isEmpty(), is(false));
 }
Exemple #2
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"))));
  }