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

View file

@ -10,10 +10,13 @@ import java.util.Collection;
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.SolrServerException;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrServer;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
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.
*/
public class SolrSearchEngine implements SearchEngine {
private HttpSolrServer queryEngine;
private ConcurrentUpdateSolrServer updateEngine;
private SolrClient queryEngine;
private ConcurrentUpdateSolrClient updateEngine;
/**
* Set up the http connection with the solr server
@ -53,16 +56,26 @@ public class SolrSearchEngine implements SearchEngine {
}
try {
queryEngine = new HttpSolrServer(solrServerUrlString);
queryEngine.setSoTimeout(10000); // socket read timeout
queryEngine.setConnectionTimeout(10000);
queryEngine.setDefaultMaxConnectionsPerHost(100);
queryEngine.setMaxTotalConnections(100);
queryEngine.setMaxRetries(1);
HttpSolrClient.Builder builder = new HttpSolrClient.Builder(solrServerUrlString);
updateEngine = new ConcurrentUpdateSolrServer(solrServerUrlString, 100, 1);
updateEngine.setConnectionTimeout(10000);
updateEngine.setPollQueueTime(25);
builder.withSocketTimeout(10000); // socket read timeout
builder.withConnectionTimeout(10000);
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 + "'.");
} catch (Exception e) {
@ -72,8 +85,12 @@ public class SolrSearchEngine implements SearchEngine {
@Override
public void shutdown(Application application) {
queryEngine.shutdown();
updateEngine.shutdown();
try {
queryEngine.close();
} catch (IOException e) {
throw new RuntimeException("Error shutting down 'queryEngine'", e);
}
updateEngine.shutdownNow();
}
@Override
@ -170,7 +187,7 @@ public class SolrSearchEngine implements SearchEngine {
SolrQuery solrQuery = SolrConversionUtils.convertToSolrQuery(query);
QueryResponse response = queryEngine.query(solrQuery);
return SolrConversionUtils.convertToSearchResponse(response);
} catch (SolrServerException e) {
} catch (SolrServerException | IOException e) {
throw appropriateException(
"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 {
try {
HttpGet method = new HttpGet(solrUrl.toExternalForm());
HttpGet method = new HttpGet(solrUrl.toExternalForm() + "/select");
SolrSmokeTest.log.debug("Trying to connect to Solr");
HttpResponse response = httpClient.execute(method);
try {

View file

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

View file

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

View file

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