Apache Lucene open-source search software
SOLR-6149: Specifying the query value without any index value does not work in Analysis browser
Shalin Shekhar Mangar07aeef7a7114
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex f996a05bea4..e342373ad1d 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -154,6 +154,9 @@ Bug Fixes* SOLR-6120: zkcli.sh should expand solr.war automatically instead of throwingClassNotFoundException. (sebastian badea, shalin)+* SOLR-6149: Specifying the query value without any index value does not work in+ Analysis browser. (Aman Tandon, shalin)+Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java b/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.javaindex e1044da2e83..3c2aaf082f7 100644--- a/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/FieldAnalysisRequestHandler.java@@ -19,6 +19,7 @@ package org.apache.solr.handler;import org.apache.lucene.util.BytesRef;import org.apache.solr.client.solrj.request.FieldAnalysisRequest;+import org.apache.solr.common.SolrException;import org.apache.solr.common.params.AnalysisParams;import org.apache.solr.common.params.CommonParams;import org.apache.solr.common.params.SolrParams;@@ -62,7 +63,7 @@ import java.util.Set;* <tr>* <td>analysis.fieldvalue</td>* <td>string</td>- * <td>yes</td>+ * <td>no</td>* <td>The text that will be analyzed. The analysis will mimic the index-time analysis.</td>* <td>No</td>* </tr>@@ -85,7 +86,7 @@ import java.util.Set;* </table>* <p>Note that if neither analysis.fieldname and analysis.fieldtype is specified, then the default search field's* analyzer is used.</p>- *+ * <p>Note that if one of analysis.value or analysis.query or q must be specified</p>** @since solr 1.4*/@@ -139,7 +140,11 @@ public class FieldAnalysisRequestHandler extends AnalysisRequestHandlerBase {}analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q)));- String value = solrParams.required().get(AnalysisParams.FIELD_VALUE);+ String value = solrParams.get(AnalysisParams.FIELD_VALUE);+ if (analysisRequest.getQuery() == null && value == null) {+ throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,+ "One of analysis.value or q or analysis.query parameters must be specified");+ }Iterable<ContentStream> streams = req.getContentStreams();if (streams != null) {diff --git a/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java b/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.javaindex 43cec6afe77..0db05e9ba08 100644--- a/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java+++ b/solr/core/src/test/org/apache/solr/handler/FieldAnalysisRequestHandlerTest.java@@ -108,6 +108,37 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestBrequest = handler.resolveAnalysisRequest(req);assertNull(request.getQuery());req.close();++ // test absence of index-time value and presence of q+ params.remove(AnalysisParams.FIELD_VALUE);+ params.add(CommonParams.Q, "quick lazy");+ request = handler.resolveAnalysisRequest(req);+ assertEquals("quick lazy", request.getQuery());+ req.close();++ // test absence of index-time value and presence of query+ params.remove(CommonParams.Q);+ params.add(AnalysisParams.QUERY, "quick lazy");+ request = handler.resolveAnalysisRequest(req);+ assertEquals("quick lazy", request.getQuery());+ req.close();++ // must fail if all of q, analysis.query or analysis.value are absent+ params.remove(CommonParams.Q);+ params.remove(AnalysisParams.QUERY);+ params.remove(AnalysisParams.FIELD_VALUE);+ try {+ request = handler.resolveAnalysisRequest(req);+ fail("Analysis request must fail if all of q, analysis.query or analysis.value are absent");+ } catch (SolrException e) {+ if (e.code() != SolrException.ErrorCode.BAD_REQUEST.code) {+ fail("Unexpected exception");+ }+ } catch (Exception e) {+ fail("Unexpected exception");+ }++ req.close();}/**@@ -380,20 +411,4 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestBassertToken(tokenList.get(4), new TokenInfo("a", null, "word", 12, 13, 4, new int[]{3,4,4}, null, false));assertToken(tokenList.get(5), new TokenInfo("test", null, "word", 14, 18, 5, new int[]{4,5,5}, null, false));}-- public void testRequiredParamHandling() throws Exception {- ModifiableSolrParams params = new ModifiableSolrParams();- params.add(CommonParams.Q, "fox brown");-- SolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), params);- try {- FieldAnalysisRequest request = handler.resolveAnalysisRequest(req);- fail("A request with no parameters should not have succeeded");- } catch (NullPointerException npe) {- fail("A request with no paramters should not result in NPE");- } catch (SolrException e) {- assertEquals("A request with no parameters should have returned a BAD_REQUEST error", e.code(),- SolrException.ErrorCode.BAD_REQUEST.code);- }- }}