Apache Solr open-source search software
SOLR-16397: Adding MLT API V2 (#1349)
Ameer Albahema6c5fa676226
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 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.javaindex 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.javanew file mode 100644index 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);+ }+}