mirror of https://github.com/apache/lucene.git
LUCENE-4255: Remove more useless try..catch on IOException after ResourceLoader update
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1365956 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ca736cea8e
commit
58a9b85ae0
|
@ -22,6 +22,7 @@ import org.apache.velocity.exception.ResourceNotFoundException;
|
|||
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 extends ResourceLoader {
|
|||
|
||||
@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
|
||||
|
|
|
@ -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 extends SolrResourceLoader {
|
|||
* @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 extends SolrResourceLoader {
|
|||
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"));
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ public class SolrResourceLoader implements ResourceLoader
|
|||
* 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 implements ResourceLoader
|
|||
* 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 implements ResourceLoader
|
|||
* 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -106,7 +106,7 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker {
|
|||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
|
|
@ -168,11 +168,10 @@ public class DirectSolrSpellChecker extends SolrSpellChecker {
|
|||
}
|
||||
|
||||
@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)
|
||||
|
|
|
@ -59,17 +59,13 @@ public class FileBasedSpellChecker extends AbstractLuceneSpellChecker {
|
|||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -73,31 +73,27 @@ public class IndexBasedSpellChecker extends AbstractLuceneSpellChecker {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.lucene.search.suggest.FileDictionary;
|
|||
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 SolrSpellChecker {
|
|||
}
|
||||
|
||||
@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 SolrSpellChecker {
|
|||
} 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");
|
||||
}
|
||||
} else {
|
||||
LOG.info("Stored suggest data to: " + target.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while building or storing Suggester data", e);
|
||||
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");
|
||||
}
|
||||
} else {
|
||||
LOG.info("Stored suggest data to: " + target.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,8 +158,13 @@ public class Suggester extends SolrSpellChecker {
|
|||
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");
|
||||
}
|
||||
|
|
|
@ -305,16 +305,22 @@ public class StatelessScriptUpdateProcessorFactory extends UpdateRequestProcesso
|
|||
}
|
||||
|
||||
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 StatelessScriptUpdateProcessorFactory extends UpdateRequestProcesso
|
|||
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);
|
||||
|
|
|
@ -40,7 +40,7 @@ public class DummyCustomParamSpellChecker extends SolrSpellChecker {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void build(SolrCore core, SolrIndexSearcher searcher) {
|
||||
public void build(SolrCore core, SolrIndexSearcher searcher) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue