SOLR-6229: Make SuggestComponent return 400 instead of 500 for bad dictionary selected in request

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1608680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2014-07-08 07:29:30 +00:00
parent 954f3dfdc5
commit beeeba528f
3 changed files with 29 additions and 3 deletions

View File

@ -161,6 +161,9 @@ Bug Fixes
* SOLR-6180: Callers of ManagedIndexSchema mutators should hold the schemaUpdateLock.
(Gregory Chanan via Steve Rowe)
* SOLR-6229: Make SuggestComponent return 400 instead of 500 for bad dictionary selected in request.
(Tomás Fernández Löbbe via shalin)
Optimizations
---------------------

View File

@ -35,6 +35,7 @@ import org.apache.lucene.search.suggest.Lookup.LookupResult;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CharsRef;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.params.ShardParams;
@ -208,7 +209,7 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
Set<SolrSuggester> querySuggesters;
try {
querySuggesters = getSuggesters(params);
} catch(IllegalArgumentException ex) {
} catch(SolrException ex) {
if (!buildAll && !reloadAll) {
throw ex;
} else {
@ -351,11 +352,12 @@ public class SuggestComponent extends SearchComponent implements SolrCoreAware,
if (curSuggester != null) {
solrSuggesters.add(curSuggester);
} else {
throw new IllegalArgumentException("No suggester named " + suggesterName +" was configured");
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No suggester named " + suggesterName +" was configured");
}
}
if (solrSuggesters.size() == 0) {
throw new IllegalArgumentException("No default suggester was configured");
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
"'" + SUGGEST_DICT + "' parameter not specified and no default suggester configured");
}
return solrSuggesters;

View File

@ -18,6 +18,7 @@ package org.apache.solr.handler.component;
*/
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrException;
import org.apache.solr.spelling.suggest.SuggesterParams;
import org.junit.BeforeClass;
import org.junit.Test;
@ -166,4 +167,24 @@ public class SuggestComponentTest extends SolrTestCaseJ4 {
);
}
@Test
public void testBadSuggesterName() throws Exception {
String fakeSuggesterName = "does-not-exist";
assertQEx("No suggester named " + fakeSuggesterName +" was configured",
req("qt", rh,
SuggesterParams.SUGGEST_DICT, fakeSuggesterName,
SuggesterParams.SUGGEST_Q, "exampel",
SuggesterParams.SUGGEST_COUNT, "2"),
SolrException.ErrorCode.BAD_REQUEST
);
assertQEx("'" + SuggesterParams.SUGGEST_DICT +
"' parameter not specified and no default suggester configured",
req("qt", rh,
SuggesterParams.SUGGEST_Q, "exampel",
SuggesterParams.SUGGEST_COUNT, "2"),
SolrException.ErrorCode.BAD_REQUEST
);
}
}