You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by no...@apache.org on 2009/09/07 09:45:57 UTC

svn commit: r812023 - in /lucene/solr/trunk/src/java/org/apache/solr: core/RequestHandlers.java core/SolrConfig.java core/SolrCore.java handler/component/SpellCheckComponent.java highlight/DefaultSolrHighlighter.java

Author: noble
Date: Mon Sep  7 07:45:57 2009
New Revision: 812023

URL: http://svn.apache.org/viewvc?rev=812023&view=rev
Log:
SOLR-1198 moved all fields and getter methods to one map and a getter by classname

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
    lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
    lucene/solr/trunk/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
    lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java?rev=812023&r1=812022&r2=812023&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/RequestHandlers.java Mon Sep  7 07:45:57 2009
@@ -136,7 +136,7 @@
 
   void initHandlersFromConfig(SolrConfig config ){
     Map<PluginInfo,SolrRequestHandler> handlers = new HashMap<PluginInfo,SolrRequestHandler>();
-    for (PluginInfo info : config.getReqHandlerInfo()) {
+    for (PluginInfo info : config.getPluginInfos(SolrRequestHandler.class.getName())) {
       try {
         SolrRequestHandler requestHandler;
         if( info.startup != null ) {

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java?rev=812023&r1=812022&r2=812023&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java Mon Sep  7 07:45:57 2009
@@ -21,20 +21,28 @@
 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 @@
     }
      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 @@
 
   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 @@
             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<String, List<PluginInfo>> loadUpdateProcessorInfo() {
     HashMap<String, List<PluginInfo>> chains = new HashMap<String, List<PluginInfo>>();
     NodeList nodes = (NodeList) evaluate("updateRequestProcessorChain", XPathConstants.NODESET);
@@ -247,21 +250,15 @@
             Collections.<String, List<PluginInfo>>emptyMap():
             Collections.unmodifiableMap(chains);
   }
-  private PluginInfo loadSinglePlugin(String tag) {
-    List<PluginInfo> l = loadPluginInfo(tag, false, true);
-    return l.isEmpty() ? null : l.get(0);
-  }
 
-  private List<PluginInfo> loadPluginInfo(String tag, boolean requireName, boolean requireClass) {
+  private void loadPluginInfo(Class clazz, String tag, boolean requireName, boolean requireClass) {
     ArrayList<PluginInfo> result = new ArrayList<PluginInfo>();
     NodeList nodes = (NodeList) evaluate(tag, XPathConstants.NODESET);
      for (int i=0; i<nodes.getLength(); i++) {
        PluginInfo pluginInfo = new PluginInfo(nodes.item(i), "[solrconfig.xml] " + tag, requireName, requireClass);
        if(pluginInfo.isEnabled()) result.add(pluginInfo);
      }
-    return result.isEmpty() ?
-            Collections.<PluginInfo>emptyList() :
-            Collections.unmodifiableList(result) ;
+    if(!result.isEmpty()) pluginStore.put(clazz.getName(),result);
   }
 
   /* The set of materialized parameters: */
@@ -289,24 +286,16 @@
   public final SolrIndexConfig defaultIndexConfig;
   public final SolrIndexConfig mainIndexConfig;
 
-  protected List<PluginInfo> reqHandlerInfo;
-  protected List<PluginInfo> queryParserInfo;
-  protected List<PluginInfo> respWriterInfo;
-  protected List<PluginInfo> valueSourceParserInfo;
-  protected List<PluginInfo> searchComponentInfo;
-  protected List<PluginInfo> highlightingFragmenterInfo;
-  protected List<PluginInfo> highlightingFormatterInfo;
-  protected List<PluginInfo> firstSearcherListenerInfo;
-  protected PluginInfo deletionPolicyInfo;
-  protected PluginInfo indexReaderFactoryInfo;
-  protected List<PluginInfo> newSearcherListenerInfo;
-  protected List<PluginInfo> queryConverterInfo;
+//  protected PluginInfo deletionPolicyInfo;
+//  protected PluginInfo indexReaderFactoryInfo;
 
-  protected PluginInfo directoryfactoryInfo;
+//  protected PluginInfo directoryfactoryInfo;
   protected Map<String ,List<PluginInfo>> updateProcessorChainInfo ;
   protected UpdateHandlerInfo updateHandlerInfo ;
   protected String highLghtingClass;
 
+  private Map<String, List<PluginInfo>> pluginStore = new LinkedHashMap<String, List<PluginInfo>>();
+
   public final int maxWarmingSearchers;
   public final boolean unlockOnStartup;
   public final boolean useColdSearcher;
@@ -462,36 +451,27 @@
     } 
   }
 
-
-  public List<PluginInfo> getReqHandlerInfo() { return reqHandlerInfo; }
-
-  public List<PluginInfo> getQueryParserInfo() { return queryParserInfo; }
-
-  public List<PluginInfo> getRespWriterInfo() { return respWriterInfo; }
-
-  public List<PluginInfo> getValueSourceParserInfo() { return valueSourceParserInfo; }
-
-  public List<PluginInfo> getSearchComponentInfo() { return searchComponentInfo; }
-
-  public List<PluginInfo> getFirstSearcherListenerInfo() { return firstSearcherListenerInfo; }
-
-  public List<PluginInfo> getNewSearcherListenerInfo() { return newSearcherListenerInfo; }
-
-  public PluginInfo getDirectoryFactoryInfo() { return directoryfactoryInfo; }
-
-  public PluginInfo getDeletionPolicyInfo() { return deletionPolicyInfo; }
-
   public Map<String, List<PluginInfo>> getUpdateProcessorChainInfo() { return updateProcessorChainInfo; }
 
-  public List<PluginInfo> getQueryConverterInfo() { return queryConverterInfo; }
-
   public UpdateHandlerInfo getUpdateHandlerInfo() { return updateHandlerInfo; }
 
-  public PluginInfo getIndexReaderFactoryInfo() { return indexReaderFactoryInfo; }
-
-  public List<PluginInfo> getHighlightingFormatterInfo() { return highlightingFormatterInfo; }
-
-  public List<PluginInfo> 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<PluginInfo> getPluginInfos(String  type){
+    List<PluginInfo> result = pluginStore.get(type);
+    return result == null ?
+            (List<PluginInfo>) Collections.EMPTY_LIST:
+            result; 
+  }
+  public PluginInfo getPluginInfo(String  type){
+    List<PluginInfo> result = pluginStore.get(type);
+    return result == null || result.isEmpty() ? null: result.get(0);
+  }
 }

Modified: lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?rev=812023&r1=812022&r2=812023&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Mon Sep  7 07:45:57 2009
@@ -248,7 +248,7 @@
   }
 
    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 @@
      solrDelPolicy = new IndexDeletionPolicyWrapper(delPolicy);
    }
 
-  private List<SolrEventListener> parseListener(List<PluginInfo> path) {
-    List<SolrEventListener> lst = new ArrayList<SolrEventListener>();
-    for (PluginInfo info : path) {
+  private void initListeners() {
+    List<PluginInfo> l = solrConfig.getPluginInfos(SolrEventListener.class.getName());
+    firstSearcherListeners = new ArrayList<SolrEventListener>();
+    newSearcherListeners = new ArrayList<SolrEventListener>();
+    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<SolrEventListener> firstSearcherListeners;
   List<SolrEventListener> 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
    * <code>inform( SolrCore core )</code> function for <code>SolrCoreAware</code> classes.
@@ -328,7 +330,7 @@
 
    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 @@
 
   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 @@
 
     booleanQueryMaxClauseCount();
   
-    parseListeners();
+    initListeners();
 
     initDeletionPolicy();
 
@@ -817,7 +819,7 @@
   private Map<String, SearchComponent> loadSearchComponents()
   {
     Map<String, SearchComponent> components = new HashMap<String, SearchComponent>();
-    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 @@
   /** 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<String, QueryResponseWriter> entry : DEFAULT_RESPONSE_WRITERS.entrySet()) {
       if(responseWriters.get(entry.getKey()) == null) responseWriters.put(entry.getKey(), entry.getValue());
     }
@@ -1422,7 +1424,7 @@
 
   /** Configure the query parsers. */
   private void initQParsers() {
-    initPlugins(solrConfig.getQueryParserInfo(),qParserPlugins,QParserPlugin.class);
+    initPlugins(qParserPlugins,QParserPlugin.class);
     // default parsers
     for (int i=0; i<QParserPlugin.standardPlugins.length; i+=2) {
      try {
@@ -1449,7 +1451,7 @@
   
   /** Configure the ValueSource (function) plugins */
   private void initValueSourceParsers() {
-    initPlugins(solrConfig.getValueSourceParserInfo(),valueSourceParsers,ValueSourceParser.class);
+    initPlugins(valueSourceParsers,ValueSourceParser.class);
     // default value source parsers
     for (Map.Entry<String, ValueSourceParser> entry : ValueSourceParser.standardValueSourceParsers.entrySet()) {
       try {
@@ -1465,9 +1467,9 @@
     }
   }
 
-  public <T> T initPlugins(List<PluginInfo> pluginInfos , Map<String ,T> registry, Class<T> type){
+  public <T> T initPlugins(Map<String ,T> registry, Class<T> 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);

Modified: lucene/solr/trunk/src/java/org/apache/solr/handler/component/SpellCheckComponent.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/handler/component/SpellCheckComponent.java?rev=812023&r1=812022&r2=812023&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/handler/component/SpellCheckComponent.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/handler/component/SpellCheckComponent.java Mon Sep  7 07:45:57 2009
@@ -30,8 +30,6 @@
 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.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.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 @@
      }
 
       Map<String, QueryConverter> queryConverters = new HashMap<String, QueryConverter>();
-      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) {

Modified: lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java?rev=812023&r1=812022&r2=812023&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java Mon Sep  7 07:45:57 2009
@@ -64,7 +64,7 @@
     // 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 @@
     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);