package org.greenstone.gsdl3.service; // Based on LuceneSearch, but not thoroughly tested // Greenstone classes import org.greenstone.gsdl3.util.*; import org.greenstone.util.GlobalProperties; import org.greenstone.util.ProtocolPortProperties; // XML classes import org.w3c.dom.Element; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import java.util.ArrayList; import java.util.HashMap; import java.util.Properties; import org.apache.log4j.Logger; import org.apache.solr.client.solrj.SolrQuery; 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.response.QueryResponse; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.util.NamedList; import org.apache.solr.servlet.SolrRequestParsers; public class SolrSearch extends LuceneSearch { static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.SolrSearch.class.getName()); protected String solr_servlet_base_url; protected HashMap solr_server; public SolrSearch() { solr_server = new HashMap(); // Create the solr servlet url on GS3's tomcat. By default it's "http://localhost:8383/solr" // Don't do this in configure(), since the tomcat url will remain unchanged while tomcat is running try { Properties globalProperties = new Properties(); globalProperties.load(Class.forName("org.greenstone.util.GlobalProperties").getClassLoader().getResourceAsStream("global.properties")); String host = globalProperties.getProperty("tomcat.server", "localhost"); //String port = globalProperties.getProperty("tomcat.port.http", "8383"); //String protocol = globalProperties.getProperty("server.protocol", "http"); ProtocolPortProperties protocolPortProps = new ProtocolPortProperties(globalProperties); if(protocolPortProps.hadError()) { throw new Exception("**** ERROR with port and/or protocol in build.properties:\n" + protocolPortProps.getErrorMsg()); } String protocol = protocolPortProps.getProtocol(); String port = protocolPortProps.getPort(); String solrContext = globalProperties.getProperty("solr.context", "solr"); String portStr = port.equals("80") ? "" : ":"+port; solr_servlet_base_url = protocol+"://"+host+portStr+"/"+solrContext; } catch(Exception e) { logger.error("Error reading greenstone's tomcat solr server properties from global.properties", e); } } // Overriding the cleanUp() method here, so as to parallel the structure of GS2SolrSearch // which also calls shutdown() on its CoreContainer object in GS2SolrSearch.cleanUp(). // However, this class has not yet been tested, so it's not certain that this method is // required here. // Adjusted to bring it up to speed with changes in GS2SolrSearch (for activate.pl) - not yet tested public void cleanUp() { super.cleanUp(); // clear the map keeping track of the SolrServers in this collection solr_server.clear(); } // adjusted configure to bring it up to speed with changes in GS2SolrSearch (for activate.pl) - not yet tested public boolean configure(Element info, Element extra_info) { boolean success = super.configure(info, extra_info); // clear the map of solr cores for this collection added to the map upon querying solr_server.clear(); if(!success) { return false; } // initialize required number of SolrCores based on values // in 'index_ids' that are set by LuceneSearch::configure() String core_name_prefix = getCollectionCoreNamePrefix(); for (int i=0; i