public class HttpSolrServer extends SolrServer
HttpSolrServer
uses the Apache HTTP Client 4.x to connect to solr.
SolrServer server = new HttpSolrServer( url );
Modifier and Type | Class and Description |
---|---|
private static class |
HttpSolrServer.DeflateDecompressingEntity |
private static class |
HttpSolrServer.GzipDecompressingEntity |
private static class |
HttpSolrServer.UseCompressionRequestInterceptor |
private static class |
HttpSolrServer.UseCompressionResponseInterceptor |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
AGENT
User-Agent String.
|
protected java.lang.String |
baseUrl
The URL of the Solr server.
|
private org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager |
ccm |
private static java.lang.String |
DEFAULT_PATH |
private boolean |
followRedirects
This defaults to false under the assumption that if you are following a
redirect to get to a Solr installation, something is misconfigured
somewhere.
|
private org.apache.http.client.HttpClient |
httpClient |
protected ModifiableSolrParams |
invariantParams
Default value: null / empty.
|
private static org.slf4j.Logger |
log |
private int |
maxRetries
Maximum number of retries to attempt in the event of transient errors.
|
protected ResponseParser |
parser
Default response parser is BinaryResponseParser
This parser represents the default Response Parser chosen to parse the
response if the parser were not specified as part of the request.
|
protected RequestWriter |
requestWriter
The RequestWriter used to write all requests to Solr
|
private static long |
serialVersionUID |
private boolean |
useMultiPartPost |
private static java.lang.String |
UTF_8 |
Constructor and Description |
---|
HttpSolrServer(java.lang.String baseURL) |
HttpSolrServer(java.lang.String baseURL,
org.apache.http.client.HttpClient client) |
HttpSolrServer(java.lang.String baseURL,
org.apache.http.client.HttpClient client,
ResponseParser parser) |
Modifier and Type | Method and Description |
---|---|
UpdateResponse |
add(java.util.Iterator<SolrInputDocument> docIterator)
Adds the documents supplied by the given iterator.
|
UpdateResponse |
addBeans(java.util.Iterator<?> beanIterator)
Adds the beans supplied by the given iterator.
|
private org.apache.http.impl.client.DefaultHttpClient |
createClient() |
java.lang.String |
getBaseURL() |
org.apache.http.client.HttpClient |
getHttpClient() |
ModifiableSolrParams |
getInvariantParams()
Retrieve the default list of parameters are added to every request
regardless.
|
ResponseParser |
getParser() |
NamedList<java.lang.Object> |
request(SolrRequest request)
Process the request.
|
NamedList<java.lang.Object> |
request(SolrRequest request,
ResponseParser processor) |
void |
setAllowCompression(boolean allowCompression)
Allow server->client communication to be compressed.
|
void |
setBaseURL(java.lang.String baseURL) |
void |
setConnectionTimeout(int timeout)
HttpConnectionParams.setConnectionTimeout
|
void |
setDefaultMaxConnectionsPerHost(int max) |
void |
setFollowRedirects(boolean followRedirects)
HttpClientParams.setRedirecting
|
void |
setMaxRetries(int maxRetries)
Set maximum number of retries to attempt in the event of transient errors.
|
void |
setMaxTotalConnections(int max)
Set the maximum number of connections that can be open at any given time.
|
void |
setParser(ResponseParser processor)
Note: This setter method is not thread-safe.
|
void |
setRequestWriter(RequestWriter requestWriter) |
void |
setSoTimeout(int timeout)
Sets HttpConnectionParams.setSoTimeout (read timeout).
|
void |
shutdown() |
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, rollback
private static final java.lang.String UTF_8
private static final java.lang.String DEFAULT_PATH
private static final long serialVersionUID
public static final java.lang.String AGENT
private static org.slf4j.Logger log
protected java.lang.String baseUrl
protected ModifiableSolrParams invariantParams
protected ResponseParser parser
BinaryResponseParser
protected RequestWriter requestWriter
RequestWriter
private final org.apache.http.client.HttpClient httpClient
private boolean followRedirects
private int maxRetries
private org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager ccm
private boolean useMultiPartPost
public HttpSolrServer(java.lang.String baseURL)
baseURL
- The URL of the Solr server. For example, "
http://localhost:8983/solr/
" if you are using the
standard distribution Solr webapp on your local machine.public HttpSolrServer(java.lang.String baseURL, org.apache.http.client.HttpClient client)
public HttpSolrServer(java.lang.String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser)
private org.apache.http.impl.client.DefaultHttpClient createClient()
public NamedList<java.lang.Object> request(SolrRequest request) throws SolrServerException, java.io.IOException
SolrRequest.getResponseParser()
is
null, then use getParser()
request
in class SolrServer
request
- The SolrRequest
to processNamedList
resultSolrServerException
java.io.IOException
request(org.apache.solr.client.solrj.SolrRequest,
org.apache.solr.client.solrj.ResponseParser)
public NamedList<java.lang.Object> request(SolrRequest request, ResponseParser processor) throws SolrServerException, java.io.IOException
SolrServerException
java.io.IOException
public ModifiableSolrParams getInvariantParams()
invariantParams
public java.lang.String getBaseURL()
public void setBaseURL(java.lang.String baseURL)
public ResponseParser getParser()
public void setParser(ResponseParser processor)
processor
- Default Response Parser chosen to parse the response if the parser
were not specified as part of the request.SolrRequest.getResponseParser()
public org.apache.http.client.HttpClient getHttpClient()
public void setConnectionTimeout(int timeout)
timeout
- Timeout in millisecondspublic void setSoTimeout(int timeout)
timeout
- Timeout in millisecondspublic void setFollowRedirects(boolean followRedirects)
followRedirects
public void setAllowCompression(boolean allowCompression)
public void setMaxRetries(int maxRetries)
maxRetries
- No more than 1 recommendedmaxRetries
public void setRequestWriter(RequestWriter requestWriter)
public UpdateResponse add(java.util.Iterator<SolrInputDocument> docIterator) throws SolrServerException, java.io.IOException
docIterator
- the iterator which returns SolrInputDocument instancesSolrServerException
java.io.IOException
public UpdateResponse addBeans(java.util.Iterator<?> beanIterator) throws SolrServerException, java.io.IOException
beanIterator
- the iterator which returns BeansSolrServerException
java.io.IOException
public void shutdown()
public void setDefaultMaxConnectionsPerHost(int max)
public void setMaxTotalConnections(int max)