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

@ -508,6 +508,8 @@ Bug Fixes
parameter after restarting Solr, if reload is called but build is not called.
(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
build scripts to make two jars: apache-solr-1.3.jar and

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")
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> list = null;
boolean makeDebugLast = true;
if( declaredComponents == null ) {
// Use the default component list
list = getDefaultComponents();
@ -100,16 +103,26 @@ 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<SearchComponent>( list.size() );
DebugComponent dbgCmp = null;
for(String c : list){
SearchComponent comp = core.getSearchComponent( c );
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);
}
}
public List<SearchComponent> getComponents() {
return components;

View File

@ -50,6 +50,27 @@ public class SearchHandlerTest extends AbstractSolrTestCase
assertEquals( core.getSearchComponent( MoreLikeThisComponent.COMPONENT_NAME ),
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
//-----------------------------------------------
@ -69,6 +90,8 @@ public class SearchHandlerTest extends AbstractSolrTestCase
List<SearchComponent> 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 ) );
}
}