You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/07/26 13:51:15 UTC
svn commit: r1365956 - in /lucene/dev/trunk/solr:
contrib/velocity/src/java/org/apache/solr/response/
core/src/java/org/apache/solr/cloud/ core/src/java/org/apache/solr/core/
core/src/java/org/apache/solr/schema/
core/src/java/org/apache/solr/spelling/...
Author: uschindler
Date: Thu Jul 26 11:51:14 2012
New Revision: 1365956
URL: http://svn.apache.org/viewvc?rev=1365956&view=rev
Log:
LUCENE-4255: Remove more useless try..catch on IOException after ResourceLoader update
Modified:
lucene/dev/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/SolrSpellChecker.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java
lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java
Modified: lucene/dev/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java (original)
+++ lucene/dev/trunk/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java Thu Jul 26 11:51:14 2012
@@ -22,6 +22,7 @@ import org.apache.velocity.exception.Res
import org.apache.commons.collections.ExtendedProperties;
import org.apache.solr.core.SolrResourceLoader;
+import java.io.IOException;
import java.io.InputStream;
// TODO: the name of this class seems ridiculous
@@ -39,7 +40,11 @@ public class SolrVelocityResourceLoader
@Override
public InputStream getResourceStream(String template_name) throws ResourceNotFoundException {
- return loader.openResource(template_name);
+ try {
+ return loader.openResource(template_name);
+ } catch (IOException ioe) {
+ throw new ResourceNotFoundException(ioe);
+ }
}
@Override
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/cloud/ZkSolrResourceLoader.java Thu Jul 26 11:51:14 2012
@@ -18,6 +18,7 @@ package org.apache.solr.cloud;
*/
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;
@@ -69,7 +70,7 @@ public class ZkSolrResourceLoader extend
* @return the stream for the named resource
*/
@Override
- public InputStream openResource(String resource) {
+ public InputStream openResource(String resource) throws IOException {
InputStream is = null;
String file = collectionZkPath + "/" + resource;
try {
@@ -78,16 +79,16 @@ public class ZkSolrResourceLoader extend
return new ByteArrayInputStream(bytes);
}
} catch (Exception e) {
- throw new RuntimeException("Error opening " + file, e);
+ throw new IOException("Error opening " + file, e);
}
try {
// delegate to the class loader (looking into $INSTANCE_DIR/lib jars)
is = classLoader.getResourceAsStream(resource);
} catch (Exception e) {
- throw new RuntimeException("Error opening " + resource, e);
+ throw new IOException("Error opening " + resource, e);
}
if (is == null) {
- throw new RuntimeException("Can't find resource '" + resource
+ throw new IOException("Can't find resource '" + resource
+ "' in classpath or '" + collectionZkPath + "', cwd="
+ System.getProperty("user.dir"));
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrResourceLoader.java Thu Jul 26 11:51:14 2012
@@ -252,7 +252,7 @@ public class SolrResourceLoader implemen
* Override this method to customize loading schema resources.
*@return the stream for the named schema
*/
- public InputStream openSchema(String name) {
+ public InputStream openSchema(String name) throws IOException {
return openResource(name);
}
@@ -260,7 +260,7 @@ public class SolrResourceLoader implemen
* Override this method to customize loading config resources.
*@return the stream for the named configuration
*/
- public InputStream openConfig(String name) {
+ public InputStream openConfig(String name) throws IOException {
return openResource(name);
}
@@ -272,7 +272,7 @@ public class SolrResourceLoader implemen
* Override this method to customize loading resources.
*@return the stream for the named resource
*/
- public InputStream openResource(String resource) {
+ public InputStream openResource(String resource) throws IOException {
InputStream is=null;
try {
File f0 = new File(resource);
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/schema/IndexSchema.java Thu Jul 26 11:51:14 2012
@@ -105,12 +105,12 @@ public final class IndexSchema {
name = DEFAULT_SCHEMA_FILE;
this.resourceName = name;
loader = solrConfig.getResourceLoader();
- if (is == null) {
- is = new InputSource(loader.openSchema(name));
- is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
- }
- readSchema(is);
try {
+ if (is == null) {
+ is = new InputSource(loader.openSchema(name));
+ is.setSystemId(SystemIdResolver.createSystemIdFromResourceName(name));
+ }
+ readSchema(is);
loader.inform( loader );
} catch (IOException e) {
throw new RuntimeException(e);
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -106,7 +106,7 @@ public class ConjunctionSolrSpellChecker
}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
for (SolrSpellChecker c : checkers) {
c.build(core, searcher);
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/DirectSolrSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -168,11 +168,10 @@ public class DirectSolrSpellChecker exte
}
@Override
- public void reload(SolrCore core, SolrIndexSearcher searcher)
- throws IOException {}
+ public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {}
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {}
@Override
public SpellingResult getSuggestions(SpellingOptions options)
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/FileBasedSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -59,17 +59,13 @@ public class FileBasedSpellChecker exten
}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {
- try {
- loadExternalFileDictionary(core);
- spellChecker.clearIndex();
- // TODO: you should be able to specify the IWC params?
- // TODO: if we enable this, codec gets angry since field won't exist in the schema
- // config.setCodec(core.getCodec());
- spellChecker.indexDictionary(dictionary, new IndexWriterConfig(core.getSolrConfig().luceneMatchVersion, null), false);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
+ loadExternalFileDictionary(core);
+ spellChecker.clearIndex();
+ // TODO: you should be able to specify the IWC params?
+ // TODO: if we enable this, codec gets angry since field won't exist in the schema
+ // config.setCodec(core.getCodec());
+ spellChecker.indexDictionary(dictionary, new IndexWriterConfig(core.getSolrConfig().luceneMatchVersion, null), false);
}
/**
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/IndexBasedSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -73,31 +73,27 @@ public class IndexBasedSpellChecker exte
}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
IndexReader reader = null;
- try {
- if (sourceLocation == null) {
- // Load from Solr's index
- reader = searcher.getIndexReader();
- } else {
- // Load from Lucene index at given sourceLocation
- reader = this.reader;
- }
-
- // Create the dictionary
- dictionary = new HighFrequencyDictionary(reader, field,
- threshold);
- // TODO: maybe whether or not to clear the index should be configurable?
- // an incremental update is faster (just adds new terms), but if you 'expunged'
- // old terms I think they might hang around.
- spellChecker.clearIndex();
- // TODO: you should be able to specify the IWC params?
- // TODO: if we enable this, codec gets angry since field won't exist in the schema
- // config.setCodec(core.getCodec());
- spellChecker.indexDictionary(dictionary, new IndexWriterConfig(core.getSolrConfig().luceneMatchVersion, null), false);
- } catch (IOException e) {
- throw new RuntimeException(e);
+ if (sourceLocation == null) {
+ // Load from Solr's index
+ reader = searcher.getIndexReader();
+ } else {
+ // Load from Lucene index at given sourceLocation
+ reader = this.reader;
}
+
+ // Create the dictionary
+ dictionary = new HighFrequencyDictionary(reader, field,
+ threshold);
+ // TODO: maybe whether or not to clear the index should be configurable?
+ // an incremental update is faster (just adds new terms), but if you 'expunged'
+ // old terms I think they might hang around.
+ spellChecker.clearIndex();
+ // TODO: you should be able to specify the IWC params?
+ // TODO: if we enable this, codec gets angry since field won't exist in the schema
+ // config.setCodec(core.getCodec());
+ spellChecker.indexDictionary(dictionary, new IndexWriterConfig(core.getSolrConfig().luceneMatchVersion, null), false);
}
@Override
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/SolrSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/SolrSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/SolrSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/SolrSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -167,7 +167,7 @@ public abstract class SolrSpellChecker {
/**
* (re)Builds the spelling index. May be a NOOP if the implementation doesn't require building, or can't be rebuilt.
*/
- public abstract void build(SolrCore core, SolrIndexSearcher searcher);
+ public abstract void build(SolrCore core, SolrIndexSearcher searcher) throws IOException;
/**
* Get the value of {@link SpellingParams#SPELLCHECK_ACCURACY} if supported.
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/spelling/suggest/Suggester.java Thu Jul 26 11:51:14 2012
@@ -35,6 +35,7 @@ import org.apache.lucene.search.suggest.
import org.apache.lucene.search.suggest.Lookup;
import org.apache.lucene.search.suggest.Lookup.LookupResult;
import org.apache.lucene.util.CharsRef;
+import org.apache.lucene.util.IOUtils;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.core.SolrCore;
@@ -121,7 +122,7 @@ public class Suggester extends SolrSpell
}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
LOG.info("build()");
if (sourceLocation == null) {
reader = searcher.getIndexReader();
@@ -129,30 +130,26 @@ public class Suggester extends SolrSpell
} else {
try {
dictionary = new FileDictionary(new InputStreamReader(
- core.getResourceLoader().openResource(sourceLocation), "UTF-8"));
+ core.getResourceLoader().openResource(sourceLocation), IOUtils.CHARSET_UTF_8));
} catch (UnsupportedEncodingException e) {
// should not happen
LOG.error("should not happen", e);
}
}
- try {
- lookup.build(dictionary);
- if (storeDir != null) {
- File target = new File(storeDir, factory.storeFileName());
- if(!lookup.store(new FileOutputStream(target))) {
- if (sourceLocation == null) {
- assert reader != null && field != null;
- LOG.error("Store Lookup build from index on field: " + field + " failed reader has: " + reader.maxDoc() + " docs");
- } else {
- LOG.error("Store Lookup build from sourceloaction: " + sourceLocation + " failed");
- }
+
+ lookup.build(dictionary);
+ if (storeDir != null) {
+ File target = new File(storeDir, factory.storeFileName());
+ if(!lookup.store(new FileOutputStream(target))) {
+ if (sourceLocation == null) {
+ assert reader != null && field != null;
+ LOG.error("Store Lookup build from index on field: " + field + " failed reader has: " + reader.maxDoc() + " docs");
} else {
- LOG.info("Stored suggest data to: " + target.getAbsolutePath());
+ LOG.error("Store Lookup build from sourceloaction: " + sourceLocation + " failed");
}
+ } else {
+ LOG.info("Stored suggest data to: " + target.getAbsolutePath());
}
-
- } catch (Exception e) {
- LOG.error("Error while building or storing Suggester data", e);
}
}
@@ -161,8 +158,13 @@ public class Suggester extends SolrSpell
LOG.info("reload()");
if (dictionary == null && storeDir != null) {
// this may be a firstSearcher event, try loading it
- if (lookup.load(new FileInputStream(new File(storeDir, factory.storeFileName())))) {
- return; // loaded ok
+ FileInputStream is = new FileInputStream(new File(storeDir, factory.storeFileName()));
+ try {
+ if (lookup.load(is)) {
+ return; // loaded ok
+ }
+ } finally {
+ IOUtils.closeWhileHandlingException(is);
}
LOG.debug("load failed, need to build Lookup again");
}
Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/update/processor/StatelessScriptUpdateProcessorFactory.java Thu Jul 26 11:51:14 2012
@@ -305,16 +305,22 @@ public class StatelessScriptUpdateProces
}
scriptEngines.add(new EngineInfo((Invocable)engine, scriptFile));
- Reader scriptSrc = scriptFile.openReader(resourceLoader);
-
try {
- engine.eval(scriptSrc);
- } catch (ScriptException e) {
+ Reader scriptSrc = scriptFile.openReader(resourceLoader);
+
+ try {
+ engine.eval(scriptSrc);
+ } catch (ScriptException e) {
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
+ "Unable to evaluate script: " +
+ scriptFile.getFileName(), e);
+ } finally {
+ IOUtils.closeQuietly(scriptSrc);
+ }
+ } catch (IOException ioe) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Unable to evaluate script: " +
- scriptFile.getFileName(), e);
- } finally {
- IOUtils.closeQuietly(scriptSrc);
+ "Unable to evaluate script: " +
+ scriptFile.getFileName(), ioe);
}
}
return scriptEngines;
@@ -485,7 +491,7 @@ public class StatelessScriptUpdateProces
return extension;
}
- public Reader openReader(SolrResourceLoader resourceLoader) {
+ public Reader openReader(SolrResourceLoader resourceLoader) throws IOException {
InputStream input = resourceLoader.openResource(fileName);
return org.apache.lucene.util.IOUtils.getDecodingReader
(input, org.apache.lucene.util.IOUtils.CHARSET_UTF_8);
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java?rev=1365956&r1=1365955&r2=1365956&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java Thu Jul 26 11:51:14 2012
@@ -40,7 +40,7 @@ public class DummyCustomParamSpellChecke
}
@Override
- public void build(SolrCore core, SolrIndexSearcher searcher) {
+ public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
}