SOLR-1326 HighLighter also has a similar syntax

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@817223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Noble Paul 2009-09-21 12:23:38 +00:00
parent 1379854e5e
commit d19802603d
4 changed files with 63 additions and 50 deletions

View File

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

View File

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

View File

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

View File

@ -46,6 +46,7 @@ public abstract class SolrHighlighter
// Thread safe registry // Thread safe registry
protected final Map<String,SolrFragmenter> fragmenters = protected final Map<String,SolrFragmenter> fragmenters =
Collections.synchronizedMap( new HashMap<String, SolrFragmenter>() ); Collections.synchronizedMap( new HashMap<String, SolrFragmenter>() );
@Deprecated
public abstract void initalize( SolrConfig config ); public abstract void initalize( SolrConfig config );