SOLR-598: Make DebugComp last

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@681809 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2008-08-01 20:06:28 +00:00
parent 18331a264b
commit 60fff07d87
3 changed files with 43 additions and 5 deletions

View File

@ -506,7 +506,9 @@ Bug Fixes
43. SOLR-648: SpellCheckComponent throws NullPointerException on using spellcheck.q request 43. SOLR-648: SpellCheckComponent throws NullPointerException on using spellcheck.q request
parameter after restarting Solr, if reload is called but build is not called. parameter after restarting Solr, if reload is called but build is not called.
(Jonathan Lee, shalin) (Jonathan Lee, shalin)
44. SOLR-598: DebugComponent now always occurs last in the SearchHandler list unless the components are explicitly declared. (gsingers)
Other Changes Other Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the

View File

@ -70,7 +70,9 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware
} }
/** /**
* Initialize the components based on name * Initialize the components based on name. Note, if using {@link #INIT_FIRST_COMPONENTS} or {@link #INIT_LAST_COMPONENTS},
* then the {@link DebugComponent} will always occur last. If this is not desired, then one must explicitly declare all components using
* the {@link #INIT_COMPONENTS} syntax.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void inform(SolrCore core) public void inform(SolrCore core)
@ -80,6 +82,7 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware
List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS); List<String> last = (List<String>) initArgs.get(INIT_LAST_COMPONENTS);
List<String> list = null; List<String> list = null;
boolean makeDebugLast = true;
if( declaredComponents == null ) { if( declaredComponents == null ) {
// Use the default component list // Use the default component list
list = getDefaultComponents(); list = getDefaultComponents();
@ -100,14 +103,24 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"First/Last components only valid if you do not declare 'components'"); "First/Last components only valid if you do not declare 'components'");
} }
makeDebugLast = false;
} }
// Build the component list // Build the component list
components = new ArrayList<SearchComponent>( list.size() ); components = new ArrayList<SearchComponent>( list.size() );
DebugComponent dbgCmp = null;
for(String c : list){ for(String c : list){
SearchComponent comp = core.getSearchComponent( c ); SearchComponent comp = core.getSearchComponent( c );
components.add(comp); if (comp instanceof DebugComponent && makeDebugLast == true){
log.info("Adding component:"+comp); dbgCmp = (DebugComponent) comp;
} else {
components.add(comp);
log.info("Adding component:"+comp);
}
}
if (makeDebugLast == true && dbgCmp != null){
components.add(dbgCmp);
log.info("Adding debug component:" + dbgCmp);
} }
} }

View File

@ -49,6 +49,27 @@ public class SearchHandlerTest extends AbstractSolrTestCase
assertEquals( 1, handler.getComponents().size() ); assertEquals( 1, handler.getComponents().size() );
assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ),
handler.getComponents().get( 0 ) ); handler.getComponents().get( 0 ) );
// Build an explicit list that includes the debug comp.
//-----------------------------------------------
names0 = new ArrayList<String>();
names0.add( FacetComponent.COMPONENT_NAME );
names0.add( DebugComponent.COMPONENT_NAME );
names0.add( MoreLikeThisComponent.COMPONENT_NAME );
args = new NamedList();
args.add( SearchHandler.INIT_COMPONENTS, names0 );
handler = new SearchHandler();
handler.init( args );
handler.inform( core );
assertEquals( 3, handler.getComponents().size() );
assertEquals( core.getSearchComponent( FacetComponent.COMPONENT_NAME ),
handler.getComponents().get( 0 ) );
assertEquals( core.getSearchComponent( DebugComponent.COMPONENT_NAME ),
handler.getComponents().get( 1 ) );
assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ),
handler.getComponents().get( 2 ) );
// First/Last list // First/Last list
@ -69,6 +90,8 @@ public class SearchHandlerTest extends AbstractSolrTestCase
List<SearchComponent> comps = handler.getComponents(); List<SearchComponent> comps = handler.getComponents();
assertEquals( 2+handler.getDefaultComponents().size(), comps.size() ); assertEquals( 2+handler.getDefaultComponents().size(), comps.size() );
assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), comps.get( 0 ) ); assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), comps.get( 0 ) );
assertEquals( core.getSearchComponent( FacetComponent.COMPONENT_NAME ), comps.get( comps.size()-1 ) ); assertEquals( core.getSearchComponent( FacetComponent.COMPONENT_NAME ), comps.get( comps.size()-2 ) );
//Debug component is always last in this case
assertEquals( core.getSearchComponent( DebugComponent.COMPONENT_NAME ), comps.get( comps.size()-1 ) );
} }
} }