[VIVO-1592] Upgrade Solr library to 7.4.0 (#82)

* Upgrade Solr library to 7.4.0

Related to: https://jira.duraspace.org/browse/VIVO-1589

* Fix SolrSmokeTest : home page connection

Related to: https://jira.duraspace.org/browse/VIVO-1589
This commit is contained in:
Andrew Woods 2018-10-17 22:14:05 -04:00 committed by hudajkhan
parent 45ddb56294
commit da16a4156d
6 changed files with 40 additions and 26 deletions

View file

@ -51,7 +51,6 @@ public class SolrConversionUtils {
SearchInputDocument doc) { SearchInputDocument doc) {
SolrInputDocument solrDoc = new SolrInputDocument( SolrInputDocument solrDoc = new SolrInputDocument(
convertToSolrInputFieldMap(doc.getFieldMap())); convertToSolrInputFieldMap(doc.getFieldMap()));
solrDoc.setDocumentBoost(doc.getDocumentBoost());
return solrDoc; return solrDoc;
} }
@ -81,11 +80,10 @@ public class SolrConversionUtils {
// No values, nothing to do. // No values, nothing to do.
} else if (values.size() == 1) { } else if (values.size() == 1) {
// One value? Insure that it is accepted as such. // One value? Insure that it is accepted as such.
solrField.addValue(values.iterator().next(), solrField.addValue(values.iterator().next());
searchInputField.getBoost());
} else { } else {
// A collection of values? Add them. // A collection of values? Add them.
solrField.addValue(values, searchInputField.getBoost()); solrField.addValue(values);
} }
return solrField; return solrField;
@ -125,7 +123,6 @@ public class SolrConversionUtils {
* Convert from a SearchQuery to a SolrQuery, so the Solr server may execute * Convert from a SearchQuery to a SolrQuery, so the Solr server may execute
* it. * it.
*/ */
@SuppressWarnings("deprecation")
static SolrQuery convertToSolrQuery(SearchQuery query) { static SolrQuery convertToSolrQuery(SearchQuery query) {
SolrQuery solrQuery = new SolrQuery(query.getQuery()); SolrQuery solrQuery = new SolrQuery(query.getQuery());
solrQuery.setStart(query.getStart()); solrQuery.setStart(query.getStart());
@ -141,7 +138,7 @@ public class SolrConversionUtils {
Map<String, Order> sortFields = query.getSortFields(); Map<String, Order> sortFields = query.getSortFields();
for (String sortField : sortFields.keySet()) { for (String sortField : sortFields.keySet()) {
solrQuery.addSortField(sortField, solrQuery.addOrUpdateSort(sortField,
convertToSolrOrder(sortFields.get(sortField))); convertToSolrOrder(sortFields.get(sortField)));
} }

View file

@ -10,10 +10,13 @@ import java.util.Collection;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer; import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrServer; import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.client.solrj.response.QueryResponse;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties; import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
@ -32,8 +35,8 @@ import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchQuery;
* The Solr-based implementation of SearchEngine. * The Solr-based implementation of SearchEngine.
*/ */
public class SolrSearchEngine implements SearchEngine { public class SolrSearchEngine implements SearchEngine {
private HttpSolrServer queryEngine; private SolrClient queryEngine;
private ConcurrentUpdateSolrServer updateEngine; private ConcurrentUpdateSolrClient updateEngine;
/** /**
* Set up the http connection with the solr server * Set up the http connection with the solr server
@ -53,16 +56,26 @@ public class SolrSearchEngine implements SearchEngine {
} }
try { try {
queryEngine = new HttpSolrServer(solrServerUrlString); HttpSolrClient.Builder builder = new HttpSolrClient.Builder(solrServerUrlString);
queryEngine.setSoTimeout(10000); // socket read timeout
queryEngine.setConnectionTimeout(10000);
queryEngine.setDefaultMaxConnectionsPerHost(100);
queryEngine.setMaxTotalConnections(100);
queryEngine.setMaxRetries(1);
updateEngine = new ConcurrentUpdateSolrServer(solrServerUrlString, 100, 1); builder.withSocketTimeout(10000); // socket read timeout
updateEngine.setConnectionTimeout(10000); builder.withConnectionTimeout(10000);
updateEngine.setPollQueueTime(25);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
httpClientBuilder.setMaxConnPerRoute(100);
httpClientBuilder.setMaxConnTotal(100);
httpClientBuilder.setRetryHandler(new StandardHttpRequestRetryHandler(1, false));
builder.withHttpClient(httpClientBuilder.build());
queryEngine = builder.build();
ConcurrentUpdateSolrClient.Builder updateBuilder =
new ConcurrentUpdateSolrClient.Builder(solrServerUrlString);
updateBuilder.withConnectionTimeout(10000);
// no apparent 7.4.0 analogy to `setPollQueueTime(25)`
updateEngine = updateBuilder.build();
css.info("Set up the Solr search engine; URL = '" + solrServerUrlString + "'."); css.info("Set up the Solr search engine; URL = '" + solrServerUrlString + "'.");
} catch (Exception e) { } catch (Exception e) {
@ -72,8 +85,12 @@ public class SolrSearchEngine implements SearchEngine {
@Override @Override
public void shutdown(Application application) { public void shutdown(Application application) {
queryEngine.shutdown(); try {
updateEngine.shutdown(); queryEngine.close();
} catch (IOException e) {
throw new RuntimeException("Error shutting down 'queryEngine'", e);
}
updateEngine.shutdownNow();
} }
@Override @Override
@ -170,7 +187,7 @@ public class SolrSearchEngine implements SearchEngine {
SolrQuery solrQuery = SolrConversionUtils.convertToSolrQuery(query); SolrQuery solrQuery = SolrConversionUtils.convertToSolrQuery(query);
QueryResponse response = queryEngine.query(solrQuery); QueryResponse response = queryEngine.query(solrQuery);
return SolrConversionUtils.convertToSearchResponse(response); return SolrConversionUtils.convertToSearchResponse(response);
} catch (SolrServerException e) { } catch (SolrServerException | IOException e) {
throw appropriateException( throw appropriateException(
"Solr server failed to execute the query" + query, e); "Solr server failed to execute the query" + query, e);
} }

View file

@ -235,7 +235,7 @@ public class SolrSmokeTest implements ServletContextListener {
private void tryToConnect() throws SolrProblemException { private void tryToConnect() throws SolrProblemException {
try { try {
HttpGet method = new HttpGet(solrUrl.toExternalForm()); HttpGet method = new HttpGet(solrUrl.toExternalForm() + "/select");
SolrSmokeTest.log.debug("Trying to connect to Solr"); SolrSmokeTest.log.debug("Trying to connect to Solr");
HttpResponse response = httpClient.execute(method); HttpResponse response = httpClient.execute(method);
try { try {

View file

@ -207,7 +207,7 @@
<dependency> <dependency>
<groupId>org.apache.solr</groupId> <groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId> <artifactId>solr-solrj</artifactId>
<version>4.10.4</version> <version>7.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.directwebremoting</groupId> <groupId>org.directwebremoting</groupId>

View file

@ -105,7 +105,7 @@
<modules> <modules>
<module>home</module> <module>home</module>
<module>solr</module> <!--<module>solr</module>-->
<module>webapp</module> <module>webapp</module>
</modules> </modules>

View file

@ -67,7 +67,7 @@
<module>api</module> <module>api</module>
<module>dependencies</module> <module>dependencies</module>
<module>webapp</module> <module>webapp</module>
<module>solr</module> <!--<module>solr</module>-->
<module>home</module> <module>home</module>
</modules> </modules>