lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r817223 - in /lucene/solr/trunk/src/java/org/apache/solr: core/SolrConfig.java core/SolrCore.java highlight/DefaultSolrHighlighter.java highlight/SolrHighlighter.java
Date Mon, 21 Sep 2009 12:23:39 GMT
Author: noble
Date: Mon Sep 21 12:23:38 2009
New Revision: 817223

URL: http://svn.apache.org/viewvc?rev=817223&view=rev
Log:
SOLR-1326 HighLighter also has a similar syntax

Modified:
    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/highlight/DefaultSolrHighlighter.java
    lucene/solr/trunk/src/java/org/apache/solr/highlight/SolrHighlighter.java

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=817223&r1=817222&r2=817223&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 21 12:23:38 2009
@@ -18,8 +18,6 @@
 package org.apache.solr.core;
 
 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;
@@ -34,8 +32,7 @@
 import org.apache.solr.update.SolrIndexConfig;
 import org.apache.solr.update.processor.UpdateRequestProcessorChain;
 import org.apache.solr.spelling.QueryConverter;
-import org.apache.solr.highlight.SolrFormatter;
-import org.apache.solr.highlight.SolrFragmenter;
+import org.apache.solr.highlight.SolrHighlighter;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.index.IndexDeletionPolicy;
 
@@ -48,8 +45,6 @@
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpressionException;
 
 import java.util.*;
 import java.util.regex.Pattern;
@@ -193,8 +188,8 @@
      loadPluginInfo(IndexDeletionPolicy.class,"mainIndex/deletionPolicy",false, true);
      loadPluginInfo(IndexReaderFactory.class,"indexReaderFactory",false, true);
      loadPluginInfo(UpdateRequestProcessorChain.class,"updateRequestProcessorChain",false,
false);
+     loadPluginInfo(SolrHighlighter.class,"highlighting",false, false);
      updateHandlerInfo = loadUpdatehandlerInfo();
-     loadHighLightingPlugins();
 
     Config.log.info("Loaded SolrConfig: " + name);
     
@@ -202,16 +197,6 @@
     config = this;
   }
 
-  public String getHighLghtingClass() {
-    return highLghtingClass;
-  }
-
-  protected void loadHighLightingPlugins() {
-    highLghtingClass =  get("highlighting/@class",null);
-    loadPluginInfo(SolrFormatter.class,"highlighting/formatter",true, true);
-    loadPluginInfo(SolrFragmenter.class,"highlighting/fragmenter",true, true);
-  }
-
   protected UpdateHandlerInfo loadUpdatehandlerInfo() {
     return new UpdateHandlerInfo(get("updateHandler/@class",null),
             getInt("updateHandler/autoCommit/maxDocs",-1),
@@ -255,7 +240,6 @@
   public final SolrIndexConfig mainIndexConfig;
 
   protected UpdateHandlerInfo updateHandlerInfo ;
-  protected String highLghtingClass;
 
   private Map<String, List<PluginInfo>> pluginStore = new LinkedHashMap<String,
List<PluginInfo>>();
 

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=817223&r1=817222&r2=817223&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 21 12:23:38 2009
@@ -551,10 +551,7 @@
     reqHandlers = new RequestHandlers(this);
     reqHandlers.initHandlersFromConfig( solrConfig );
 
-    String highLightClass = solrConfig.getHighLghtingClass();
-  
-    highlighter = createHighlighter(highLightClass == null? DefaultSolrHighlighter.class.getName()
: highLightClass);
-    highlighter.initalize( solrConfig );
+    highlighter = initHighLighter();
 
     // Handle things that should eventually go away
     initDeprecatedSupport();
@@ -596,6 +593,19 @@
     infoRegistry.put("core", this);
   }
 
+  private SolrHighlighter initHighLighter() {
+    SolrHighlighter highlighter = null;
+    PluginInfo pluginInfo = solrConfig.getPluginInfo(SolrHighlighter.class.getName());
+    if(pluginInfo != null){
+      highlighter = createInitInstance(pluginInfo,SolrHighlighter.class,null, DefaultSolrHighlighter.class.getName());
+      highlighter.initalize(solrConfig);
+    } else{
+      highlighter = new DefaultSolrHighlighter();
+      highlighter.initalize(solrConfig);
+    }
+    return highlighter;
+  }
+
 
   /**
    * Load the request processors
@@ -1457,8 +1467,12 @@
   }
 
   public <T> T initPlugins(Map<String ,T> registry, Class<T> type, String
defClassName){
+    return initPlugins(solrConfig.getPluginInfos(type.getName()), registry, type, defClassName);
+  }
+
+  public <T> T initPlugins(List<PluginInfo> pluginInfos, Map<String, T>
registry, Class<T> type, String defClassName) {
     T def = null;
-    for (PluginInfo info : solrConfig.getPluginInfos(type.getName())) {
+    for (PluginInfo info : pluginInfos) {
       T o = createInitInstance(info,type, type.getSimpleName(), defClassName);
       if (o instanceof PluginInfoInitialized) {
         ((PluginInfoInitialized) o).init(info);

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=817223&r1=817222&r2=817223&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
21 12:23:38 2009
@@ -43,52 +43,66 @@
 import org.apache.solr.common.util.SimpleOrderedMap;
 import org.apache.solr.core.SolrConfig;
 import org.apache.solr.core.PluginInfo;
+import org.apache.solr.core.SolrCore;
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.DocIterator;
 import org.apache.solr.search.DocList;
 import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.plugin.PluginInfoInitialized;
 
 /**
  * 
  * @since solr 1.3
  */
-public class DefaultSolrHighlighter extends SolrHighlighter
+public class DefaultSolrHighlighter extends SolrHighlighter implements PluginInfoInitialized
 {
 
-  public void initalize( SolrConfig config) {
+  private SolrCore solrCore;
+
+  public DefaultSolrHighlighter() {
+  }
+
+  public DefaultSolrHighlighter(SolrCore solrCore) {
+    this.solrCore = solrCore;
+  }
+
+  public void init(PluginInfo info) {
     formatters.clear();
     fragmenters.clear();
 
+    List<PluginInfo> fragmenterInfo = new ArrayList<PluginInfo>();
+    List<PluginInfo> formatterrInfo = new ArrayList<PluginInfo>();
     // Load the fragmenters
-    ResourceLoader loader= config.getResourceLoader();
-    SolrFragmenter frag = null;
-    for (PluginInfo info : config.getPluginInfos(SolrFragmenter.class.getName())) {
-      SolrFragmenter fragmenter = (SolrFragmenter) loader.newInstance(info.className);
-      fragmenter.init(info.initArgs);
-      if(info.isDefault()) frag = fragmenter;
-      fragmenters.put(info.name,fragmenter);
+    for (PluginInfo child : info.children) {
+      if("fragmenter".equals(child.type)) fragmenterInfo.add(child);
+      if("formatter".equals(child.type)) formatterrInfo.add(child);
     }
-
-    if( frag == null ) {
-      frag = new GapFragmenter();
-    }
-    fragmenters.put( "", frag );
-    fragmenters.put( null, frag );
+    SolrFragmenter frag = solrCore.initPlugins(fragmenterInfo, fragmenters,SolrFragmenter.class,null);
+    if (frag == null) frag = new GapFragmenter();
+    fragmenters.put("", frag);
+    fragmenters.put(null, frag);
     // Load the formatters
-    SolrFormatter fmt = null;
-    for (PluginInfo info : config.getPluginInfos(SolrFormatter.class.getName())) {
-      SolrFormatter formatter = (SolrFormatter) loader.newInstance(info.className);
-      formatter.init(info.initArgs);
-      formatters.put(info.name, formatter);
-      if(info.isDefault()) fmt = formatter;
-    }
-    if( fmt == null ) {
-      fmt = new HtmlFormatter();
-    }
-    formatters.put( "", fmt );
-    formatters.put( null, fmt );
+    SolrFormatter fmt = solrCore.initPlugins(formatterrInfo, formatters,SolrFormatter.class,null);
+    if (fmt == null) fmt = new HtmlFormatter();
+    formatters.put("", fmt);
+    formatters.put(null, fmt);
+    initialized = true;
+
+  }
+  private boolean initialized = false;
+  @Deprecated
+  public void initalize( SolrConfig config) {
+    if (initialized) return;
+    SolrFragmenter frag = new GapFragmenter();
+    fragmenters.put("", frag);
+    fragmenters.put(null, frag);
+
+    SolrFormatter fmt = new HtmlFormatter();
+    formatters.put("", fmt);
+    formatters.put(null, fmt);    
+
 
   }
 

Modified: lucene/solr/trunk/src/java/org/apache/solr/highlight/SolrHighlighter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/highlight/SolrHighlighter.java?rev=817223&r1=817222&r2=817223&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/highlight/SolrHighlighter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/highlight/SolrHighlighter.java Mon Sep 21 12:23:38
2009
@@ -46,6 +46,7 @@
   // Thread safe registry
   protected final Map<String,SolrFragmenter> fragmenters =
     Collections.synchronizedMap( new HashMap<String, SolrFragmenter>() );
+  @Deprecated
   public abstract void initalize( SolrConfig config );
 
 



Mime
View raw message