Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions changelog/unreleased/SOLR-18479-v2-copyfield-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
title: >
The v2 Schema API can now manage copy-field rules directly, under
`/api/collections/<collection>/schema/copyfields/<sourceField>`.
Previously copy-fields were the one schema resource reachable only through the bulk endpoint.
Rules are addressed by their source field: `GET` lists that source's rules, `PUT` sets its
complete list of destination objects, each with its own optional `maxChars`,
`POST` appends destinations without disturbing existing rules,
and `DELETE` removes them -- either all of them, or the ones named in a trailing
comma-separated path segment.
The Admin UI uses these endpoints to add and delete copy-field rules.
type: added
authors:
- name: Jan Høydahl
- name: Eric Pugh
links:
- name: SOLR-18479
url: https://issues.apache.org/jira/browse/SOLR-18479
10 changes: 10 additions & 0 deletions changelog/unreleased/SOLR-18479-v2-destination.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: >
The v2 Schema API uses `destination` for copy-field request and response properties,
and `destination.fl` for destination filtering. Each bulk copy-field operation addresses
one destination. The v1 Schema API retains its existing `dest` names and behavior.
type: changed
authors:
- name: Eric Pugh
links:
- name: SOLR-18479
url: https://issues.apache.org/jira/browse/SOLR-18479
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ interface Fields {
tags = {"schema"})
SchemaListCopyFieldsResponse listCopyFields();

@GET
@Path("/copyfields/{sourceField}")
@StoreApiParameters
@Operation(
summary = "List the copy-field rules copying from the specified source field",
tags = {"schema"})
SchemaListCopyFieldsResponse listCopyFieldsBySource(
@PathParam("sourceField") String sourceField);

@GET
@Path("/dynamicfields")
@StoreApiParameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import java.util.List;
import org.apache.solr.client.api.model.CopyFieldDestination;
import org.apache.solr.client.api.model.SchemaChange;
import org.apache.solr.client.api.model.SolrJerseyResponse;
import org.apache.solr.client.api.model.UpsertDynamicFieldOperation;
Expand Down Expand Up @@ -112,25 +113,56 @@ SolrJerseyResponse addFieldType(
SolrJerseyResponse deleteFieldType(@PathParam("fieldTypeName") String fieldTypeName)
throws Exception;

// TODO Gah! Copyfields don't currently have names for us to create/delete by name in an API like
// /schema/copyfields/{copyFieldName}...figure out how to address this in a way consistent with
// all our other APIs. (In the meantime, the functionality is exposed through the bulk API at
// least.
// @POST
// @Path("/copyfields/{copyFieldName}")
// @StoreApiParameters
// @Operation(
// summary = "Add a new copy-field with the specified name.",
// tags = {"schema"})
// SolrJerseyResponse addCopyField(@PathParam("copyFieldName") String copyFieldName,
// @RequestBody SchemaChangeOperation.AddCopyField requestBody) throws Exception;
//
// @DELETE
// @Path("/copyfields/{copyFieldName}")
// @StoreApiParameters
// @Operation(summary = "Remove the copy-field with the specified name.", tags = {"schema"})
// SolrJerseyResponse deleteCopyField(@PathParam("copyFieldName") String copyFieldName) throws
// Exception;
// Copy-field rules have no name of their own, so unlike the other schema resources they are
// addressed by their source field. A single request therefore covers all of the rules that
// share that source.
@PUT
@Path("/copyfields/{sourceField}")
@StoreApiParameters
@Operation(
summary =
"Set the copy-field rules for the specified source field, with a character limit per destination. The given destinations "
+ "replace any rules that source already has.",
tags = {"schema"})
SolrJerseyResponse upsertCopyFields(
@PathParam("sourceField") String sourceField,
@RequestBody(required = true) List<CopyFieldDestination> requestBody)
throws Exception;

@POST
@Path("/copyfields/{sourceField}")
@StoreApiParameters
@Operation(
summary =
"Add the given destinations to the copy-field rules for the specified source field, "
+ "leaving that source's existing rules in place.",
tags = {"schema"})
SolrJerseyResponse appendCopyFields(
@PathParam("sourceField") String sourceField,
@RequestBody(required = true) List<CopyFieldDestination> requestBody)
throws Exception;

@DELETE
@Path("/copyfields/{sourceField}")
@StoreApiParameters
@Operation(
summary = "Remove every copy-field rule copying from the specified source field.",
tags = {"schema"})
SolrJerseyResponse deleteCopyFields(@PathParam("sourceField") String sourceField)
throws Exception;

@DELETE
@Path("/copyfields/{sourceField}/{destinationFields}")
@StoreApiParameters
@Operation(
summary =
"Remove the copy-field rules from the specified source field to the specified "
+ "destinations. Several destinations may be given as a comma-separated list.",
tags = {"schema"})
SolrJerseyResponse deleteCopyFieldsByDestination(
@PathParam("sourceField") String sourceField,
@PathParam("destinationFields") String destinationFields)
throws Exception;

@POST
@Path("/bulk")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.util.List;

@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public class AddCopyFieldOperation extends SchemaChange {
@JsonProperty public String source;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/** A v2 bulk operation adding one copy-field destination. */
public class AddCopyFieldRequest extends SchemaChange {
@JsonProperty(required = true)
public String source;

@JsonProperty(required = true)
public String destination;

@JsonProperty public Integer maxChars;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/** A destination and its optional character limit for a v2 copy-field rule. */
public class CopyFieldDestination {
@JsonProperty(required = true)
public String destination;

@JsonProperty public Integer maxChars;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import java.util.List;

@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)
public class DeleteCopyFieldOperation extends SchemaChange {
@JsonProperty public String source;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.client.api.model;

import com.fasterxml.jackson.annotation.JsonProperty;

/** A v2 bulk operation deleting one copy-field destination. */
public class DeleteCopyFieldRequest extends SchemaChange {
@JsonProperty(required = true)
public String source;

@JsonProperty(required = true)
public String destination;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
@JsonSubTypes.Type(value = DeleteFieldTypeOperation.class, name = "delete-field-type"),
@JsonSubTypes.Type(value = DeleteFieldOperation.class, name = "delete-field"),
@JsonSubTypes.Type(value = DeleteDynamicFieldOperation.class, name = "delete-dynamic-field"),
@JsonSubTypes.Type(value = AddCopyFieldOperation.class, name = "add-copy-field"),
@JsonSubTypes.Type(value = DeleteCopyFieldOperation.class, name = "delete-copy-field"),
@JsonSubTypes.Type(value = AddCopyFieldRequest.class, name = "add-copy-field"),
@JsonSubTypes.Type(value = DeleteCopyFieldRequest.class, name = "delete-copy-field"),
})
public class SchemaChange {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,22 @@ public void testAddCopyField() throws Exception {
{
"operationType": "add-copy-field",
"source": "source1",
"destinations": ["dest1", "dest2"],
"destination": "dest1",
"maxChars": 123
}
""";

final var parsedGeneric = OBJECT_MAPPER.readValue(inputJson, SchemaChange.class);

assertThat(parsedGeneric, instanceOf(AddCopyFieldOperation.class));
final var parsedSpecific = (AddCopyFieldOperation) parsedGeneric;
assertThat(parsedGeneric, instanceOf(AddCopyFieldRequest.class));
final var parsedSpecific = (AddCopyFieldRequest) parsedGeneric;
assertEquals("source1", parsedSpecific.source);
assertThat(parsedSpecific.destinations, contains("dest1", "dest2"));
assertEquals("dest1", parsedSpecific.destination);
assertEquals(Integer.valueOf(123), parsedSpecific.maxChars);
}

// "dest" is used instead of "destinations", to support v1 APIs
@Test
public void testAddCopyFieldAltFieldName() throws Exception {
public void testV1AddCopyFieldDest() throws Exception {
final var inputJson =
"""
{
Expand All @@ -104,10 +103,7 @@ public void testAddCopyFieldAltFieldName() throws Exception {
}
""";

final var parsedGeneric = OBJECT_MAPPER.readValue(inputJson, SchemaChange.class);

assertThat(parsedGeneric, instanceOf(AddCopyFieldOperation.class));
final var parsedSpecific = (AddCopyFieldOperation) parsedGeneric;
final var parsedSpecific = OBJECT_MAPPER.readValue(inputJson, AddCopyFieldOperation.class);
assertEquals("source1", parsedSpecific.source);
assertThat(parsedSpecific.destinations, contains("dest1", "dest2"));
assertEquals(Integer.valueOf(123), parsedSpecific.maxChars);
Expand Down Expand Up @@ -183,21 +179,20 @@ public void testDeleteCopyField() throws Exception {
{
"operationType": "delete-copy-field",
"source": "source1",
"destinations": ["dest1", "dest2"]
"destination": "dest1"
}
""";

final var parsedGeneric = OBJECT_MAPPER.readValue(inputJson, SchemaChange.class);

assertThat(parsedGeneric, instanceOf(DeleteCopyFieldOperation.class));
final var parsedSpecific = (DeleteCopyFieldOperation) parsedGeneric;
assertThat(parsedGeneric, instanceOf(DeleteCopyFieldRequest.class));
final var parsedSpecific = (DeleteCopyFieldRequest) parsedGeneric;
assertEquals("source1", parsedSpecific.source);
assertThat(parsedSpecific.destinations, contains("dest1", "dest2"));
assertEquals("dest1", parsedSpecific.destination);
}

// "dest" is used instead of "destinations", to support v1 APIs
@Test
public void testDeleteCopyFieldAltFieldName() throws Exception {
public void testV1DeleteCopyFieldDest() throws Exception {
final var inputJson =
"""
{
Expand All @@ -207,10 +202,7 @@ public void testDeleteCopyFieldAltFieldName() throws Exception {
}
""";

final var parsedGeneric = OBJECT_MAPPER.readValue(inputJson, SchemaChange.class);

assertThat(parsedGeneric, instanceOf(DeleteCopyFieldOperation.class));
final var parsedSpecific = (DeleteCopyFieldOperation) parsedGeneric;
final var parsedSpecific = OBJECT_MAPPER.readValue(inputJson, DeleteCopyFieldOperation.class);
assertEquals("source1", parsedSpecific.source);
assertThat(parsedSpecific.destinations, contains("dest1", "dest2"));
}
Expand Down
5 changes: 3 additions & 2 deletions solr/core/src/java/org/apache/solr/handler/SchemaHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void handleGET(SolrQueryRequest req, SolrQueryResponse rsp) {
case "/schema":
{
V2ApiUtils.squashIntoSolrResponseWithoutHeader(
rsp, new GetSchema(req.getCore(), req.getSchema()).getSchemaInfo());
rsp, new GetSchema(req.getCore(), req.getSchema()).getSchemaInfoForV1());
break;
}
case "/schema/version":
Expand Down Expand Up @@ -216,7 +216,8 @@ private void handleGET(SolrQueryRequest req, SolrQueryResponse rsp) {
case "copyfields":
{
V2ApiUtils.squashIntoSolrResponseWithoutHeader(
rsp, new GetSchemaField(req.getSchema(), req.getParams()).listCopyFields());
rsp,
new GetSchemaField(req.getSchema(), req.getParams()).listCopyFieldsForV1());
return;
}
case "dynamicfields":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import jakarta.inject.Inject;
import java.lang.invoke.MethodHandles;
import java.util.LinkedHashMap;
import java.util.List;
import org.apache.solr.api.JerseyResource;
import org.apache.solr.client.api.endpoint.GetSchemaApi;
import org.apache.solr.client.api.model.SchemaInfoResponse;
Expand Down Expand Up @@ -54,6 +56,16 @@ public GetSchema(SolrCore solrCore, IndexSchema indexSchema) {
@Override
@PermissionName(PermissionNameProvider.Name.SCHEMA_READ_PERM)
public SchemaInfoResponse getSchemaInfo() {
final var response = getSchemaInfoForV1();
response.schema = new LinkedHashMap<>(response.schema);
if (response.schema.get("copyFields") instanceof List<?> rules) {
response.schema.put("copyFields", GetSchemaField.copyFieldsForV2(rules));
}
return response;
}

/** Returns the schema using the v1 copy-field names. */
public SchemaInfoResponse getSchemaInfoForV1() {
final var response = instantiateJerseyResponse(SchemaInfoResponse.class);

response.schema = indexSchema.getNamedPropertyValues();
Expand Down
Loading
Loading