You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ge...@apache.org on 2022/05/11 15:44:55 UTC

[solr] branch branch_9x updated: SOLR-15739: Convert v2 GET /get API to annotations (#852)

This is an automated email from the ASF dual-hosted git repository.

gerlowskija pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9x by this push:
     new 00ac7ad4038 SOLR-15739: Convert v2 GET /get API to annotations (#852)
00ac7ad4038 is described below

commit 00ac7ad4038da2a91f40aaa02033cd139558a629
Author: Jason Gerlowski <ge...@apache.org>
AuthorDate: Wed May 11 11:28:16 2022 -0400

    SOLR-15739: Convert v2 GET /get API to annotations (#852)
    
    Solr's been in the slow process of moving its v2 APIs away from the
    existing apispec/mapping framework towards one that relies on more
    explicit annotations to specify API properties.
    
    This commit converts the APIs from the core.RealtimeGet apispec files to
    the "new" framework.
---
 .../apache/solr/handler/RealTimeGetHandler.java    |  6 ++-
 .../solr/handler/admin/api/RealTimeGetAPI.java     | 48 ++++++++++++++++++++++
 .../src/resources/apispec/core.RealtimeGet.json    | 26 ------------
 3 files changed, 52 insertions(+), 28 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/handler/RealTimeGetHandler.java b/solr/core/src/java/org/apache/solr/handler/RealTimeGetHandler.java
index 4858fdb59f9..9716de9f3d8 100644
--- a/solr/core/src/java/org/apache/solr/handler/RealTimeGetHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/RealTimeGetHandler.java
@@ -16,11 +16,13 @@
  */
 package org.apache.solr.handler;
 
+import com.google.common.collect.Lists;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import org.apache.solr.api.AnnotatedApi;
 import org.apache.solr.api.Api;
-import org.apache.solr.api.ApiBag;
+import org.apache.solr.handler.admin.api.RealTimeGetAPI;
 import org.apache.solr.handler.component.HttpShardHandler;
 import org.apache.solr.handler.component.RealTimeGetComponent;
 import org.apache.solr.handler.component.SearchHandler;
@@ -51,7 +53,7 @@ public class RealTimeGetHandler extends SearchHandler {
 
   @Override
   public Collection<Api> getApis() {
-    return ApiBag.wrapRequestHandlers(this, "core.RealtimeGet");
+    return Lists.newArrayList(AnnotatedApi.getApis(new RealTimeGetAPI(this)));
   }
 
   @Override
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/RealTimeGetAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/RealTimeGetAPI.java
new file mode 100644
index 00000000000..25544d02fce
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/RealTimeGetAPI.java
@@ -0,0 +1,48 @@
+/*
+ * 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.handler.admin.api;
+
+import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET;
+
+import org.apache.solr.api.EndPoint;
+import org.apache.solr.handler.RealTimeGetHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.security.PermissionNameProvider;
+
+/**
+ * V2 API for fetching the latest (possibly uncommitted) version of one or more documents.
+ *
+ * <p>This API (GET /v2/collections/collectionName/get) is analogous to the v1
+ * /solr/collectionName/get API.
+ */
+public class RealTimeGetAPI {
+
+  private final RealTimeGetHandler rtgHandler;
+
+  public RealTimeGetAPI(RealTimeGetHandler rtgHandler) {
+    this.rtgHandler = rtgHandler;
+  }
+
+  @EndPoint(
+      path = {"/get"},
+      method = GET,
+      permission = PermissionNameProvider.Name.READ_PERM)
+  public void getDocuments(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
+    rtgHandler.handleRequestBody(req, rsp);
+  }
+}
diff --git a/solr/solrj/src/resources/apispec/core.RealtimeGet.json b/solr/solrj/src/resources/apispec/core.RealtimeGet.json
deleted file mode 100644
index b670398f41e..00000000000
--- a/solr/solrj/src/resources/apispec/core.RealtimeGet.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
-  "documentation": "https://solr.apache.org/guide/realtime-get.html",
-  "description": "RealTime Get allows retrieving documents by ID before the documents have been committed to the index. It is useful when you need access to documents as soon as they are indexed but your commit times are high for other reasons.",
-  "methods": [
-    "GET"
-  ],
-  "url": {
-    "paths": [
-      "/get"
-    ],
-    "params": {
-      "id": {
-        "type": "string",
-        "description": "A single document ID to retrieve."
-      },
-      "ids": {
-        "type": "string",
-        "description": "One or more document IDs to retrieve. Separate by commas if more than one ID is specified."
-      },
-      "fq":{
-        "type": "string",
-        "description": "An optional filter query to add to the query. One use case for this is security filtering, in case users or groups should not be able to retrieve the document ID requested."
-      }
-    }
-  }
-}