Java Code Examples for org.apache.solr.client.solrj.response.schema.SchemaResponse#UpdateResponse

The following examples show how to use org.apache.solr.client.solrj.response.schema.SchemaResponse#UpdateResponse . 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 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 2
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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);

  expectThrows(SolrException.class, () -> fieldSchemaRequest.process(getSolrClient()));
}
 
Example 3
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 4
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void addFieldTypeShouldntBeCalledTwiceWithTheSameName() throws Exception {
  Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
  String fieldName = "failureInt";
  fieldTypeAttributes.put("name", fieldName);
  fieldTypeAttributes.put("class",  RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class));
  fieldTypeAttributes.put("omitNorms", true);
  fieldTypeAttributes.put("positionIncrementGap", 0);
  FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
  fieldTypeDefinition.setAttributes(fieldTypeAttributes);
  SchemaRequest.AddFieldType addFieldTypeRequest =
      new SchemaRequest.AddFieldType(fieldTypeDefinition);
  SchemaResponse.UpdateResponse addFieldTypeFirstResponse = addFieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(addFieldTypeFirstResponse);

  assertFailedSchemaResponse(() -> addFieldTypeRequest.process(getSolrClient()),
      "Field type '" + fieldName + "' already exists.");
}
 
Example 5
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@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);

  expectThrows(SolrException.class, () -> dynamicFieldSchemaRequest.process(getSolrClient()));
}
 
Example 6
Source File: TestManagedSchemaAPI.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private void testModifyField(String collection) throws IOException, SolrServerException {
  CloudSolrClient cloudClient = cluster.getSolrClient();

  SolrInputDocument doc = new SolrInputDocument("id", "3");
  cloudClient.add(collection, doc);
  cloudClient.commit(collection);

  String fieldName = "id";
  SchemaRequest.Field getFieldRequest = new SchemaRequest.Field(fieldName);
  SchemaResponse.FieldResponse getFieldResponse = getFieldRequest.process(cloudClient, collection);
  Map<String, Object> field = getFieldResponse.getField();
  field.put("docValues", true);
  SchemaRequest.ReplaceField replaceRequest = new SchemaRequest.ReplaceField(field);
  SchemaResponse.UpdateResponse replaceResponse = replaceRequest.process(cloudClient, collection);
  assertNull(replaceResponse.getResponse().get("errors"));
  CollectionAdminRequest.Reload reloadRequest = CollectionAdminRequest.reloadCollection(collection);
  CollectionAdminResponse response = reloadRequest.process(cloudClient);
  assertEquals(0, response.getStatus());
  assertTrue(response.isSuccess());

}
 
Example 7
Source File: TestManagedSchemaAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void addStringField(String fieldName, String collection, CloudSolrClient cloudClient) throws IOException, SolrServerException {
  Map<String, Object> fieldAttributes = new LinkedHashMap<>();
  fieldAttributes.put("name", fieldName);
  fieldAttributes.put("type", "string");
  SchemaRequest.AddField addFieldUpdateSchemaRequest = new SchemaRequest.AddField(fieldAttributes);
  SchemaResponse.UpdateResponse addFieldResponse = addFieldUpdateSchemaRequest.process(cloudClient, collection);
  assertEquals(0, addFieldResponse.getStatus());
  assertNull(addFieldResponse.getResponse().get("errors"));

  log.info("added new field={}", fieldName);
}
 
Example 8
Source File: TestEmbeddedSolrServerSchemaAPI.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testSchemaAddFieldAndVerifyExistence() throws Exception {
  assumeTrue("it needs to ammend schema", Boolean.getBoolean("managed.schema.mutable"));
  SchemaResponse.UpdateResponse addFieldResponse = new SchemaRequest.AddField(fieldAttributes).process(server);

  assertEquals(addFieldResponse.toString(), 0, addFieldResponse.getStatus());

  // This asserts that the field was actually created
  // this is due to the fact that the response gave OK but actually never created the field.
  Map<String,Object> foundFieldAttributes = new SchemaRequest.Field(fieldName).process(server).getField();
  assertEquals(fieldAttributes, foundFieldAttributes);

  assertEquals("removing " + fieldName, 0,
      new SchemaRequest.DeleteField(fieldName).process(server).getStatus());
}
 
Example 9
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 10
Source File: SchemaApiFailureTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
// commented 4-Sep-2018 @BadApple(bugUrl="https://issues.apache.org/jira/browse/SOLR-12028") // added 23-Aug-2018
public void testAddTheSameFieldTwice() throws Exception {
  CloudSolrClient client = cluster.getSolrClient();
  SchemaRequest.Update fieldAddition = new SchemaRequest.AddField
      (Utils.makeMap("name","myfield", "type","string"));
  SchemaResponse.UpdateResponse updateResponse = fieldAddition.process(client, COLLECTION);

  BaseHttpSolrClient.RemoteExecutionException ex = expectThrows(BaseHttpSolrClient.RemoteExecutionException.class,
      () -> fieldAddition.process(client, COLLECTION));

  assertTrue("expected error message 'Field 'myfield' already exists'.",Utils.getObjectByPath(ex.getMetaData(), false, "error/details[0]/errorMessages[0]").toString().contains("Field 'myfield' already exists.") );

}
 
Example 11
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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"))));
}
 
Example 12
Source File: ManagedSchemaRoundRobinCloudTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private void addField(SolrClient client, Map<String,Object> field) throws Exception {
  SchemaResponse.UpdateResponse addFieldResponse = new SchemaRequest.AddField(field).process(client, COLLECTION);
  assertNotNull(addFieldResponse);
  assertEquals(0, addFieldResponse.getStatus());
  assertNull(addFieldResponse.getResponse().get("errors"));
  String fieldName = field.get("name").toString();
  SchemaResponse.FieldResponse fieldResponse = new SchemaRequest.Field(fieldName).process(client, COLLECTION);
  assertNotNull(fieldResponse);
  assertEquals(0, fieldResponse.getStatus());
}
 
Example 13
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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"))));
}
 
Example 14
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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"))));
}
 
Example 15
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void addFieldShouldntBeCalledTwiceWithTheSameName() throws Exception {
  Map<String, Object> fieldAttributes = new LinkedHashMap<>();
  String fieldName = "failureField"; 
  fieldAttributes.put("name", fieldName);
  fieldAttributes.put("type", "string");
  SchemaRequest.AddField addFieldUpdateSchemaRequest =
      new SchemaRequest.AddField(fieldAttributes);
  SchemaResponse.UpdateResponse addFieldFirstResponse = addFieldUpdateSchemaRequest.process(getSolrClient());
  assertValidSchemaResponse(addFieldFirstResponse);

  assertFailedSchemaResponse(() -> addFieldUpdateSchemaRequest.process(getSolrClient()),
      "Field '" + fieldName + "' already exists.");
}
 
Example 16
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@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"))));
}
 
Example 17
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddFieldTypeAccuracy() throws Exception {
  SchemaRequest.FieldTypes fieldTypesRequest = new SchemaRequest.FieldTypes();
  SchemaResponse.FieldTypesResponse initialFieldTypesResponse = fieldTypesRequest.process(getSolrClient());
  assertValidSchemaResponse(initialFieldTypesResponse);
  List<FieldTypeRepresentation> initialFieldTypes = initialFieldTypesResponse.getFieldTypes();

  FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
  Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
  String fieldTypeName = "accuracyTextField";
  fieldTypeAttributes.put("name", fieldTypeName);
  fieldTypeAttributes.put("class", "solr.TextField");
  fieldTypeAttributes.put("positionIncrementGap", "100");
  fieldTypeDefinition.setAttributes(fieldTypeAttributes);

  AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition();
  Map<String, Object> charFilterAttributes = new LinkedHashMap<>();
  charFilterAttributes.put("class", "solr.PatternReplaceCharFilterFactory");
  charFilterAttributes.put("replacement", "$1$1");
  charFilterAttributes.put("pattern", "([a-zA-Z])\\\\1+");
  analyzerDefinition.setCharFilters(Collections.singletonList(charFilterAttributes));
  Map<String, Object> tokenizerAttributes = new LinkedHashMap<>();
  tokenizerAttributes.put("class", "solr.WhitespaceTokenizerFactory");
  analyzerDefinition.setTokenizer(tokenizerAttributes);
  Map<String, Object> filterAttributes = new LinkedHashMap<>();
  filterAttributes.put("class", "solr.WordDelimiterGraphFilterFactory");
  filterAttributes.put("preserveOriginal", "0");
  analyzerDefinition.setFilters(Collections.singletonList(filterAttributes));
  fieldTypeDefinition.setAnalyzer(analyzerDefinition);

  SchemaRequest.AddFieldType addFieldTypeRequest =
      new SchemaRequest.AddFieldType(fieldTypeDefinition);
  SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(addFieldTypeResponse);

  SchemaResponse.FieldTypesResponse currentFieldTypesResponse = fieldTypesRequest.process(getSolrClient());
  assertEquals(0, currentFieldTypesResponse.getStatus());
  List<FieldTypeRepresentation> currentFieldTypes = currentFieldTypesResponse.getFieldTypes();
  assertEquals(initialFieldTypes.size() + 1, currentFieldTypes.size());

  Map<String, Object> fieldAttributes = new LinkedHashMap<>();
  String fieldName = "accuracyField";
  fieldAttributes.put("name", fieldName);
  fieldAttributes.put("type", fieldTypeName);
  SchemaRequest.AddField addFieldRequest =
      new SchemaRequest.AddField(fieldAttributes);
  SchemaResponse.UpdateResponse addFieldResponse = addFieldRequest.process(getSolrClient());
  assertValidSchemaResponse(addFieldResponse);

  Map<String, Object> dynamicFieldAttributes = new LinkedHashMap<>();
  String dynamicFieldName = "*_accuracy";
  dynamicFieldAttributes.put("name", dynamicFieldName);
  dynamicFieldAttributes.put("type", fieldTypeName);
  SchemaRequest.AddDynamicField addDynamicFieldRequest =
      new SchemaRequest.AddDynamicField(dynamicFieldAttributes);
  SchemaResponse.UpdateResponse addDynamicFieldResponse = addDynamicFieldRequest.process(getSolrClient());
  assertValidSchemaResponse(addDynamicFieldResponse);

  SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName);
  SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(newFieldTypeResponse);
  FieldTypeRepresentation newFieldTypeRepresentation = newFieldTypeResponse.getFieldType();
  assertThat(fieldTypeName, is(equalTo(newFieldTypeRepresentation.getAttributes().get("name"))));
  assertThat("solr.TextField", is(equalTo(newFieldTypeRepresentation.getAttributes().get("class"))));
  assertThat(analyzerDefinition.getTokenizer().get("class"),
      is(equalTo(newFieldTypeRepresentation.getAnalyzer().getTokenizer().get("class"))));
}
 
Example 18
Source File: DocValuesNotIndexedTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void createCluster() throws Exception {
  System.setProperty("managed.schema.mutable", "true");
  configureCluster(2)
      .addConfig("conf1", TEST_PATH().resolve("configsets").resolve("cloud-managed").resolve("conf"))
      .configure();

  // Need enough shards that we have some shards that don't have any docs on them.
  CollectionAdminRequest.createCollection(COLLECTION, "conf1", 4, 1)
      .setMaxShardsPerNode(2)
      .process(cluster.getSolrClient());
  
  cluster.waitForActiveCollection(COLLECTION, 4, 4);

  fieldsToTestSingle =
      Collections.unmodifiableList(Arrays.asList(
          new FieldProps("intField", "int", 1),
          new FieldProps("longField", "long", 1),
          new FieldProps("doubleField", "double", 1),
          new FieldProps("floatField", "float", 1),
          new FieldProps("dateField", "date", 1),
          new FieldProps("stringField", "string", 1),
          new FieldProps("boolField", "boolean", 1),
          new FieldProps("sortableText", "sortabletext", 1)
      ));

  fieldsToTestMulti =
      Collections.unmodifiableList(Arrays.asList(
          new FieldProps("intFieldMulti", "int", 5),
          new FieldProps("longFieldMulti", "long", 5),
          new FieldProps("doubleFieldMulti", "double", 5),
          new FieldProps("floatFieldMulti", "float", 5),
          new FieldProps("dateFieldMulti", "date", 5),
          new FieldProps("stringFieldMulti", "string", 5),
          new FieldProps("boolFieldMulti", "boolean", 2),
          new FieldProps("sortableFieldMulti", "sortabletext", 5)
      ));

  // Fields to test for grouping and sorting with sortMissingFirst/Last.
  fieldsToTestGroupSortFirst =
      Collections.unmodifiableList(Arrays.asList(
          new FieldProps("intGSF", "int"),
          new FieldProps("longGSF", "long"),
          new FieldProps("doubleGSF", "double"),
          new FieldProps("floatGSF", "float"),
          new FieldProps("dateGSF", "date"),
          new FieldProps("stringGSF", "string"),
          new FieldProps("boolGSF", "boolean"),
          new FieldProps("sortableGSF", "sortabletext")
      ));

  fieldsToTestGroupSortLast =
      Collections.unmodifiableList(Arrays.asList(
          new FieldProps("intGSL", "int"),
          new FieldProps("longGSL", "long"),
          new FieldProps("doubleGSL", "double"),
          new FieldProps("floatGSL", "float"),
          new FieldProps("dateGSL", "date"),
          new FieldProps("stringGSL", "string"),
          new FieldProps("boolGSL", "boolean"),
          new FieldProps("sortableGSL", "sortabletext")
      ));

  List<Update> updateList = new ArrayList<>(fieldsToTestSingle.size() +
      fieldsToTestMulti.size() + fieldsToTestGroupSortFirst.size() + fieldsToTestGroupSortLast.size() +
      4);

  updateList.add(getType("name", "float", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Float.class)));

  updateList.add(getType("name", "double", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Double.class)));

  updateList.add(getType("name", "date", "class", RANDOMIZED_NUMERIC_FIELDTYPES.get(Date.class)));

  updateList.add(getType("name", "boolean", "class", "solr.BoolField"));


  // Add a field for each of the types we want to the schema.

  defineFields(updateList, fieldsToTestSingle, false);
  defineFields(updateList, fieldsToTestMulti, true);
  defineFields(updateList, fieldsToTestGroupSortFirst, false, "sorMissingFirst", "true");
  defineFields(updateList, fieldsToTestGroupSortLast, false, "sorMissingLast", "true");


  MultiUpdate multiUpdateRequest = new MultiUpdate(updateList);
  SchemaResponse.UpdateResponse multipleUpdatesResponse = multiUpdateRequest.process(cluster.getSolrClient(), COLLECTION);
  assertNull("Error adding fields", multipleUpdatesResponse.getResponse().get("errors"));

  cluster.getSolrClient().setDefaultCollection(COLLECTION);
}
 
Example 19
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Test
public void testReplaceFieldTypeAccuracy() throws Exception {
  // a fixed value for comparison after update, be contraian from the randomized 'default'
  final boolean useDv = Boolean.getBoolean(NUMERIC_DOCVALUES_SYSPROP);
  
  // Given
  Map<String, Object> fieldTypeAttributes = new LinkedHashMap<>();
  String fieldTypeName = "replaceInt";
  fieldTypeAttributes.put("name", fieldTypeName);
  fieldTypeAttributes.put("class",  RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class));
  fieldTypeAttributes.put("docValues", useDv);
  fieldTypeAttributes.put("omitNorms", true);
  fieldTypeAttributes.put("positionIncrementGap", 0);
  FieldTypeDefinition fieldTypeDefinition = new FieldTypeDefinition();
  fieldTypeDefinition.setAttributes(fieldTypeAttributes);
  SchemaRequest.AddFieldType addFieldTypeRequest =
      new SchemaRequest.AddFieldType(fieldTypeDefinition);
  SchemaResponse.UpdateResponse addFieldTypeResponse = addFieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(addFieldTypeResponse);

  // When : update the field definition
  fieldTypeAttributes.put("positionIncrementGap", 42);
  fieldTypeAttributes.put("omitNorms", false);
  FieldTypeDefinition replaceFieldTypeDefinition = new FieldTypeDefinition();
  replaceFieldTypeDefinition.setAttributes(fieldTypeAttributes);
  SchemaRequest.ReplaceFieldType replaceFieldTypeRequest =
      new SchemaRequest.ReplaceFieldType(replaceFieldTypeDefinition);
  SchemaResponse.UpdateResponse replaceFieldTypeResponse = replaceFieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(replaceFieldTypeResponse);

  // Then
  SchemaRequest.FieldType fieldTypeRequest = new SchemaRequest.FieldType(fieldTypeName);
  SchemaResponse.FieldTypeResponse newFieldTypeResponse = fieldTypeRequest.process(getSolrClient());
  assertValidSchemaResponse(newFieldTypeResponse);
  FieldTypeRepresentation replacedFieldTypeRepresentation = newFieldTypeResponse.getFieldType();
  Map<String, Object> replacedFieldTypeAttributes = replacedFieldTypeRepresentation.getAttributes();
  assertThat(fieldTypeName, is(equalTo(replacedFieldTypeAttributes.get("name"))));
  assertThat( RANDOMIZED_NUMERIC_FIELDTYPES.get(Integer.class),
              is(equalTo(replacedFieldTypeAttributes.get("class"))));
  assertThat(false, is(equalTo(replacedFieldTypeAttributes.get("omitNorms"))));
  assertThat("42", is(equalTo(replacedFieldTypeAttributes.get("positionIncrementGap"))));
  // should be unchanged...
  assertThat(useDv, is(equalTo(replacedFieldTypeAttributes.get("docValues"))));
}
 
Example 20
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@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"))));
}