Changeset 29711 for gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java
- Timestamp:
- 2015-02-03T21:57:53+13:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java
r29710 r29711 20 20 21 21 // Greenstone classes 22 import java.io.File;23 22 import java.util.ArrayList; 24 import java.util.Collection;25 23 import java.util.HashMap; 26 24 import java.util.Iterator; 27 25 import java.util.List; 28 26 import java.util.Map; 27 import java.util.Properties; 29 28 import java.util.Set; 30 29 import java.util.Vector; 31 30 32 31 import org.apache.log4j.Logger; 33 import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer; 32 import org.apache.solr.client.solrj.SolrServer; 33 import org.apache.solr.client.solrj.impl.HttpSolrServer; 34 34 import org.apache.solr.client.solrj.response.FacetField; 35 import org.apache.solr.core.CoreContainer;36 import org.apache.solr.core.SolrCore;37 35 import org.greenstone.LuceneWrapper4.SharedSoleneQueryResult; 38 36 import org.greenstone.gsdl3.util.FacetWrapper; … … 50 48 { 51 49 50 public static final String SOLR_SERVLET_SUFFIX = "/solr"; 52 51 protected static final String SORT_ORDER_PARAM = "sortOrder"; 53 52 protected static final String SORT_ORDER_DESCENDING = "1"; … … 56 55 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2SolrSearch.class.getName()); 57 56 58 static protected CoreContainer all_solr_cores = null; 59 60 protected HashMap solr_core_cache; 57 protected String solr_servlet_base_url; 58 protected HashMap<String, SolrServer> solr_core_cache; 61 59 protected SolrQueryWrapper solr_src = null; 62 60 … … 72 70 // based on 'level' parameter passed in to 'setUpQueryer()' 73 71 74 solr_core_cache = new HashMap(); 75 76 if (all_solr_cores == null) 77 { 78 // Share one CoreContainer across all sites/collections 79 try 80 { 81 String gsdl3_writablehome = GlobalProperties.getGSDL3WritableHome(); 82 String solr_ext_name = GlobalProperties.getProperty("gsdlext.solr.dirname", "solr"); 83 84 String solr_home_str = GSFile.extHome(gsdl3_writablehome, solr_ext_name); 85 86 all_solr_cores = new CoreContainer(solr_home_str); 87 } 88 catch (Exception e) 89 { 90 e.printStackTrace(); 91 } 92 } 93 94 this.solr_src = new SolrQueryWrapper(); 72 solr_core_cache = new HashMap<String, SolrServer>(); 73 74 this.solr_src = new SolrQueryWrapper(); 75 76 // Create the solr servlet url on GS3's tomcat. By default it's "http://localhost:8383/solr" 77 // Don't do this in configure(), since the tomcat url will remain unchanged while tomcat is running 78 try { 79 Properties globalProperties = new Properties(); 80 globalProperties.load(Class.forName("org.greenstone.util.GlobalProperties").getClassLoader().getResourceAsStream("global.properties")); 81 String host = globalProperties.getProperty("tomcat.server", "localhost"); 82 String port = globalProperties.getProperty("tomcat.port", "8383"); 83 String protocol = globalProperties.getProperty("tomcat.protocol", "http"); 84 85 String portStr = port.equals("80") ? "" : ":"+port; 86 solr_servlet_base_url = protocol+"://"+host+portStr+SOLR_SERVLET_SUFFIX; 87 } catch(Exception e) { 88 logger.error("Error reading greenstone's tomcat solr server properties from global.properties", e); 89 } 95 90 } 96 91 … … 100 95 boolean success = super.configure(info, extra_info); 101 96 102 // 1. Make the CoreContainer reload solr.xml 103 // This is particularly needed for when activate.pl is executed during 104 // a running GS3 server. At that point, the solr collection is reactivated and 105 // we need to tell Greenstone that the solr index has changed. This requires 106 // the CoreContainer to reload the solr.xml file, and it all works again. 107 108 solr_core_cache.clear(); // clear the map of solr cores for this collection added to the map upon querying 109 110 // Reload the updated solr.xml into the CoreContainer 111 // (Doing an all_solr_cores.shutdown() first doesn't seem to be required) 112 try { 113 String solr_home_str = all_solr_cores.getSolrHome(); 114 File solr_home = new File(solr_home_str); 115 File solr_xml = new File( solr_home,"solr.xml" ); 116 117 //all_solr_cores.load(solr_home_str,solr_xml); 118 all_solr_cores.load(); 119 120 } catch (Exception e) { 121 logger.error("Exception in GS2SolrSearch.configure(): " + e.getMessage()); 122 e.printStackTrace(); 123 return false; 124 } 125 97 // clear the map of solr cores for this collection added to the map upon querying 98 solr_core_cache.clear(); 99 126 100 if(!success) { 127 101 return false; 128 102 } 129 103 130 // 2.Setting up facets104 // Setting up facets 131 105 // TODO - get these from build config, in case some haven't built 132 106 Element searchElem = (Element) GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM); … … 170 144 this.solr_src.cleanUp(); 171 145 172 173 // 1. clear the map keeping track of the solrcores' EmbeddedSolrServers in this collection 146 // clear the map keeping track of the SolrServers in this collection 174 147 solr_core_cache.clear(); 175 176 // 2. For solr 4.7.2., GLI (and ant stop from cmd) is unable to shutdown the tomcat server fully,177 // IF any collection has been previewed AND if there are any solr collections in the collect folder.178 // This is because although the GS3 server seems to have stopped running at this stage, running a179 // `ps aux | grep tomcat` reveals that some part of tomcat is still running. It seems to be still180 // holding on to the cores. Doing an all_cores.shutdown() here, stops GS3 from hanging on to the cores181 // while still preserving the core desciptions in web/ext/solr.xml as needed when restarting the GS3 server.182 183 // Need GS3 server (tomcat) to release the cores, else a part of tomcat is still running in the background184 // on ant stop, holding a lock on the cores. Doing shutdown() preserves core descriptions in solr.xml185 all_solr_cores.shutdown();186 all_solr_cores = null;187 148 } 188 149 … … 356 317 // solr-core, (caching the result in 'solr_core_cache') 357 318 String core_name = getCollectionCoreNamePrefix() + "-" + index; 358 359 EmbeddedSolrServer solr_core = null;319 320 SolrServer solr_core = null; 360 321 361 322 if (!solr_core_cache.containsKey(core_name)) 362 { 363 solr_core = new EmbeddedSolrServer(all_solr_cores, core_name); 364 365 solr_core_cache.put(core_name, solr_core); 323 { 324 solr_core = new HttpSolrServer(this.solr_servlet_base_url+"/"+core_name); 325 solr_core_cache.put(core_name, solr_core); 366 326 } 367 327 else 368 328 { 369 solr_core = (EmbeddedSolrServer)solr_core_cache.get(core_name);329 solr_core = solr_core_cache.get(core_name); 370 330 } 371 331 … … 381 341 try 382 342 { 383 //SharedSoleneQueryResult sqr = this.solr_src.runQuery(query);384 343 SharedSoleneQueryResult sqr = this.solr_src.runQuery(query); 385 344
Note:
See TracChangeset
for help on using the changeset viewer.