Author: yonik
Date: Mon Feb 6 18:58:55 2006
New Revision: 375449
URL: http://svn.apache.org/viewcvs?rev=375449&view=rev
Log:
look for config files in ./conf and the main index in ./data/index by default
Modified:
incubator/solr/trunk/src/apps/SolarTest/src/SolrTest.java
incubator/solr/trunk/src/java/org/apache/solr/core/Config.java
incubator/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
incubator/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
incubator/solr/trunk/src/java/org/apache/solr/update/UpdateHandler.java
incubator/solr/trunk/src/webapp/resources/admin/solar-status.jsp
incubator/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
Modified: incubator/solr/trunk/src/apps/SolarTest/src/SolrTest.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/apps/SolarTest/src/SolrTest.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/apps/SolarTest/src/SolrTest.java (original)
+++ incubator/solr/trunk/src/apps/SolarTest/src/SolrTest.java Mon Feb 6
18:58:55 2006
@@ -286,8 +286,8 @@
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 @@
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 @@
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();
Modified: incubator/solr/trunk/src/java/org/apache/solr/core/Config.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/core/Config.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/core/Config.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/core/Config.java Mon Feb 6
18:58:55 2006
@@ -220,10 +220,31 @@
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;
}
Modified: incubator/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java
(original)
+++ incubator/solr/trunk/src/java/org/apache/solr/core/SolrConfig.java Mon Feb
6 18:58:55 2006
@@ -43,7 +43,7 @@
} 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);
}
Modified: incubator/solr/trunk/src/java/org/apache/solr/core/SolrCore.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/core/SolrCore.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/core/SolrCore.java (original)
+++ incubator/solr/trunk/src/java/org/apache/solr/core/SolrCore.java Mon Feb 6
18:58:55 2006
@@ -64,6 +64,7 @@
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 @@
newSearcherListeners = parseListener("//[EMAIL PROTECTED]"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 @@
// 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 @@
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 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();
Modified:
incubator/solr/trunk/src/java/org/apache/solr/update/UpdateHandler.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/java/org/apache/solr/update/UpdateHandler.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/java/org/apache/solr/update/UpdateHandler.java
(original)
+++ incubator/solr/trunk/src/java/org/apache/solr/update/UpdateHandler.java Mon
Feb 6 18:58:55 2006
@@ -93,7 +93,7 @@
}
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;
}
Modified: incubator/solr/trunk/src/webapp/resources/admin/solar-status.jsp
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/webapp/resources/admin/solar-status.jsp?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
--- incubator/solr/trunk/src/webapp/resources/admin/solar-status.jsp (original)
+++ incubator/solr/trunk/src/webapp/resources/admin/solar-status.jsp Mon Feb 6
18:58:55 2006
@@ -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>
Modified:
incubator/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
URL:
http://svn.apache.org/viewcvs/incubator/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java?rev=375449&r1=375448&r2=375449&view=diff
==============================================================================
---
incubator/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
(original)
+++
incubator/solr/trunk/src/webapp/src/org/apache/solr/servlet/SolrServlet.java
Mon Feb 6 18:58:55 2006
@@ -46,15 +46,15 @@
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();