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 ry...@apache.org on 2007/11/24 14:51:51 UTC

svn commit: r597847 [2/2] - in /lucene/solr/trunk: ./ src/java/org/apache/solr/analysis/ src/java/org/apache/solr/common/ src/java/org/apache/solr/core/ src/java/org/apache/solr/handler/admin/ src/java/org/apache/solr/highlight/ src/java/org/apache/sol...

Added: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java?rev=597847&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java Sat Nov 24 05:51:46 2007
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.plugin;
+
+import org.apache.solr.common.ResourceLoader;
+
+/**
+ * @since solr 1.3
+ */
+public interface ResourceLoaderAware 
+{
+  void inform( ResourceLoader loader );
+}

Propchange: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/ResourceLoaderAware.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java?rev=597847&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java Sat Nov 24 05:51:46 2007
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.util.plugin;
+
+import org.apache.solr.core.SolrCore;
+
+/**
+ * @since solr 1.3
+ */
+public interface SolrCoreAware 
+{
+  void inform( SolrCore core );
+}

Propchange: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/java/org/apache/solr/util/plugin/SolrCoreAware.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/solr/trunk/src/java/org/apache/solr/util/xslt/TransformerProvider.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/util/xslt/TransformerProvider.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/util/xslt/TransformerProvider.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/util/xslt/TransformerProvider.java Sat Nov 24 05:51:46 2007
@@ -28,6 +28,7 @@
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.stream.StreamSource;
 
+import org.apache.solr.common.ResourceLoader;
 import org.apache.solr.core.SolrConfig;
 
 /** Singleton that creates a Transformer for the XSLTServletFilter.
@@ -72,7 +73,7 @@
         log.fine("Using cached Templates:" + filename);
       }
     } else {
-      lastTemplates = getTemplates(solrConfig, filename,cacheLifetimeSeconds);
+      lastTemplates = getTemplates(solrConfig.getResourceLoader(), filename,cacheLifetimeSeconds);
     }
     
     Transformer result = null;
@@ -90,7 +91,7 @@
   }
   
   /** Return a Templates object for the given filename */
-  private Templates getTemplates(SolrConfig solrConfig, String filename,int cacheLifetimeSeconds) throws IOException {
+  private Templates getTemplates(ResourceLoader loader, String filename,int cacheLifetimeSeconds) throws IOException {
     
     Templates result = null;
     lastFilename = null;
@@ -98,7 +99,7 @@
       if(log.isLoggable(Level.FINE)) {
         log.fine("compiling XSLT templates:" + filename);
       }
-      final InputStream xsltStream = solrConfig.openResource("xslt/" + filename);
+      final InputStream xsltStream = loader.openResource("xslt/" + filename);
       result = tFactory.newTemplates(new StreamSource(xsltStream));
     } catch (Exception e) {
       log.throwing(getClass().getName(), "newTemplates", e);

Modified: lucene/solr/trunk/src/test/org/apache/solr/analysis/TestCapitalizationFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/analysis/TestCapitalizationFilter.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/analysis/TestCapitalizationFilter.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/analysis/TestCapitalizationFilter.java Sat Nov 24 05:51:46 2007
@@ -33,7 +33,7 @@
     args.put( CapitalizationFilterFactory.ONLY_FIRST_WORD, "true" );  
     
     CapitalizationFilterFactory factory = new CapitalizationFilterFactory();
-    factory.init( solrConfig, args );
+    factory.init( args );
 
     assertEquals( "Kitten", factory.processWord( "kiTTEN", 0 ) );
     factory.forceFirstLetter = true;
@@ -63,7 +63,7 @@
     // Now try some prefixes
     factory = new CapitalizationFilterFactory();
     args.put( "okPrefix", "McK" );  // all words
-    factory.init( solrConfig, args );
+    factory.init( args );
     out = tsToString( factory.create( new IterTokenStream( "McKinley" ) ) );
     assertEquals( "McKinley", out );
     

Modified: lucene/solr/trunk/src/test/org/apache/solr/analysis/TestKeepWordFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/analysis/TestKeepWordFilter.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/analysis/TestKeepWordFilter.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/analysis/TestKeepWordFilter.java Sat Nov 24 05:51:46 2007
@@ -44,7 +44,8 @@
     // Test Stopwords
     KeepWordFilterFactory factory = new KeepWordFilterFactory();
     args.put( "ignoreCase", "true" );
-    factory.init( solrConfig, args );
+    factory.init( args );
+    factory.inform( solrConfig.getResourceLoader() );
     factory.setWords( words );
     
     List<Token> expect = tokens( "aaa BBB" );
@@ -53,7 +54,8 @@
     
     // Now force case
     args.put( "ignoreCase", "false" );
-    factory.init( solrConfig, args );
+    factory.init( args );
+    factory.inform( solrConfig.getResourceLoader() );
     
     expect = tokens( "aaa" );
     real = getTokens(factory.create( new IterTokenStream(input) ));

Modified: lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPatternTokenizerFactory.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPatternTokenizerFactory.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPatternTokenizerFactory.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPatternTokenizerFactory.java Sat Nov 24 05:51:46 2007
@@ -50,7 +50,7 @@
       args.put( PatternTokenizerFactory.PATTERN, test[1] );
 
       PatternTokenizerFactory tokenizer = new PatternTokenizerFactory();
-      tokenizer.init(solrConfig, args );
+      tokenizer.init( args );
       
       TokenStream stream = tokenizer.create( new StringReader( test[2] ) );
       String out = TestHyphenatedWordsFilter.tsToString( stream );

Modified: lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPhoneticFilter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPhoneticFilter.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPhoneticFilter.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/analysis/TestPhoneticFilter.java Sat Nov 24 05:51:46 2007
@@ -40,24 +40,24 @@
     
     PhoneticFilterFactory ff = new PhoneticFilterFactory();
     try {
-      ff.init( solrConfig, args );
+      ff.init( args );
       fail( "missing encoder parameter" );
     }
     catch( Exception ex ) {}
     args.put( PhoneticFilterFactory.ENCODER, "XXX" );
     try {
-      ff.init( solrConfig, args );
+      ff.init( args );
       fail( "unknown encoder parameter" );
     }
     catch( Exception ex ) {}
     
     args.put( PhoneticFilterFactory.ENCODER, "Metaphone" );
-    ff.init( solrConfig, args );
+    ff.init( args );
     assertTrue( ff.encoder instanceof Metaphone );
     assertTrue( ff.inject ); // default
 
     args.put( PhoneticFilterFactory.INJECT, "false" );
-    ff.init( solrConfig, args );
+    ff.init( args );
     assertFalse( ff.inject );
   }
   

Added: lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java?rev=597847&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java (added)
+++ lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java Sat Nov 24 05:51:46 2007
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.core;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.lucene.analysis.ngram.NGramTokenFilter;
+import org.apache.solr.analysis.KeywordTokenizerFactory;
+import org.apache.solr.analysis.NGramFilterFactory;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.handler.admin.LukeRequestHandler;
+import org.apache.solr.handler.component.FacetComponent;
+import org.apache.solr.request.JSONResponseWriter;
+import org.apache.solr.util.plugin.ResourceLoaderAware;
+import org.apache.solr.util.plugin.SolrCoreAware;
+
+public class ResourceLoaderTest extends TestCase 
+{
+  public void testAwareCompatibility() 
+  {
+    SolrResourceLoader loader = new SolrResourceLoader( "." );
+    
+    Class clazz = ResourceLoaderAware.class;
+    // Check ResourceLoaderAware valid objects
+    loader.assertAwareCompatibility( clazz, new NGramFilterFactory() );
+    loader.assertAwareCompatibility( clazz, new KeywordTokenizerFactory() );
+    
+    // Make sure it throws an error for invalid objects
+    Object[] invalid = new Object[] {
+        new NGramTokenFilter( null ),
+        "hello",  new Float( 12.3f ),
+        new LukeRequestHandler(),
+        new JSONResponseWriter()
+    };
+    for( Object obj : invalid ) {
+      try {
+        loader.assertAwareCompatibility( clazz, obj );
+        Assert.fail( "Should be invalid class: "+obj + " FOR " + clazz );
+      }
+      catch( SolrException ex ) { } // OK
+    }
+    
+
+    clazz = SolrCoreAware.class;
+    // Check ResourceLoaderAware valid objects
+    loader.assertAwareCompatibility( clazz, new LukeRequestHandler() );
+    loader.assertAwareCompatibility( clazz, new FacetComponent() );
+    loader.assertAwareCompatibility( clazz, new JSONResponseWriter() );
+    
+    // Make sure it throws an error for invalid objects
+    invalid = new Object[] {
+        new NGramFilterFactory(),
+        "hello",  new Float( 12.3f ),
+        new KeywordTokenizerFactory()
+    };
+    for( Object obj : invalid ) {
+      try {
+        loader.assertAwareCompatibility( clazz, obj );
+        Assert.fail( "Should be invalid class: "+obj + " FOR " + clazz );
+      }
+      catch( SolrException ex ) { } // OK
+    }
+  }
+}
\ No newline at end of file

Propchange: lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: lucene/solr/trunk/src/test/org/apache/solr/core/ResourceLoaderTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/DirectSolrConnection.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/DirectSolrConnection.java?rev=597847&r1=597846&r2=597847&view=diff
==============================================================================
--- lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/DirectSolrConnection.java (original)
+++ lucene/solr/trunk/src/webapp/src/org/apache/solr/servlet/DirectSolrConnection.java Sat Nov 24 05:51:46 2007
@@ -103,7 +103,7 @@
     SolrConfig config = null;
     try {
       config = new SolrConfig(instanceDir, SolrConfig.DEFAULT_CONF_FILE, null);
-      instanceDir = config.getInstanceDir();
+      instanceDir = config.getResourceLoader().getInstanceDir();
 
       // If the Data directory is specified, initialize SolrCore directly
       IndexSchema schema = new IndexSchema(config, instanceDir+"/conf/schema.xml");