diff --git a/CHANGES.txt b/CHANGES.txt index 8ca6fb5da56..fbcf59fab21 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -506,7 +506,9 @@ Bug Fixes 43. SOLR-648: SpellCheckComponent throws NullPointerException on using spellcheck.q request 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 1. SOLR-135: Moved common classes to org.apache.solr.common and altered the diff --git a/src/java/org/apache/solr/handler/component/SearchHandler.java b/src/java/org/apache/solr/handler/component/SearchHandler.java index 82afc618705..2742718009f 100644 --- a/src/java/org/apache/solr/handler/component/SearchHandler.java +++ b/src/java/org/apache/solr/handler/component/SearchHandler.java @@ -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") public void inform(SolrCore core) @@ -80,6 +82,7 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware List last = (List) initArgs.get(INIT_LAST_COMPONENTS); List list = null; + boolean makeDebugLast = true; if( declaredComponents == null ) { // Use the default component list list = getDefaultComponents(); @@ -100,14 +103,24 @@ public class SearchHandler extends RequestHandlerBase implements SolrCoreAware throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "First/Last components only valid if you do not declare 'components'"); } + makeDebugLast = false; } // Build the component list components = new ArrayList( list.size() ); + DebugComponent dbgCmp = null; for(String c : list){ SearchComponent comp = core.getSearchComponent( c ); - components.add(comp); - log.info("Adding component:"+comp); + if (comp instanceof DebugComponent && makeDebugLast == true){ + 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); } } diff --git a/src/test/org/apache/solr/handler/component/SearchHandlerTest.java b/src/test/org/apache/solr/handler/component/SearchHandlerTest.java index 8ed2f8090f8..a1d645f3604 100644 --- a/src/test/org/apache/solr/handler/component/SearchHandlerTest.java +++ b/src/test/org/apache/solr/handler/component/SearchHandlerTest.java @@ -49,6 +49,27 @@ public class SearchHandlerTest extends AbstractSolrTestCase assertEquals( 1, handler.getComponents().size() ); assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ), handler.getComponents().get( 0 ) ); + + // Build an explicit list that includes the debug comp. + //----------------------------------------------- + names0 = new ArrayList(); + 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 @@ -69,6 +90,8 @@ public class SearchHandlerTest extends AbstractSolrTestCase List comps = handler.getComponents(); assertEquals( 2+handler.getDefaultComponents().size(), comps.size() ); 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 ) ); } }