From 70ab45ce2d78cce6a11966a4a72f42a6d16f2da4 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Mon, 27 Oct 2008 18:10:45 +0000 Subject: [PATCH] SOLR-813: Deprecate access to SolrConfig from IndexSchema. Rather then access SolrConfig from the schema, plugins should get the config from the core. IndexSchema still has access to the ResourceLoader. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@708259 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 5 ++++ .../solr/request/XSLTResponseWriter.java | 2 +- .../org/apache/solr/schema/IndexSchema.java | 30 ++++++++++++------- .../apache/solr/search/SolrIndexSearcher.java | 2 +- .../apache/solr/update/SolrIndexWriter.java | 4 +-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2715096a73b..98b9e23b528 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -73,6 +73,11 @@ New Features 11. SOLR-651: Added TermVectorComponent for serving up term vector information, plus IDF. See http://wiki.apache.org/solr/TermVectorComponent (gsingers, Vaijanath N. Rao, Noble Paul) +12. SOLR-813: Deprecate access to SolrConfig from IndexSchema. Rather then access + SolrConfig from the schema, plugins should get the config from the core. IndexSchema + still has access to the ResourceLoader. (ryan) + + Optimizations ---------------------- 1. SOLR-374: Use IndexReader.reopen to save resources by re-using parts of the diff --git a/src/java/org/apache/solr/request/XSLTResponseWriter.java b/src/java/org/apache/solr/request/XSLTResponseWriter.java index 0ddf752af84..87ef0ebd2e6 100644 --- a/src/java/org/apache/solr/request/XSLTResponseWriter.java +++ b/src/java/org/apache/solr/request/XSLTResponseWriter.java @@ -109,7 +109,7 @@ public class XSLTResponseWriter implements QueryResponseWriter { throw new IOException("'" + TRANSFORM_PARAM + "' request parameter is required to use the XSLTResponseWriter"); } // not the cleanest way to achieve this - SolrConfig solrConfig = request.getSearcher().getSchema().getSolrConfig(); + SolrConfig solrConfig = request.getCore().getSolrConfig(); // no need to synchronize access to context, right? // Nothing else happens with it at the same time final Map ctx = request.getContext(); diff --git a/src/java/org/apache/solr/schema/IndexSchema.java b/src/java/org/apache/solr/schema/IndexSchema.java index 3b042c1f8d7..99e8d3a8a06 100644 --- a/src/java/org/apache/solr/schema/IndexSchema.java +++ b/src/java/org/apache/solr/schema/IndexSchema.java @@ -62,6 +62,7 @@ public final class IndexSchema { private final String resourceName; private String name; private float version; + private final SolrResourceLoader loader; /** * Constructs a schema using the specified file name using the normal @@ -86,7 +87,7 @@ public final class IndexSchema { if (name == null) name = DEFAULT_SCHEMA_FILE; this.resourceName = name; - SolrResourceLoader loader = solrConfig.getResourceLoader(); + loader = solrConfig.getResourceLoader(); InputStream lis = is; if (lis == null) lis = loader.openSchema(name); @@ -97,14 +98,23 @@ public final class IndexSchema { } catch(IOException xio) {} // ignore } - loader.inform( loader ); } + /** + * @deprecated -- get access to SolrConfig some other way... + */ public SolrConfig getSolrConfig() { return solrConfig; } + /** + * @since solr 1.4 + */ + public SolrResourceLoader getResourceLoader() + { + return loader; + } /** Gets the name of the resource used to instantiate this schema. */ public String getResourceName() { @@ -128,7 +138,7 @@ public final class IndexSchema { */ @Deprecated public InputStream getInputStream() { - return solrConfig.getResourceLoader().openResource(resourceName); + return loader.openResource(resourceName); } /** Gets the name of the schema file. @@ -381,7 +391,7 @@ public final class IndexSchema { try { // pass the config resource loader to avoid building an empty one for no reason: // in the current case though, the stream is valid so we wont load the resource by name - Config schemaConf = new Config(solrConfig.getResourceLoader(), "schema", is, "/schema/"); + Config schemaConf = new Config(loader, "schema", is, "/schema/"); Document document = schemaConf.getDocument(); final XPath xpath = schemaConf.getXPath(); @@ -396,7 +406,7 @@ public final class IndexSchema { version = schemaConf.getFloat("/schema/@version", 1.0f); final IndexSchema schema = this; - AbstractPluginLoader loader = new AbstractPluginLoader( "[schema.xml] fieldType", true, true) { + AbstractPluginLoader fieldLoader = new AbstractPluginLoader( "[schema.xml] fieldType", true, true) { @Override protected FieldType create( ResourceLoader loader, String name, String className, Node node ) throws Exception @@ -438,7 +448,7 @@ public final class IndexSchema { String expression = "/schema/types/fieldtype | /schema/types/fieldType"; NodeList nodes = (NodeList) xpath.evaluate(expression, document, XPathConstants.NODESET); - loader.load( solrConfig.getResourceLoader(), nodes ); + fieldLoader.load( loader, nodes ); @@ -539,7 +549,7 @@ public final class IndexSchema { }; log.debug("using default similarity"); } else { - final Object obj = solrConfig.getResourceLoader().newInstance(((Element) node).getAttribute("class")); + final Object obj = loader.newInstance(((Element) node).getAttribute("class")); if (obj instanceof SimilarityFactory) { // configure a factory, get a similarity back SolrParams params = SolrParams.toSolrParams(DOMUtil.childNodesToNamedList(node)); @@ -724,7 +734,7 @@ public final class IndexSchema { NamedNodeMap attrs = node.getAttributes(); String analyzerName = DOMUtil.getAttr(attrs,"class"); if (analyzerName != null) { - return (Analyzer)solrConfig.getResourceLoader().newInstance(analyzerName); + return (Analyzer)loader.newInstance(analyzerName); } XPath xpath = XPathFactory.newInstance().newXPath(); @@ -752,7 +762,7 @@ public final class IndexSchema { return null; // used for map registration } }; - tokenizerLoader.load( solrConfig.getResourceLoader(), (NodeList)xpath.evaluate("./tokenizer", node, XPathConstants.NODESET) ); + tokenizerLoader.load( loader, (NodeList)xpath.evaluate("./tokenizer", node, XPathConstants.NODESET) ); // Make sure something was loaded if( tokenizers.isEmpty() ) { @@ -779,7 +789,7 @@ public final class IndexSchema { return null; // used for map registration } }; - filterLoader.load( solrConfig.getResourceLoader(), (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET) ); + filterLoader.load( loader, (NodeList)xpath.evaluate("./filter", node, XPathConstants.NODESET) ); return new TokenizerChain(tokenizers.get(0), filters.toArray(new TokenFilterFactory[filters.size()])); }; diff --git a/src/java/org/apache/solr/search/SolrIndexSearcher.java b/src/java/org/apache/solr/search/SolrIndexSearcher.java index 9a2082e1724..b7a0e7880c6 100644 --- a/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -123,7 +123,7 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean { this.closeReader = closeReader; searcher.setSimilarity(schema.getSimilarity()); - SolrConfig solrConfig = schema.getSolrConfig(); + SolrConfig solrConfig = core.getSolrConfig(); queryResultWindowSize = solrConfig.queryResultWindowSize; queryResultMaxDocsCached = solrConfig.queryResultMaxDocsCached; useFilterForSortedQuery = solrConfig.useFilterForSortedQuery; diff --git a/src/java/org/apache/solr/update/SolrIndexWriter.java b/src/java/org/apache/solr/update/SolrIndexWriter.java index cc5fdfb0a14..031b2842ad3 100644 --- a/src/java/org/apache/solr/update/SolrIndexWriter.java +++ b/src/java/org/apache/solr/update/SolrIndexWriter.java @@ -59,14 +59,14 @@ public class SolrIndexWriter extends IndexWriter { if (config.maxMergeDocs != -1) setMaxMergeDocs(config.maxMergeDocs); if (config.maxFieldLength != -1) setMaxFieldLength(config.maxFieldLength); if (config.mergePolicyClassName != null && SolrIndexConfig.DEFAULT_MERGE_POLICY_CLASSNAME.equals(config.mergePolicyClassName) == false) { - MergePolicy policy = (MergePolicy) schema.getSolrConfig().getResourceLoader().newInstance(config.mergePolicyClassName); + MergePolicy policy = (MergePolicy) schema.getResourceLoader().newInstance(config.mergePolicyClassName); setMergePolicy(policy);///hmm, is this really the best way to get a newInstance? } if (config.mergeFactor != -1 && getMergePolicy() instanceof LogMergePolicy) { setMergeFactor(config.mergeFactor); } if (config.mergeSchedulerClassname != null && SolrIndexConfig.DEFAULT_MERGE_SCHEDULER_CLASSNAME.equals(config.mergeSchedulerClassname) == false) { - MergeScheduler scheduler = (MergeScheduler) schema.getSolrConfig().getResourceLoader().newInstance(config.mergeSchedulerClassname); + MergeScheduler scheduler = (MergeScheduler) schema.getResourceLoader().newInstance(config.mergeSchedulerClassname); setMergeScheduler(scheduler); }