1
|
package eu.dnetlib.openaire.directindex.api;
|
2
|
|
3
|
import eu.dnetlib.functionality.index.utils.ZkServers;
|
4
|
import org.apache.commons.logging.Log;
|
5
|
import org.apache.commons.logging.LogFactory;
|
6
|
import org.apache.solr.client.solrj.impl.CloudSolrClient;
|
7
|
|
8
|
public class IndexClientManager {
|
9
|
|
10
|
private static final Log log = LogFactory.getLog(IndexClientManager.class);
|
11
|
|
12
|
private CloudSolrClient client = null;
|
13
|
|
14
|
public CloudSolrClient getClient(IndexDsInfo info) {
|
15
|
|
16
|
if (client == null) {
|
17
|
log.info(String.format("Initializing solr client (%s) with collection %s", info.getIndexBaseUrl(), info.getColl()));
|
18
|
ZkServers zk = ZkServers.newInstance(info.getIndexBaseUrl());
|
19
|
CloudSolrClient.Builder builder = new CloudSolrClient.Builder(zk.getHosts(), zk.getChroot()).withParallelUpdates(true);
|
20
|
client = builder.build();
|
21
|
}
|
22
|
client.setDefaultCollection(info.getColl());
|
23
|
return client;
|
24
|
}
|
25
|
|
26
|
}
|