-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR-16835: Add approximate-/select to OAS (#2079)
Now that Solr uses its OAS to generate client bindings in multiple languages (Java and JavaScript, so far), users of these clients may wish to use them to run searches. Normally, this would require converting the `/select` endpoint to JAX-RS so that its inputs and outputs can be described comprehensively in our OAS. However, doing this for `/select` will take some time due to the complexity and large degree of configurability the endpoint offers. This commit works around this limitation by creating an approximation of the `/select` endpoint that can appear in our OAS until the API can be converted to JAX-RS in earnest. This will give generated-client users access to at least some query functionality in this interim. The `/select` query parameters supported in this commit were chosen mostly arbitrarily. They may be added to freely as generated-client users run into particular needs (e.g. for setting 'faceting' parameters).
- Loading branch information
1 parent
3ba8346
commit fb9b6fd
Showing
5 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
solr/api/src/java/org/apache/solr/client/api/endpoint/SelectApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.endpoint; | ||
|
||
import static org.apache.solr.client.api.util.Constants.GENERIC_ENTITY_PROPERTY; | ||
import static org.apache.solr.client.api.util.Constants.STORE_PATH_PREFIX; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.extensions.Extension; | ||
import io.swagger.v3.oas.annotations.extensions.ExtensionProperty; | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody; | ||
import java.io.InputStream; | ||
import java.util.List; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.QueryParam; | ||
import org.apache.solr.client.api.model.FlexibleSolrJerseyResponse; | ||
import org.apache.solr.client.api.util.StoreApiParameters; | ||
|
||
/** | ||
* V2 API implementation shim for Solr's querying or otherwise inspecting documents in a core or | ||
* collection. | ||
* | ||
* <p>Due to the complexity and configurability of Solr's '/select' endpoint, this interface doesn't | ||
* attempt to be exhaustive in describing /select inputs and outputs. Rather, it exists to give | ||
* Solr's OAS (and the clients generated from that) an approximate view of the endpoint until its | ||
* inputs and outputs can be understood more fully. | ||
*/ | ||
@Path(STORE_PATH_PREFIX + "/select") | ||
public interface SelectApi { | ||
@GET | ||
@StoreApiParameters | ||
@Operation( | ||
summary = "Query a Solr core or collection using individual query parameters", | ||
tags = {"querying"}) | ||
FlexibleSolrJerseyResponse query( | ||
@QueryParam("q") String query, | ||
@QueryParam("fq") List<String> filterQueries, | ||
@QueryParam("fl") String fieldList, | ||
@QueryParam("rows") Integer rows); | ||
|
||
@POST | ||
@StoreApiParameters | ||
@Operation( | ||
summary = "Query a Solr core or collection using the structured request DSL", | ||
tags = {"querying"}) | ||
// TODO Find way to bundle the request-body annotations below for re-use on other similar | ||
// endpoints. | ||
FlexibleSolrJerseyResponse jsonQuery( | ||
@Parameter(required = true) | ||
@RequestBody( | ||
required = true, | ||
extensions = { | ||
@Extension( | ||
properties = { | ||
@ExtensionProperty(name = GENERIC_ENTITY_PROPERTY, value = "true") | ||
}) | ||
}) | ||
InputStream structuredRequest); | ||
} |
38 changes: 38 additions & 0 deletions
38
solr/api/src/java/org/apache/solr/client/api/model/FlexibleSolrJerseyResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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.JsonAnyGetter; | ||
import com.fasterxml.jackson.annotation.JsonAnySetter; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** A {@link SolrJerseyResponse} which can accept any top-level properties. */ | ||
public class FlexibleSolrJerseyResponse extends SolrJerseyResponse { | ||
|
||
private Map<String, Object> unknownFields = new HashMap<>(); | ||
|
||
@JsonAnyGetter | ||
public Map<String, Object> unknownProperties() { | ||
return unknownFields; | ||
} | ||
|
||
@JsonAnySetter | ||
public void setUnknownProperty(String field, Object value) { | ||
unknownFields.put(field, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters