Project

General

Profile

« Previous | Next » 

Revision 48891

upgraded solr version to 6.6.0

View differences:

SolrIndexCollection.java
1 1
package eu.dnetlib.functionality.index;
2 2

  
3
import java.io.IOException;
3 4
import java.util.Collection;
4 5
import java.util.Iterator;
5 6

  
6 7
import org.apache.commons.lang.StringUtils;
7 8
import org.apache.commons.logging.Log;
8 9
import org.apache.commons.logging.LogFactory;
9
import org.apache.solr.client.solrj.impl.CloudSolrServer;
10
import org.apache.solr.client.solrj.impl.CloudSolrClient;
10 11
import org.apache.solr.client.solrj.response.UpdateResponse;
11 12
import org.apache.solr.common.SolrInputDocument;
12 13

  
......
33 34
	public static final int STATUS_INDEX_OK = 0;
34 35

  
35 36
	/** The server. */
36
	private CloudSolrServer server;
37
	private CloudSolrClient client;
37 38

  
38 39
	private boolean shutdown = false;
39 40

  
40 41
	/**
41 42
	 * The Constructor.
42 43
	 *
43
	 * @param newServer
44
	 *            the server
45
	 * @param queryResponseFactory
46
	 *            the query response factory
44
	 * @param client
45
	 *            the client
47 46
	 */
48
	public SolrIndexCollection(final CloudSolrServer newServer) {
49
		this.server = newServer;
50
		server.connect();
47
	public SolrIndexCollection(final CloudSolrClient client) {
48
		this.client = client;
49
		client.connect();
51 50
	}
52 51

  
53 52
	/**
......
60 59
		if (isShutdown()) throw new IndexServiceException("Please get another SolrIndexCollection: this has been shut down");
61 60
		final SolrIndexDocument solrDocument = (SolrIndexDocument) doc;
62 61
		try {
63
			final UpdateResponse response = server.add(solrDocument.getSolrDocument());
62
			final UpdateResponse response = client.add(solrDocument.getSolrDocument());
64 63
			return response.getStatus() == 0;
65 64
		} catch (final Exception e) {
66 65
			throw new IndexServiceException("Unable to add document", e);
......
85 84
		});
86 85

  
87 86
		try {
88
			final UpdateResponse response = server.add(Lists.newArrayList(solrDocs));
87
			final UpdateResponse response = client.add(Lists.newArrayList(solrDocs));
89 88
			return response.getStatus() == 0;
90 89
		} catch (final Exception e) {
91 90
			throw new IndexServiceException("Unable to add document", e);
......
139 138
		if (isShutdown()) throw new IndexServiceException("Please get another SolrIndexCollection: this has been shut down");
140 139
		try {
141 140
			log.debug("delete by query: " + query);
142
			return server.deleteByQuery(query).getStatus() == STATUS_INDEX_OK;
141
			return client.deleteByQuery(query).getStatus() == STATUS_INDEX_OK;
143 142
		} catch (final Exception e) {
144 143
			throw new IndexServiceException("unable to run delete by query: " + query, e);
145 144
		}
......
155 154
		if (isShutdown()) throw new IndexServiceException("Please get another SolrIndexCollection: this has been shut down");
156 155
		try {
157 156
			log.info("performing commit");
158
			final UpdateResponse rsp = server.commit();
157
			final UpdateResponse rsp = client.commit();
159 158
			log.info(String.format("commit completed in %s, status %s", rsp.getElapsedTime(), rsp.getStatus()));
160 159
			return rsp.getStatus() == STATUS_INDEX_OK;
161 160
		} catch (final Throwable e) {
......
165 164

  
166 165
	@Override
167 166
	public void shutdown() {
168
		server.shutdown();
167
		try {
168
			client.close();
169
		} catch (IOException e) {
170
			throw new RuntimeException(e);
171
		}
169 172
		shutdown = true;
170 173
	}
171 174

  

Also available in: Unified diff