Revision 7595
Added by Jing Tao over 11 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrServerFactory.java | ||
---|---|---|
32 | 32 |
import org.apache.commons.logging.LogFactory; |
33 | 33 |
import org.apache.solr.client.solrj.SolrServer; |
34 | 34 |
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; |
35 |
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; |
|
35 | 36 |
import org.apache.solr.core.CoreContainer; |
36 | 37 |
import org.dataone.configuration.Settings; |
37 | 38 |
|
... | ... | |
57 | 58 |
public static final String SOLR_CONFIG_FILE_NAME_PROPERTY_NAME = "solr.configFileName"; |
58 | 59 |
public static final String SOLR_COLLECTION_NAME_PROPERTY_NAME = "solr.collectionName"; |
59 | 60 |
public static final String SOLR_SERVER_CLASSNAME_PROPERTY_NAME = "solr.server.classname"; |
61 |
public static final String SOLR_ENPOINT_PROPERTY_NAME = "solr.endpoint"; |
|
60 | 62 |
private static final String EMBEDDEDSERVERCLASS = "org.apache.solr.client.solrj.embedded.EmbeddedSolrServer"; |
61 | 63 |
private static final String HTTPSERVERCLASS = "org.apache.solr.client.solrj.impl.CommonsHttpSolrServer"; |
62 | 64 |
|
63 | 65 |
public static Log log = LogFactory.getLog(SolrServerFactory.class); |
64 | 66 |
|
65 | 67 |
private static CoreContainer coreContainer = null; |
68 |
private static SolrServer solrServer = null; |
|
66 | 69 |
|
67 | 70 |
public static SolrServer createSolrServer() throws Exception { |
68 |
SolrServer solrServer = null; |
|
69 | 71 |
|
70 |
String solrHomeDir = Settings.getConfiguration().getString(SOLR_HOME_PROPERTY_NAME); |
|
72 |
String className = Settings.getConfiguration().getString(SOLR_SERVER_CLASSNAME_PROPERTY_NAME); |
|
73 |
if (className != null && className.equals(EMBEDDEDSERVERCLASS)) { |
|
74 |
generateEmbeddedServer(); |
|
75 |
} else if (className != null && className.equals(HTTPSERVERCLASS)) { |
|
76 |
String solrServerUrl = Settings.getConfiguration().getString(SOLR_ENPOINT_PROPERTY_NAME); |
|
77 |
solrServer = new CommonsHttpSolrServer(solrServerUrl); |
|
78 |
} else { |
|
79 |
throw new Exception("SolrServerFactory.createSolrServer - MetacatIndex doesn't support this solr server type: "+className); |
|
80 |
} |
|
81 |
|
|
82 |
|
|
83 |
return solrServer; |
|
84 |
} |
|
85 |
|
|
86 |
private static void generateEmbeddedServer() throws Exception { |
|
87 |
String solrHomeDir = Settings.getConfiguration().getString(SOLR_HOME_PROPERTY_NAME); |
|
71 | 88 |
log.info("The configured solr home from properties is " + solrHomeDir); |
72 | 89 |
String configFileName = Settings.getConfiguration().getString(SOLR_CONFIG_FILE_NAME_PROPERTY_NAME); |
73 | 90 |
File configFile = new File(solrHomeDir, configFileName); |
... | ... | |
75 | 92 |
coreContainer.load(solrHomeDir, configFile); |
76 | 93 |
String collectioname = Settings.getConfiguration().getString(SOLR_COLLECTION_NAME_PROPERTY_NAME); |
77 | 94 |
solrServer = new EmbeddedSolrServer(coreContainer, collectioname); |
78 |
|
|
79 |
return solrServer; |
|
80 | 95 |
} |
81 | 96 |
|
82 | 97 |
public static CoreContainer getCoreContainer() { |
Also available in: Unified diff
Base the configuration to create either EmbeddedSolrServer or HttpSolrServer.