Apache Lucene open-source search software
SOLR-1198 moved searchComponent, indexreaderFactory
Noble Paul42c9350e9cae
diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.javaindex 755465daff2..466afe40630 100644--- a/src/java/org/apache/solr/core/SolrConfig.java+++ b/src/java/org/apache/solr/core/SolrConfig.java@@ -195,10 +195,9 @@ public class SolrConfig extends Config {valueSourceParserInfo = loadPluginInfo("valueSourceParser",true);queryParserInfo = loadPluginInfo("queryParser",true);searchComponentInfo = loadPluginInfo("searchComponent",true);- List<PluginInfo> plugins = loadPluginInfo("directoryFactory",true);- directoryfactoryInfo = plugins.isEmpty() ? null:plugins.get(0);- plugins = loadPluginInfo("mainIndex/deletionPolicy",false);- deletionPolicyInfo = plugins.isEmpty() ? null : plugins.get(0);+ directoryfactoryInfo = loadSinglePlugin("directoryFactory");+ deletionPolicyInfo = loadSinglePlugin("mainIndex/deletionPolicy");+ indexReaderFactoryInfo = loadSinglePlugin("indexReaderFactory");firstSearcherListenerInfo = loadPluginInfo("//listener[@event='firstSearcher']",false);newSearcherListenerInfo = loadPluginInfo("//listener[@event='newSearcher']",false);}@@ -232,6 +231,13 @@ public class SolrConfig extends Config {return Collections.unmodifiableMap(chains);}+ private PluginInfo loadSinglePlugin(String tag){+ NodeList nodes = (NodeList) evaluate(tag, XPathConstants.NODESET);+ for (int i=0; i<nodes.getLength(); i++) {+ return new PluginInfo(nodes.item(i) ,"[solrconfig.xml] "+tag,false);+ }+ return null;+ }private List<PluginInfo> loadPluginInfo(String tag, boolean requireName) {ArrayList<PluginInfo> result = new ArrayList<PluginInfo>();@@ -274,6 +280,7 @@ public class SolrConfig extends Config {protected List<PluginInfo> searchComponentInfo;protected List<PluginInfo> firstSearcherListenerInfo;protected PluginInfo deletionPolicyInfo;+ protected PluginInfo indexReaderFactoryInfo;protected List<PluginInfo> newSearcherListenerInfo;protected PluginInfo directoryfactoryInfo;protected Map<String ,List<PluginInfo>> updateProcessorChainInfo ;@@ -510,4 +517,6 @@ public class SolrConfig extends Config {public Map<String, List<PluginInfo>> getUpdateProcessorChainInfo() { return updateProcessorChainInfo; }public UpdateHandlerInfo getUpdateHandlerInfo() { return updateHandlerInfo; }++ public PluginInfo getIndexReaderFactoryInfo() { return indexReaderFactoryInfo; }}diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.javaindex e3449eb524c..2e0ca325f68 100644--- a/src/java/org/apache/solr/core/SolrCore.java+++ b/src/java/org/apache/solr/core/SolrCore.java@@ -348,20 +348,14 @@ public final class SolrCore implements SolrInfoMBean {}private void initIndexReaderFactory() {- String xpath = "indexReaderFactory";- Node node = (Node) solrConfig.evaluate(xpath, XPathConstants.NODE);IndexReaderFactory indexReaderFactory;- if (node != null) {- Map<String, IndexReaderFactory> registry = new HashMap<String, IndexReaderFactory>();- NamedListPluginLoader<IndexReaderFactory> indexReaderFactoryLoader = new NamedListPluginLoader<IndexReaderFactory>(- "[solrconfig.xml] " + xpath, registry);-- indexReaderFactory = indexReaderFactoryLoader.loadSingle(solrConfig- .getResourceLoader(), node);+ SolrConfig.PluginInfo info = solrConfig.getIndexReaderFactoryInfo();+ if (info != null) {+ indexReaderFactory = (IndexReaderFactory) resourceLoader.newInstance(info.className);+ indexReaderFactory.init(info.initArgs);} else {indexReaderFactory = new StandardIndexReaderFactory();- }-+ }this.indexReaderFactory = indexReaderFactory;}@@ -419,11 +413,11 @@ public final class SolrCore implements SolrInfoMBean {private <T extends Object> T createInstance(String className, Class<T> cast, String msg) {Class clazz = null;if (msg == null) msg = "SolrCore Object";- try {+ try {clazz = getResourceLoader().findClass(className);if (cast != null && !cast.isAssignableFrom(clazz))throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Error Instantiating "+msg+", "+className+ " is not a " +cast.getName());- //most of the classes do not have constructors whiuch take in SolrCore. It is recommended to obtain SolrCore by implementing SolrCoreAare.+ //most of the classes do not have constructors which takes SolrCore argument. It is recommended to obtain SolrCore by implementing SolrCoreAware.// So invariably always it will cause a NoSuchMethodException. So iterate though the list of available constructorsConstructor[] cons = clazz.getConstructors();for (Constructor con : cons) {@@ -432,7 +426,7 @@ public final class SolrCore implements SolrInfoMBean {return (T)con.newInstance(this);}}- return (T) clazz.newInstance();//use the empty constructor+ return (T) getResourceLoader().newInstance(className);//use the empty constructor} catch (SolrException e) {throw e;} catch (Exception e) {@@ -823,34 +817,25 @@ public final class SolrCore implements SolrInfoMBean {private Map<String, SearchComponent> loadSearchComponents(){Map<String, SearchComponent> components = new HashMap<String, SearchComponent>();-- String xpath = "searchComponent";- NamedListPluginLoader<SearchComponent> loader = new NamedListPluginLoader<SearchComponent>( xpath, components );- loader.load( solrConfig.getResourceLoader(), (NodeList)solrConfig.evaluate( xpath, XPathConstants.NODESET ) );-- final Map<String,Class<? extends SearchComponent>> standardcomponents- = new HashMap<String, Class<? extends SearchComponent>>();- standardcomponents.put( QueryComponent.COMPONENT_NAME, QueryComponent.class );- standardcomponents.put( FacetComponent.COMPONENT_NAME, FacetComponent.class );- standardcomponents.put( MoreLikeThisComponent.COMPONENT_NAME, MoreLikeThisComponent.class );- standardcomponents.put( HighlightComponent.COMPONENT_NAME, HighlightComponent.class );- standardcomponents.put( StatsComponent.COMPONENT_NAME, StatsComponent.class );- standardcomponents.put( DebugComponent.COMPONENT_NAME, DebugComponent.class );- for( Map.Entry<String, Class<? extends SearchComponent>> entry : standardcomponents.entrySet() ) {- if( components.get( entry.getKey() ) == null ) {- try {- SearchComponent comp = entry.getValue().newInstance();- comp.init( null ); // default components initialized with nothing- components.put( entry.getKey(), comp );- }- catch (Exception e) {- SolrConfig.severeErrors.add( e );- SolrException.logOnce(log,null,e);- }- }+ // there is something strange which makes the tests fail when the instance is created using SolrCore#createInstance+ for (SolrConfig.PluginInfo info : solrConfig.getSearchComponentInfo()) {+ SearchComponent sc = (SearchComponent) resourceLoader.newInstance(info.className);+ sc.init(info.initArgs);+ components.put(info.name, sc);}+ addIfNotPresent(components,QueryComponent.COMPONENT_NAME,QueryComponent.class);+ addIfNotPresent(components,FacetComponent.COMPONENT_NAME,FacetComponent.class);+ addIfNotPresent(components,MoreLikeThisComponent.COMPONENT_NAME,MoreLikeThisComponent.class);+ addIfNotPresent(components,HighlightComponent.COMPONENT_NAME,HighlightComponent.class);+ addIfNotPresent(components,StatsComponent.COMPONENT_NAME,StatsComponent.class);+ addIfNotPresent(components,DebugComponent.COMPONENT_NAME,DebugComponent.class);return components;}+ private <T> void addIfNotPresent(Map<String ,T> registry, String name, Class<? extends T> c){+ if(!registry.containsKey(name)){+ registry.put(name, (T) resourceLoader.newInstance(c.getName()));+ }+ }/*** @return a Search Component registered to a given name. Throw an exception if the component is undefined@@ -1493,8 +1478,7 @@ public final class SolrCore implements SolrInfoMBean {registry.put(info.name, o);if(info.isDefault){def = o;- }-+ }}return def;}