From 4d9906400f5ade727334f8ad6616e870f8481b3f Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Mon, 7 Sep 2009 07:45:57 +0000 Subject: [PATCH] SOLR-1198 moved all fields and getter methods to one map and a getter by classname git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@812023 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/solr/core/RequestHandlers.java | 2 +- src/java/org/apache/solr/core/SolrConfig.java | 112 +++++++----------- src/java/org/apache/solr/core/SolrCore.java | 42 +++---- .../component/SpellCheckComponent.java | 7 +- .../highlight/DefaultSolrHighlighter.java | 4 +- 5 files changed, 72 insertions(+), 95 deletions(-) diff --git a/src/java/org/apache/solr/core/RequestHandlers.java b/src/java/org/apache/solr/core/RequestHandlers.java index 37ec3554a4a..1b86d31e5ef 100644 --- a/src/java/org/apache/solr/core/RequestHandlers.java +++ b/src/java/org/apache/solr/core/RequestHandlers.java @@ -136,7 +136,7 @@ final class RequestHandlers { void initHandlersFromConfig(SolrConfig config ){ Map handlers = new HashMap(); - for (PluginInfo info : config.getReqHandlerInfo()) { + for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName())) { try { SolrRequestHandler requestHandler; if( info.startup != null ) { diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.java index be0364800e2..fd270486ebb 100644 --- a/src/java/org/apache/solr/core/SolrConfig.java +++ b/src/java/org/apache/solr/core/SolrConfig.java @@ -21,20 +21,28 @@ import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.DOMUtil; import org.apache.solr.common.SolrException; import org.apache.solr.handler.PingRequestHandler; +import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.request.SolrRequestHandler; +import org.apache.solr.request.QueryResponseWriter; import org.apache.solr.search.CacheConfig; import org.apache.solr.search.FastLRUCache; +import org.apache.solr.search.QParserPlugin; +import org.apache.solr.search.ValueSourceParser; import org.apache.solr.update.SolrIndexConfig; +import org.apache.solr.spelling.QueryConverter; +import org.apache.solr.highlight.SolrFormatter; +import org.apache.solr.highlight.SolrFragmenter; import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.index.IndexDeletionPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.w3c.dom.NamedNodeMap; import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; @@ -173,7 +181,16 @@ public class SolrConfig extends Config { } maxWarmingSearchers = getInt("query/maxWarmingSearchers",Integer.MAX_VALUE); - loadPluginInfo(); + loadPluginInfo(SolrRequestHandler.class,"requestHandler",true, true); + loadPluginInfo(QParserPlugin.class,"queryParser",true, true); + loadPluginInfo(QueryResponseWriter.class,"queryResponseWriter",true, true); + loadPluginInfo(ValueSourceParser.class,"valueSourceParser",true, true); + loadPluginInfo(SearchComponent.class,"searchComponent",true, true); + loadPluginInfo(QueryConverter.class,"queryConverter",true, true); + loadPluginInfo(SolrEventListener.class, "//listener",false, true); + loadPluginInfo(DirectoryFactory.class,"directoryFactory",false, true); + loadPluginInfo(IndexDeletionPolicy.class,"mainIndex/deletionPolicy",false, true); + loadPluginInfo(IndexReaderFactory.class,"indexReaderFactory",false, true); updateProcessorChainInfo = loadUpdateProcessorInfo(); updateHandlerInfo = loadUpdatehandlerInfo(); loadHighLightingPlugins(); @@ -190,8 +207,8 @@ public class SolrConfig extends Config { protected void loadHighLightingPlugins() { highLghtingClass = get("highlighting/@class",null); - highlightingFragmenterInfo = loadPluginInfo("highlighting/fragmenter",true,true); - highlightingFormatterInfo = loadPluginInfo("highlighting/formatter",true, true); + loadPluginInfo(SolrFormatter.class,"highlighting/formatter",true, true); + loadPluginInfo(SolrFragmenter.class,"highlighting/fragmenter",true, true); } protected UpdateHandlerInfo loadUpdatehandlerInfo() { @@ -201,20 +218,6 @@ public class SolrConfig extends Config { getInt("updateHandler/commitIntervalLowerBound",-1)); } - protected void loadPluginInfo() { - reqHandlerInfo = loadPluginInfo("requestHandler",true, true); - respWriterInfo = loadPluginInfo("queryResponseWriter",true, true); - valueSourceParserInfo = loadPluginInfo("valueSourceParser",true, true); - queryParserInfo = loadPluginInfo("queryParser",true, true); - searchComponentInfo = loadPluginInfo("searchComponent",true, true); - queryConverterInfo = loadPluginInfo("queryConverter",true, true); - directoryfactoryInfo = loadSinglePlugin("directoryFactory"); - deletionPolicyInfo = loadSinglePlugin("mainIndex/deletionPolicy"); - indexReaderFactoryInfo = loadSinglePlugin("indexReaderFactory"); - firstSearcherListenerInfo = loadPluginInfo("//listener[@event='firstSearcher']",false, true); - newSearcherListenerInfo = loadPluginInfo("//listener[@event='newSearcher']",false, true); - } - protected Map> loadUpdateProcessorInfo() { HashMap> chains = new HashMap>(); NodeList nodes = (NodeList) evaluate("updateRequestProcessorChain", XPathConstants.NODESET); @@ -247,21 +250,15 @@ public class SolrConfig extends Config { Collections.>emptyMap(): Collections.unmodifiableMap(chains); } - private PluginInfo loadSinglePlugin(String tag) { - List l = loadPluginInfo(tag, false, true); - return l.isEmpty() ? null : l.get(0); - } - private List loadPluginInfo(String tag, boolean requireName, boolean requireClass) { + private void loadPluginInfo(Class clazz, String tag, boolean requireName, boolean requireClass) { ArrayList result = new ArrayList(); NodeList nodes = (NodeList) evaluate(tag, XPathConstants.NODESET); for (int i=0; iemptyList() : - Collections.unmodifiableList(result) ; + if(!result.isEmpty()) pluginStore.put(clazz.getName(),result); } /* The set of materialized parameters: */ @@ -289,24 +286,16 @@ public class SolrConfig extends Config { public final SolrIndexConfig defaultIndexConfig; public final SolrIndexConfig mainIndexConfig; - protected List reqHandlerInfo; - protected List queryParserInfo; - protected List respWriterInfo; - protected List valueSourceParserInfo; - protected List searchComponentInfo; - protected List highlightingFragmenterInfo; - protected List highlightingFormatterInfo; - protected List firstSearcherListenerInfo; - protected PluginInfo deletionPolicyInfo; - protected PluginInfo indexReaderFactoryInfo; - protected List newSearcherListenerInfo; - protected List queryConverterInfo; +// protected PluginInfo deletionPolicyInfo; +// protected PluginInfo indexReaderFactoryInfo; - protected PluginInfo directoryfactoryInfo; +// protected PluginInfo directoryfactoryInfo; protected Map> updateProcessorChainInfo ; protected UpdateHandlerInfo updateHandlerInfo ; protected String highLghtingClass; + private Map> pluginStore = new LinkedHashMap>(); + public final int maxWarmingSearchers; public final boolean unlockOnStartup; public final boolean useColdSearcher; @@ -462,36 +451,27 @@ public class SolrConfig extends Config { } } - - public List getReqHandlerInfo() { return reqHandlerInfo; } - - public List getQueryParserInfo() { return queryParserInfo; } - - public List getRespWriterInfo() { return respWriterInfo; } - - public List getValueSourceParserInfo() { return valueSourceParserInfo; } - - public List getSearchComponentInfo() { return searchComponentInfo; } - - public List getFirstSearcherListenerInfo() { return firstSearcherListenerInfo; } - - public List getNewSearcherListenerInfo() { return newSearcherListenerInfo; } - - public PluginInfo getDirectoryFactoryInfo() { return directoryfactoryInfo; } - - public PluginInfo getDeletionPolicyInfo() { return deletionPolicyInfo; } - public Map> getUpdateProcessorChainInfo() { return updateProcessorChainInfo; } - public List getQueryConverterInfo() { return queryConverterInfo; } - public UpdateHandlerInfo getUpdateHandlerInfo() { return updateHandlerInfo; } - public PluginInfo getIndexReaderFactoryInfo() { return indexReaderFactoryInfo; } - - public List getHighlightingFormatterInfo() { return highlightingFormatterInfo; } - - public List getHighlightingFragmenterInfo() { return highlightingFragmenterInfo; } - public String getDataDir() { return dataDir; } + + /**SolrConfig keeps a repository of plugins by the type. The known interfaces are the types. + * @param type The key is FQN of the plugin class there are a few known types : SolrFormatter, SolrFragmenter + * SolrRequestHandler,QParserPlugin, QueryResponseWriter,ValueSourceParser, + * SearchComponent, QueryConverter, SolrEventListener, DirectoryFactory, + * IndexDeletionPolicy, IndexReaderFactory + * @return + */ + public List getPluginInfos(String type){ + List result = pluginStore.get(type); + return result == null ? + (List) Collections.EMPTY_LIST: + result; + } + public PluginInfo getPluginInfo(String type){ + List result = pluginStore.get(type); + return result == null || result.isEmpty() ? null: result.get(0); + } } diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java index 4e118289850..3827ef99153 100644 --- a/src/java/org/apache/solr/core/SolrCore.java +++ b/src/java/org/apache/solr/core/SolrCore.java @@ -248,7 +248,7 @@ public final class SolrCore implements SolrInfoMBean { } private void initDeletionPolicy() { - PluginInfo info = solrConfig.getDeletionPolicyInfo(); + PluginInfo info = solrConfig.getPluginInfo(IndexDeletionPolicy.class.getName()); IndexDeletionPolicy delPolicy = null; if(info != null){ delPolicy = createInstance(info.className,IndexDeletionPolicy.class,"Deletion Policy for SOLR"); @@ -261,24 +261,26 @@ public final class SolrCore implements SolrInfoMBean { solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy); } - private List parseListener(List path) { - List lst = new ArrayList(); - for (PluginInfo info : path) { + private void initListeners() { + List l = solrConfig.getPluginInfos(SolrEventListener.class.getName()); + firstSearcherListeners = new ArrayList(); + newSearcherListeners = new ArrayList(); + for (PluginInfo info : l) { SolrEventListener listener = createEventListener(info.className); listener.init(info.initArgs); - lst.add(listener); + String event = info.attributes.get("event"); + if("firstSearcher".equals(event) ){ + firstSearcherListeners.add(listener); + } else if("newSearcher".equals(event) ){ + newSearcherListeners.add(listener); + } log.info(logid + "Added SolrEventListener: " + listener); } - return lst; } List firstSearcherListeners; List newSearcherListeners; - private void parseListeners() { - firstSearcherListeners = parseListener(solrConfig.getFirstSearcherListenerInfo()); - newSearcherListeners = parseListener(solrConfig.getNewSearcherListenerInfo()); - } - + /** * NOTE: this function is not thread safe. However, it is safe to call within the * inform( SolrCore core ) function for SolrCoreAware classes. @@ -328,7 +330,7 @@ public final class SolrCore implements SolrInfoMBean { private void initDirectoryFactory() { DirectoryFactory dirFactory; - PluginInfo info = solrConfig.getDirectoryFactoryInfo(); + PluginInfo info = solrConfig.getPluginInfo(DirectoryFactory.class.getName()); if (info != null) { dirFactory = (DirectoryFactory) getResourceLoader().newInstance(info.className); dirFactory.init(info.initArgs); @@ -341,7 +343,7 @@ public final class SolrCore implements SolrInfoMBean { private void initIndexReaderFactory() { IndexReaderFactory indexReaderFactory; - PluginInfo info = solrConfig.getIndexReaderFactoryInfo(); + PluginInfo info = solrConfig.getPluginInfo(IndexReaderFactory.class.getName()); if (info != null) { indexReaderFactory = (IndexReaderFactory) resourceLoader.newInstance(info.className); indexReaderFactory.init(info.initArgs); @@ -521,7 +523,7 @@ public final class SolrCore implements SolrInfoMBean { booleanQueryMaxClauseCount(); - parseListeners(); + initListeners(); initDeletionPolicy(); @@ -817,7 +819,7 @@ public final class SolrCore implements SolrInfoMBean { private Map loadSearchComponents() { Map components = new HashMap(); - initPlugins(solrConfig.getSearchComponentInfo(),components,SearchComponent.class); + initPlugins(components,SearchComponent.class); addIfNotPresent(components,QueryComponent.COMPONENT_NAME,QueryComponent.class); addIfNotPresent(components,FacetComponent.COMPONENT_NAME,FacetComponent.class); addIfNotPresent(components,MoreLikeThisComponent.COMPONENT_NAME,MoreLikeThisComponent.class); @@ -1388,7 +1390,7 @@ public final class SolrCore implements SolrInfoMBean { /** Configure the query response writers. There will always be a default writer; additional * writers may also be configured. */ private void initWriters() { - defaultResponseWriter = initPlugins(solrConfig.getRespWriterInfo(), responseWriters, QueryResponseWriter.class); + defaultResponseWriter = initPlugins(responseWriters, QueryResponseWriter.class); for (Map.Entry entry : DEFAULT_RESPONSE_WRITERS.entrySet()) { if(responseWriters.get(entry.getKey()) == null) responseWriters.put(entry.getKey(), entry.getValue()); } @@ -1422,7 +1424,7 @@ public final class SolrCore implements SolrInfoMBean { /** Configure the query parsers. */ private void initQParsers() { - initPlugins(solrConfig.getQueryParserInfo(),qParserPlugins,QParserPlugin.class); + initPlugins(qParserPlugins,QParserPlugin.class); // default parsers for (int i=0; i entry : ValueSourceParser.standardValueSourceParsers.entrySet()) { try { @@ -1465,9 +1467,9 @@ public final class SolrCore implements SolrInfoMBean { } } - public T initPlugins(List pluginInfos , Map registry, Class type){ + public T initPlugins(Map registry, Class type){ T def = null; - for (PluginInfo info : pluginInfos) { + for (PluginInfo info : solrConfig.getPluginInfos(type.getName())) { T o = createInstance(info.className,type, type.getSimpleName()); if (o instanceof NamedListInitializedPlugin) { ((NamedListInitializedPlugin) o).init(info.initArgs); diff --git a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java index 6e732cf330e..1a8a8a44c80 100644 --- a/src/java/org/apache/solr/handler/component/SpellCheckComponent.java +++ b/src/java/org/apache/solr/handler/component/SpellCheckComponent.java @@ -30,8 +30,6 @@ import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.xml.xpath.XPathConstants; - import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Token; import org.apache.lucene.analysis.TokenStream; @@ -43,7 +41,6 @@ import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SpellingParams; import org.apache.solr.common.util.NamedList; import org.apache.solr.common.util.SimpleOrderedMap; -import org.apache.solr.core.SolrConfig; import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrEventListener; import org.apache.solr.core.SolrResourceLoader; @@ -51,9 +48,7 @@ import org.apache.solr.schema.FieldType; import org.apache.solr.schema.IndexSchema; import org.apache.solr.search.SolrIndexSearcher; import org.apache.solr.spelling.*; -import org.apache.solr.util.plugin.NamedListPluginLoader; import org.apache.solr.util.plugin.SolrCoreAware; -import org.w3c.dom.NodeList; /** * A SearchComponent implementation which provides support for spell checking @@ -295,7 +290,7 @@ public class SpellCheckComponent extends SearchComponent implements SolrCoreAwar } Map queryConverters = new HashMap(); - core.initPlugins(core.getSolrConfig().getQueryConverterInfo(), queryConverters,QueryConverter.class); + core.initPlugins(queryConverters,QueryConverter.class); //ensure that there is at least one query converter defined if (queryConverters.size() == 0) { diff --git a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java index 5e2cfa88317..62ed4965e20 100644 --- a/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java +++ b/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java @@ -64,7 +64,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter // Load the fragmenters ResourceLoader loader= config.getResourceLoader(); SolrFragmenter frag = null; - for (PluginInfo info : config.getHighlightingFragmenterInfo()) { + for (PluginInfo info : config.getPluginInfos(SolrFragmenter.class.getName())) { SolrFragmenter fragmenter = (SolrFragmenter) loader.newInstance(info.className); fragmenter.init(info.initArgs); if(info.isDefault) frag = fragmenter; @@ -78,7 +78,7 @@ public class DefaultSolrHighlighter extends SolrHighlighter fragmenters.put( null, frag ); // Load the formatters SolrFormatter fmt = null; - for (PluginInfo info : config.getHighlightingFormatterInfo()) { + for (PluginInfo info : config.getPluginInfos(SolrFormatter.class.getName())) { SolrFormatter formatter = (SolrFormatter) loader.newInstance(info.className); formatter.init(info.initArgs); formatters.put(info.name, formatter);