mirror of https://github.com/apache/lucene.git
SOLR-297 - fixed the RequiredSolrParams.getField* methods, they weren't falling back to the non field specific param names before failing with an exception
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@555345 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a53367d319
commit
1fec553e28
|
@ -113,6 +113,10 @@ Bug Fixes
|
|||
|
||||
5. SOLR-292: Fix MoreLikeThis facet counting. (Pieter Berkel via ryan)
|
||||
|
||||
6. SOLR-297: Fix bug in RequiredSolrParams where requiring a field
|
||||
specific param would fail if a general default value had been supplied.
|
||||
(hossman)
|
||||
|
||||
Other Changes
|
||||
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
|
||||
build scripts to make two jars: apache-solr-1.3.jar and
|
||||
|
|
|
@ -50,7 +50,40 @@ public class RequiredSolrParams extends SolrParams {
|
|||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFieldParam(final String field, final String param) {
|
||||
final String fpname = fpname(field,param);
|
||||
String val = params.get(fpname);
|
||||
if (null == val) {
|
||||
// don't call this.get, we want a specified exception message
|
||||
val = params.get(param);
|
||||
if (null == val) {
|
||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
|
||||
"Missing required parameter: "+fpname+
|
||||
" (or default: "+param+")" );
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getFieldParams(final String field, final String param) {
|
||||
final String fpname = fpname(field,param);
|
||||
String[] val = params.getParams(fpname);
|
||||
if (null == val) {
|
||||
// don't call this.getParams, we want a specified exception message
|
||||
val = params.getParams(param);
|
||||
if (null == val) {
|
||||
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
|
||||
"Missing required parameter: "+fpname+
|
||||
" (or default: "+param+")" );
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getParams(String param) {
|
||||
String[] vals = params.getParams(param);
|
||||
|
|
|
@ -127,7 +127,11 @@ public class SolrParamTest extends TestCase
|
|||
// field value present
|
||||
assertEquals( pbool , required.getFieldBool( "fl", "bool" ) );
|
||||
// field defaulting (fall through to non-field-specific value)
|
||||
//assertEquals( pint , required.getFieldInt( "fff", "int" ) );
|
||||
assertEquals( pstr , required.getFieldParams("fakefield", "str")[0] );
|
||||
assertEquals( pstr , required.getFieldParam( "fakefield", "str" ) );
|
||||
assertEquals( pbool , required.getFieldBool( "fakefield", "bool" ) );
|
||||
assertEquals( pint , required.getFieldInt( "fakefield", "int" ) );
|
||||
assertEquals( pfloat , required.getFieldFloat( "fakefield", "float" ) );
|
||||
|
||||
// Required params which are missing: These should throw a 400
|
||||
assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.get( "aaaa" ); } } ) );
|
||||
|
|
Loading…
Reference in New Issue