Java Code Examples for org.apache.solr.client.solrj.request.schema.SchemaRequest#AddCopyField

The following examples show how to use org.apache.solr.client.solrj.request.schema.SchemaRequest#AddCopyField . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testCopyFieldAccuracy() throws Exception {
  SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields();
  SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient());
  List<Map<String, Object>> initialCopyFieldsAttributes = initialCopyFieldsResponse.getCopyFields();

  String srcFieldName = "copyfield";
  String destFieldName1 = "destField1", destFieldName2 = "destField2";
  createStoredStringField(srcFieldName, getSolrClient());
  createStoredStringField(destFieldName1, getSolrClient());
  createStoredStringField(destFieldName2, getSolrClient());

  SchemaRequest.AddCopyField addCopyFieldRequest =
      new SchemaRequest.AddCopyField(srcFieldName,
          Arrays.asList(destFieldName1, destFieldName2));
  SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient());
  assertValidSchemaResponse(addCopyFieldResponse);

  SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient());
  List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields();
  assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size());
}
 
Example 2
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCopyFieldAccuracy() throws Exception {
  String srcFieldName = "copyfield";
  String destFieldName1 = "destField1", destFieldName2 = "destField2";
  createStoredStringField(srcFieldName, getSolrClient());
  createStoredStringField(destFieldName1, getSolrClient());
  createStoredStringField(destFieldName2, getSolrClient());

  SchemaRequest.AddCopyField addCopyFieldRequest =
      new SchemaRequest.AddCopyField(srcFieldName,
          Arrays.asList(destFieldName1, destFieldName2));
  SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient());
  System.out.println(addCopyFieldResponse);
  assertValidSchemaResponse(addCopyFieldResponse);

  SchemaRequest.DeleteCopyField deleteCopyFieldRequest1 =
      new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName1));
  assertValidSchemaResponse(deleteCopyFieldRequest1.process(getSolrClient()));

  SchemaRequest.DeleteCopyField deleteCopyFieldRequest2 =
      new SchemaRequest.DeleteCopyField(srcFieldName, Arrays.asList(destFieldName2));
  assertValidSchemaResponse(deleteCopyFieldRequest2.process(getSolrClient()));
}
 
Example 3
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyFieldWithMaxCharsAccuracy() throws Exception {
  SchemaRequest.CopyFields copyFieldsSchemaRequest = new SchemaRequest.CopyFields();
  SchemaResponse.CopyFieldsResponse initialCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient());
  List<Map<String, Object>> initialCopyFieldsAttributes = initialCopyFieldsResponse.getCopyFields();

  String srcFieldName = "copyfield";
  String destFieldName1 = "destField1", destFieldName2 = "destField2";
  createStoredStringField(srcFieldName, getSolrClient());
  createStoredStringField(destFieldName1, getSolrClient());
  createStoredStringField(destFieldName2, getSolrClient());

  Integer maxChars = 200;
  SchemaRequest.AddCopyField addCopyFieldRequest =
      new SchemaRequest.AddCopyField(srcFieldName,
          Arrays.asList(destFieldName1, destFieldName2), maxChars);
  SchemaResponse.UpdateResponse addCopyFieldResponse = addCopyFieldRequest.process(getSolrClient());
  assertValidSchemaResponse(addCopyFieldResponse);

  SchemaResponse.CopyFieldsResponse currentCopyFieldsResponse = copyFieldsSchemaRequest.process(getSolrClient());
  List<Map<String, Object>> currentCopyFields = currentCopyFieldsResponse.getCopyFields();
  assertEquals(initialCopyFieldsAttributes.size() + 2, currentCopyFields.size());
  for (Map<String, Object> currentCopyField : currentCopyFields) {
    if (srcFieldName.equals(currentCopyField.get("source"))) {
      String currentDestFieldName = (String) currentCopyField.get("dest");
      int currentMaxChars = (Integer) currentCopyField.get("maxChars");
      assertThat(currentDestFieldName, anyOf(is(equalTo(destFieldName1)), is(equalTo(destFieldName2))));
      assertTrue(maxChars == currentMaxChars);
    }
  }
}
 
Example 4
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void copyFieldsShouldFailWhenOneOfTheFieldsDoesntExistInTheSchema() throws Exception {
  String srcFieldName = "srcnotexist";
  String destFieldName1 = "destNotExist1", destFieldName2 = "destNotExist2";

  SchemaRequest.AddCopyField addCopyFieldRequest 
      = new SchemaRequest.AddCopyField(srcFieldName, Arrays.asList(destFieldName1, destFieldName2));
  assertFailedSchemaResponse(() -> addCopyFieldRequest.process(getSolrClient()),
      "copyField source :'" + srcFieldName + "' is not a glob and doesn't match any explicit field or dynamicField.");
}