Skip to content

Apache Lucene open-source search software

look for config files in ./conf and the main index in ./data/index by default

Yonik Seeley773ec8344b20
diff --git a/src/apps/SolarTest/src/SolrTest.java b/src/apps/SolarTest/src/SolrTest.java
index 837555ff608..04894bf9d9b 100644
--- a/src/apps/SolarTest/src/SolrTest.java
+++ b/src/apps/SolarTest/src/SolrTest.java
@@ -286,8 +286,8 @@ public class SolrTest extends Thread {
String filename="dict.txt";
String updateFilename="update_dict.txt";
- String luceneDir=null;
- String schemaFile="schema.xml";
+ String dataDir =null;
+ String schemaFile=null;
String testFile=null;
boolean b_numUpdates=false; boolean b_writers=false;
@@ -299,8 +299,8 @@ public class SolrTest extends Thread {
verbose=true;
} else if (arg.equals("-dict")) {
filename=args[i++];
- } else if (arg.equals("-index")) {
- luceneDir=args[i++];
+ } else if (arg.equals("-data")) {
+ dataDir =args[i++];
} else if (arg.equals("-readers")) {
readers=Integer.parseInt(args[i++]);
} else if (arg.equals("-numRequests")) {
@@ -322,16 +322,17 @@ public class SolrTest extends Thread {
try {
- IndexSchema schema = new IndexSchema(schemaFile);
+ IndexSchema schema = schemaFile==null ? null : new IndexSchema(schemaFile);
countdown = requests;
- core=new SolrCore(luceneDir,schema);
+ core=new SolrCore(dataDir,schema);
try {
- if (readers > 0) requestDict = readDict(filename);
- if (writers > 0) updateDict = readDict(updateFilename);
if (testFile != null) {
testDict = readDict(testFile);
testDictLineno = lineno;
+ } else {
+ if (readers > 0) requestDict = readDict(filename);
+ if (writers > 0) updateDict = readDict(updateFilename);
}
} catch (IOException e) {
e.printStackTrace();
diff --git a/src/java/org/apache/solr/core/Config.java b/src/java/org/apache/solr/core/Config.java
index d99b36fa15e..195aaefa59d 100644
--- a/src/java/org/apache/solr/core/Config.java
+++ b/src/java/org/apache/solr/core/Config.java
@@ -220,10 +220,31 @@ public class Config {
public static InputStream openResource(String resource) {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- InputStream is = loader.getResourceAsStream(resource);
+ InputStream is=null;
+
+ try {
+ File f = new File(resource);
+ if (!f.isAbsolute()) {
+ // try $CWD/conf/
+ f = new File("conf/" + resource);
+ }
+ if (f.isFile() && f.canRead()) {
+ return new FileInputStream(f);
+ } else {
+ // try $CWD
+ f = new File(resource);
+ if (f.isFile() && f.canRead()) {
+ return new FileInputStream(f);
+ }
+ }
+
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ is = loader.getResourceAsStream(resource);
+ } catch (Exception e) {
+ throw new RuntimeException("Error opening " + resource, e);
+ }
if (is==null) {
- throw new SolrException(500,"Can't open " + resource);
+ throw new RuntimeException("Can't find resource " + resource);
}
return is;
}
diff --git a/src/java/org/apache/solr/core/SolrConfig.java b/src/java/org/apache/solr/core/SolrConfig.java
index 3be8d097ad4..32adc6068c6 100644
--- a/src/java/org/apache/solr/core/SolrConfig.java
+++ b/src/java/org/apache/solr/core/SolrConfig.java
@@ -43,7 +43,7 @@ public class SolrConfig {
} catch (Exception ee) {
throw new RuntimeException(ee);
}
- Config.log.info("Loaded Config solarconfig.xml");
+ Config.log.info("Loaded Config solrconfig.xml");
} else {
throw new RuntimeException(e);
}
diff --git a/src/java/org/apache/solr/core/SolrCore.java b/src/java/org/apache/solr/core/SolrCore.java
index a7cfe8a60ad..2cc4349601d 100644
--- a/src/java/org/apache/solr/core/SolrCore.java
+++ b/src/java/org/apache/solr/core/SolrCore.java
@@ -64,6 +64,7 @@ public final class SolrCore {
public static Logger log = Logger.getLogger(SolrCore.class.getName());
private final IndexSchema schema;
+ private final String dataDir;
private final String index_path;
private final UpdateHandler updateHandler;
@@ -98,10 +99,9 @@ public final class SolrCore {
newSearcherListeners = parseListener("//listener[@event=\"newSearcher\"]");
}
-
public IndexSchema getSchema() { return schema; }
- public String getDir() { return index_path; }
-
+ public String getDataDir() { return index_path; }
+ public String getIndexDir() { return index_path; }
private final RequestHandlers reqHandlers = new RequestHandlers(SolrConfig.config);
@@ -130,23 +130,22 @@ public final class SolrCore {
// gets a non-caching searcher
public SolrIndexSearcher newSearcher(String name) throws IOException {
- return new SolrIndexSearcher(schema, name,getDir(),false);
+ return new SolrIndexSearcher(schema, name,getDataDir(),false);
}
void initIndex() {
try {
- File dirFile = new File(getDir());
+ File dirFile = new File(getIndexDir());
boolean indexExists = dirFile.canRead();
-
boolean removeLocks = SolrConfig.config.getBool("mainIndex/unlockOnStartup", false);
if (removeLocks) {
// to remove locks, the directory must already exist... so we create it
// if it didn't exist already...
Directory dir = FSDirectory.getDirectory(dirFile, !indexExists);
if (IndexReader.isLocked(dir)) {
- log.warning("WARNING: Solr index directory '" + getDir() + "' is locked. Unlocking...");
+ log.warning("WARNING: Solr index directory '" + getDataDir() + "' is locked. Unlocking...");
IndexReader.unlock(dir);
}
}
@@ -157,7 +156,7 @@ public final class SolrCore {
log.warning("Solr index directory '" + dirFile + "' doesn't exist."
+ " Creating new index...");
- SolrIndexWriter writer = new SolrIndexWriter("SolrCore.initIndex",getDir(), true, schema, mainIndexConfig);
+ SolrIndexWriter writer = new SolrIndexWriter("SolrCore.initIndex",getDataDir(), true, schema, mainIndexConfig);
writer.close();
}
@@ -192,24 +191,25 @@ public final class SolrCore {
}
- public SolrCore(String index_path, IndexSchema schema) {
+ public SolrCore(String dataDir, IndexSchema schema) {
synchronized (SolrCore.class) {
// this is for backward compatibility (and also the reason
// the sync block is needed)
core = this; // set singleton
try {
- if (index_path==null) {
- index_path=SolrConfig.config.get("indexDir","index");
+ if (dataDir ==null) {
+ dataDir =SolrConfig.config.get("dataDir","data");
}
- log.info("Opening new SolrCore at " + index_path);
+ log.info("Opening new SolrCore with data directory at " + dataDir);
if (schema==null) {
schema = new IndexSchema("schema.xml");
}
this.schema = schema;
- this.index_path = index_path;
+ this.dataDir = dataDir;
+ this.index_path = dataDir + "/" + "index";
parseListeners();
diff --git a/src/java/org/apache/solr/update/UpdateHandler.java b/src/java/org/apache/solr/update/UpdateHandler.java
index e410b6ce274..d7a64bc1c0d 100644
--- a/src/java/org/apache/solr/update/UpdateHandler.java
+++ b/src/java/org/apache/solr/update/UpdateHandler.java
@@ -93,7 +93,7 @@ public abstract class UpdateHandler implements SolrInfoMBean {
}
protected SolrIndexWriter createMainIndexWriter(String name) throws IOException {
- SolrIndexWriter writer = new SolrIndexWriter(name,core.getDir(), false, schema,SolrCore.mainIndexConfig);
+ SolrIndexWriter writer = new SolrIndexWriter(name,core.getIndexDir(), false, schema,SolrCore.mainIndexConfig);
return writer;
}
diff --git a/src/webapp/resources/admin/solar-status.jsp b/src/webapp/resources/admin/solar-status.jsp
index ae9548ac1c2..7343c0d58ed 100644
--- a/src/webapp/resources/admin/solar-status.jsp
+++ b/src/webapp/resources/admin/solar-status.jsp
@@ -56,7 +56,7 @@
<state>IN_SERVICE</state>
<schemaFile>schema.xml</schemaFile>
<schemaName><%= schema.getName() %></schemaName>
- <indexDir><%= core.getDir() %></indexDir>
+ <indexDir><%= core.getDataDir() %></indexDir>
<maxDoc><%= core.maxDoc() %></maxDoc>
</status>
</solr>
diff --git a/src/webapp/src/org/apache/solr/servlet/SolrServlet.java b/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
index c9cef2836e9..acc96afde68 100644
--- a/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
+++ b/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
@@ -46,15 +46,15 @@ public class SolrServlet extends HttpServlet {
public void init() throws ServletException
{
- /***
- luceneDir=getServletContext().getInitParameter("solr.indexdir");
- schemaFile=getServletContext().getInitParameter("solr.schema");
- if (schemaFile == null) schemaFile="schema.xml";
- ***/
+ String configDir=getServletContext().getInitParameter("solr.configDir");
+ String dataDir=getServletContext().getInitParameter("solr.dataDir");
log.info("user.dir=" + System.getProperty("user.dir"));
- IndexSchema schema = new IndexSchema("schema.xml");
+ // TODO: find a way to allow configuration of the config and data
+ // directories other than using CWD. If it is done via servlet
+ // params, then we must insure that this init() run before any
+ // of the JSPs.
core = SolrCore.getSolrCore();
xmlResponseWriter=new XMLResponseWriter();