SOLR-6149: Specifying the query value without any index value does not work in Analysis browser

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1601317 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2014-06-09 06:38:28 +00:00
parent fde58d3d67
commit 07aeef7a71
3 changed files with 42 additions and 19 deletions

View File

@ -154,6 +154,9 @@ Bug Fixes
* SOLR-6120: zkcli.sh should expand solr.war automatically instead of throwing
ClassNotFoundException. (sebastian badea, shalin)
* SOLR-6149: Specifying the query value without any index value does not work in
Analysis browser. (Aman Tandon, shalin)
Other Changes
---------------------

View File

@ -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) {

View File

@ -108,6 +108,37 @@ public class FieldAnalysisRequestHandlerTest extends AnalysisRequestHandlerTestB
request = 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 AnalysisRequestHandlerTestB
assertToken(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);
}
}
}