Hi,
I reply to myslef.
In fact in Solr 4 beta, org.apache.lucene.analysis.util.ResourceLoader
is a SolrResourceLoader.
However getConfigDir do not return the absolute path to the config
directory. I mimiced the openResource method from ResourceLoader in
order to write my own getConfigDir method
public void inform(org.apache.lucene.analysis.util.ResourceLoader
loader) {
String configDir = getConfigDir(loader);
...
}
private String
getConfigDir(org.apache.lucene.analysis.util.ResourceLoader loader) {
File f = new File(analyzerConfigPath);
if (!f.isAbsolute()) {
// try $CWD/$configDir/$resource
f = new File(((SolrResourceLoader)loader).getConfigDir() +
analyzerConfigPath);
}
if (f.isFile() && f.canRead()) {
String path = f.getAbsolutePath();
if (path.lastIndexOf(f.separatorChar)!=-1) {
return path.substring(0,
path.lastIndexOf(f.separatorChar));
}
return null;
}
return null;
}
Not sure it is the best way, but it works :)
Dominique
Le 27/08/12 23:40, Dominique Bejean a écrit :
Hi,
I wrote a custom fieldtype that need to read a configuration file in
the conf directory of the core and also get the absolute path of the
conf directory
In solr 4 alpha, my code was something like :
import org.apache.solr.core.SolrResourceLoader;
...
public class MultilingualField extends TextField implements
ResourceLoaderAware {
...
public void inform(ResourceLoader loader) {
List<String> lines = loader.getLines("multiligual.xml");
// do something with lines
String configDir = ((SolrResourceLoader) loader).getConfigDir();
// do something with configDir
...
In beta version, there was a big refactoring of analyzer factories and
ressource loaders
now, inform method signature is
public void inform(org.apache.lucene.analysis.util.ResourceLoader
loader) {
...
I still can read the configuration file with something like
FileInputStream fis = (FileInputStream)
loader.openResource("multilingual.xml");
But, I can't get the conf directory absolute path anymore.
Any suggestion ?
Thank you.
Dominique