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;
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.search.ValueSourceParser;
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 org.xml.sax.SAXException;
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 @@ public class SolrConfig extends Config {
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 @@ public class SolrConfig extends Config {
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 class SolrConfig extends Config {
public final SolrIndexConfig mainIndexConfig;
protected UpdateHandlerInfo updateHandlerInfo ;
protected String highLghtingClass;
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.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 @@ public final class SolrCore implements SolrInfoMBean {
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 final class SolrCore implements SolrInfoMBean {
}
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);

View File

@ -43,52 +43,66 @@ 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.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);
}

View File

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