1 |
7591
|
leinfelder
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A class that gets Accession Number, check for uniqueness
|
4 |
|
|
* and register it into db
|
5 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* Authors: Jivka Bojilova, Matt Jones
|
8 |
|
|
*
|
9 |
|
|
* '$Author$'
|
10 |
|
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
12 |
|
|
*
|
13 |
|
|
* This program is free software; you can redistribute it and/or modify
|
14 |
|
|
* it under the terms of the GNU General Public License as published by
|
15 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
16 |
|
|
* (at your option) any later version.
|
17 |
|
|
*
|
18 |
|
|
* This program is distributed in the hope that it will be useful,
|
19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
|
|
* GNU General Public License for more details.
|
22 |
|
|
*
|
23 |
|
|
* You should have received a copy of the GNU General Public License
|
24 |
|
|
* along with this program; if not, write to the Free Software
|
25 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
|
|
*/
|
27 |
|
|
package edu.ucsb.nceas.metacat.index;
|
28 |
|
|
|
29 |
|
|
import java.io.File;
|
30 |
|
|
|
31 |
|
|
import org.apache.commons.logging.Log;
|
32 |
|
|
import org.apache.commons.logging.LogFactory;
|
33 |
|
|
import org.apache.solr.client.solrj.SolrServer;
|
34 |
|
|
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
|
35 |
|
|
import org.apache.solr.core.CoreContainer;
|
36 |
|
|
import org.dataone.configuration.Settings;
|
37 |
|
|
|
38 |
|
|
/**
|
39 |
|
|
* A factory for creating SolrServer implementations based on
|
40 |
|
|
* configuration in Settings.java
|
41 |
|
|
* Options are as follows.
|
42 |
|
|
*
|
43 |
|
|
* Embedded (default):
|
44 |
|
|
* solr.server.classname=org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
|
45 |
|
|
* solr.homeDir=/path/to/solr/home
|
46 |
|
|
*
|
47 |
|
|
* HTTP:
|
48 |
|
|
* solr.server.classname=org.apache.solr.client.solrj.impl.CommonsHttpSolrServer
|
49 |
|
|
* solr.endpoint=http://endpoint/to/solr/service
|
50 |
|
|
*
|
51 |
|
|
* @author leinfelder + tao
|
52 |
|
|
*
|
53 |
|
|
*/
|
54 |
|
|
public class SolrServerFactory {
|
55 |
|
|
|
56 |
|
|
public static final String SOLR_HOME_PROPERTY_NAME = "solr.homeDir";
|
57 |
|
|
|
58 |
|
|
public static Log log = LogFactory.getLog(SolrServerFactory.class);
|
59 |
|
|
|
60 |
|
|
public static SolrServer createSolrServer() throws Exception {
|
61 |
|
|
SolrServer solrServer = null;
|
62 |
|
|
|
63 |
|
|
String solrHomeDir = Settings.getConfiguration().getString(SOLR_HOME_PROPERTY_NAME);
|
64 |
|
|
log.info("The configured solr home from properties is " + solrHomeDir);
|
65 |
|
|
File configFile = new File(solrHomeDir, "solr.xml");
|
66 |
|
|
CoreContainer c = new CoreContainer(solrHomeDir, configFile);
|
67 |
|
|
c.load(solrHomeDir, configFile);
|
68 |
|
|
solrServer = new EmbeddedSolrServer(c, "collection1");
|
69 |
|
|
|
70 |
|
|
return solrServer;
|
71 |
|
|
}
|
72 |
|
|
}
|