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 2023/03/10 20:05:02 UTC
[solr] branch main updated: SOLR-16397: Adding MLT API V2 (#1349)
This is an automated email from the ASF dual-hosted git repository.
gerlowskija pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new a6c5fa67622 SOLR-16397: Adding MLT API V2 (#1349)
a6c5fa67622 is described below
commit a6c5fa676226f52f614422f655bfe48c72e5d71f
Author: Ameer Albahem <42...@users.noreply.github.com>
AuthorDate: Sat Mar 11 07:04:56 2023 +1100
SOLR-16397: Adding MLT API V2 (#1349)
Co-authored-by: Jason Gerlowski <ge...@apache.org>
---
solr/CHANGES.txt | 2 +
.../apache/solr/handler/MoreLikeThisHandler.java | 14 +++++++
.../solr/handler/admin/api/MoreLikeThisAPI.java | 48 ++++++++++++++++++++++
3 files changed, 64 insertions(+)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index bc9448b48e1..d1c54405070 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -168,6 +168,8 @@ Improvements
`GET /api/aliases`. It is also now possible to request information about a specific alias at `GET /api/aliases/<aliasName>`.
(Alex Deparvu via Jason Gerlowski)
+* SOLR-16397: /mlt now has a v2 API available at `GET /api/collections/collName/mlt` (Ameer Albahem via Jason Gerlowski)
+
Optimizations
---------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
index 47ca8e3108b..fbe3b82953f 100644
--- a/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
+++ b/solr/core/src/java/org/apache/solr/handler/MoreLikeThisHandler.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr.handler;
+import com.google.common.collect.Lists;
import java.io.IOException;
import java.io.Reader;
import java.lang.invoke.MethodHandles;
@@ -38,6 +39,8 @@ import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.CharsRefBuilder;
+import org.apache.solr.api.AnnotatedApi;
+import org.apache.solr.api.Api;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.StringUtils;
import org.apache.solr.common.params.CommonParams;
@@ -47,6 +50,7 @@ import org.apache.solr.common.params.MoreLikeThisParams.TermStyle;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.NamedList;
+import org.apache.solr.handler.admin.api.MoreLikeThisAPI;
import org.apache.solr.handler.component.FacetComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SimpleFacets;
@@ -497,4 +501,14 @@ public class MoreLikeThisHandler extends RequestHandlerBase {
public String getDescription() {
return "Solr MoreLikeThis";
}
+
+ @Override
+ public Collection<Api> getApis() {
+ return Lists.newArrayList(AnnotatedApi.getApis(new MoreLikeThisAPI(this)));
+ }
+
+ @Override
+ public Boolean registerV2() {
+ return Boolean.TRUE;
+ }
}
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/api/MoreLikeThisAPI.java b/solr/core/src/java/org/apache/solr/handler/admin/api/MoreLikeThisAPI.java
new file mode 100644
index 00000000000..5c690ba517e
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/handler/admin/api/MoreLikeThisAPI.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.MoreLikeThisHandler;
+import org.apache.solr.request.SolrQueryRequest;
+import org.apache.solr.response.SolrQueryResponse;
+import org.apache.solr.security.PermissionNameProvider;
+
+/**
+ * V2 API for performing a more like this request to a solr collection.
+ *
+ * <p>This API (GET /v2/collections/collectionName/mlt) is analogous to the v1 /solr/collName/mlt
+ * API.
+ */
+public class MoreLikeThisAPI {
+ private final MoreLikeThisHandler mltHandler;
+
+ public MoreLikeThisAPI(MoreLikeThisHandler mltHandler) {
+ this.mltHandler = mltHandler;
+ }
+
+ @EndPoint(
+ path = {"/mlt"},
+ method = GET,
+ permission = PermissionNameProvider.Name.READ_PERM)
+ public void getDocuments(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception {
+ mltHandler.handleRequestBody(req, rsp);
+ }
+}