Index: gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java
===================================================================
--- gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java	(revision 30534)
+++ gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java	(revision 30564)
@@ -19,4 +19,6 @@
 package org.greenstone.gsdl3.service;
 
+import java.io.File;
+import java.io.IOException;
 // Greenstone classes
 import java.util.ArrayList;
@@ -31,6 +33,12 @@
 import org.apache.log4j.Logger;
 import org.apache.solr.client.solrj.SolrServer;
+import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.impl.HttpSolrServer;
+import org.apache.solr.client.solrj.impl.HttpSolrServer.RemoteSolrException;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.response.CoreAdminResponse;
 import org.apache.solr.client.solrj.response.FacetField;
+import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
+import org.apache.solr.common.util.NamedList;
 import org.greenstone.LuceneWrapper4.SharedSoleneQueryResult;
 import org.greenstone.gsdl3.util.FacetWrapper;
@@ -44,4 +52,10 @@
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
+
+import org.apache.solr.client.solrj.impl.HttpSolrServer.RemoteSolrException;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.response.CoreAdminResponse;
+import org.apache.solr.common.params.CoreAdminParams.CoreAdminAction;
+import org.apache.solr.common.util.NamedList;
 
 public class GS2SolrSearch extends SharedSoleneGS2FieldSearch
@@ -111,4 +125,11 @@
 		  _facets.add(((Element)facet_list.item(i)).getAttribute(GSXML.SHORTNAME_ATT));
 		}
+		
+		//If use Solr check if cores loaded
+		if (!loadSolrCores()) {
+			logger.error("Collection: couldn't configure collection: " + this.cluster_name + ", "
+					+ "Couldn't activate Solr cores");
+			 return false;
+		}
 		// NodeList configIndexElems = searchElem.getElementsByTagName(GSXML.INDEX_ELEM);
 
@@ -324,5 +345,5 @@
 		
 		SolrServer solr_core = null;
-
+		//CHECK HERE
 		if (!solr_core_cache.containsKey(core_name))
 		{		    
@@ -485,3 +506,83 @@
 	return collection_core_name_prefix;
     }
+    
+	private boolean loadSolrCores() {
+		
+		HttpSolrServer solrServer = new HttpSolrServer(solr_servlet_base_url);
+		// Max retries
+		solrServer.setMaxRetries(1);
+		// Connection Timeout
+		solrServer.setConnectionTimeout(3000);
+		//Cores
+		String coreSecName = getCollectionCoreNamePrefix() + "-sidx";
+		String coreDocName = getCollectionCoreNamePrefix() + "-didx";
+
+
+		if (!checkSolrCore(coreSecName, solrServer)){
+			if (!activateSolrCore(coreSecName, solrServer)){
+				logger.error("Couldn't activate Solr core " + coreSecName + " for collection " + cluster_name);
+				return false;
+			}
+		}
+		if (!checkSolrCore(coreDocName, solrServer)){
+			if (!activateSolrCore(coreDocName, solrServer)){
+				logger.error("Couldn't activate Solr core " + coreDocName + " for collection " + cluster_name);
+				return false;
+			}
+		}
+		return true;
+	}
+
+	private boolean checkSolrCore(String coreName, HttpSolrServer solrServer) {
+		CoreAdminRequest adminRequest = new CoreAdminRequest();
+		adminRequest.setAction(CoreAdminAction.STATUS);
+		adminRequest.setCoreName(coreName);
+
+		try {
+			CoreAdminResponse adminResponse = adminRequest.process(solrServer);
+			NamedList<NamedList<Object>> coreStatus = adminResponse.getCoreStatus();
+			NamedList<Object> coreList = coreStatus.getVal(0);
+			if (coreList != null) {
+				if (coreList.get("name") == null) {
+					logger.warn("Solr core " + coreName + " for collection " + cluster_name + " not exists.");
+					return false;
+				} 
+			}
+			
+		} catch (SolrServerException e) {
+			e.printStackTrace();
+			return false;
+		} catch (IOException e) {
+			e.printStackTrace();
+			return false;
+		} catch (RemoteSolrException e1){
+			logger.error("Check solr core " + coreName + " for collection " + cluster_name + " failed.");
+			e1.printStackTrace();
+			return false;
+		}
+		return true;
+	}
+	
+	private boolean activateSolrCore(String coreName, HttpSolrServer solrServer) {
+		String dataDir = GSFile.collectionIndexDir(site_home, cluster_name) + File.separator + coreName.substring(coreName.length() - 4);
+		String instanceDir = GSFile.collectionEtcDir(site_home, cluster_name);
+	
+		try {
+			CoreAdminRequest.createCore(coreName, instanceDir, solrServer, "", "", dataDir, "");
+			logger.warn("Solr core " + coreName + " for collection " + cluster_name + " activated.");
+		} catch (SolrServerException e1) {
+			e1.printStackTrace();
+			return false;
+		} catch (IOException e1) {
+			e1.printStackTrace();
+			return false;
+		} catch (RemoteSolrException e1){
+			logger.error("Activation solr core " + coreName + " for collection " + cluster_name + " failed.");
+			e1.printStackTrace();
+			return false;
+		}
+
+		return true;
+	}
+	
 }
