org.apache.solr.client.solrj.impl
Class HttpSolrServer

java.lang.Object
  extended by org.apache.solr.client.solrj.SolrServer
      extended by org.apache.solr.client.solrj.impl.HttpSolrServer
All Implemented Interfaces:
Serializable

public class HttpSolrServer
extends SolrServer

The HttpSolrServer uses the Apache HTTP Client 4.x to connect to solr.

SolrServer server = new HttpSolrServer( url );

See Also:
Serialized Form

Field Summary
static String AGENT
          User-Agent String.
protected  String baseUrl
          The URL of the Solr server.
protected  ModifiableSolrParams invariantParams
          Default value: null / empty.
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
 
Constructor Summary
HttpSolrServer(String baseURL)
           
HttpSolrServer(String baseURL, org.apache.http.client.HttpClient client)
           
HttpSolrServer(String baseURL, org.apache.http.client.HttpClient client, ResponseParser parser)
           
 
Method Summary
 UpdateResponse add(Iterator<SolrInputDocument> docIterator)
          Adds the documents supplied by the given iterator.
 UpdateResponse addBeans(Iterator<?> beanIterator)
          Adds the beans supplied by the given iterator.
 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<Object> request(SolrRequest request)
          Process the request.
 NamedList<Object> request(SolrRequest request, ResponseParser processor)
           
 void setAllowCompression(boolean allowCompression)
          Allow server->client communication to be compressed.
 void setBaseURL(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()
           
 
Methods inherited from class org.apache.solr.client.solrj.SolrServer
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, deleteById, deleteById, deleteById, deleteById, deleteByQuery, deleteByQuery, getBinder, optimize, optimize, optimize, ping, query, query, rollback
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AGENT

public static final String AGENT
User-Agent String.


baseUrl

protected String baseUrl
The URL of the Solr server.


invariantParams

protected ModifiableSolrParams invariantParams
Default value: null / empty.

Parameters that are added to every request regardless. This may be a place to add something like an authentication token.


parser

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.

See Also:
BinaryResponseParser

requestWriter

protected RequestWriter requestWriter
The RequestWriter used to write all requests to Solr

See Also:
RequestWriter
Constructor Detail

HttpSolrServer

public HttpSolrServer(String baseURL)
Parameters:
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.

HttpSolrServer

public HttpSolrServer(String baseURL,
                      org.apache.http.client.HttpClient client)

HttpSolrServer

public HttpSolrServer(String baseURL,
                      org.apache.http.client.HttpClient client,
                      ResponseParser parser)
Method Detail

request

public NamedList<Object> request(SolrRequest request)
                          throws SolrServerException,
                                 IOException
Process the request. If SolrRequest.getResponseParser() is null, then use getParser()

Specified by:
request in class SolrServer
Parameters:
request - The SolrRequest to process
Returns:
The NamedList result
Throws:
SolrServerException
IOException
See Also:
request(org.apache.solr.client.solrj.SolrRequest, org.apache.solr.client.solrj.ResponseParser)

request

public NamedList<Object> request(SolrRequest request,
                                 ResponseParser processor)
                          throws SolrServerException
Throws:
SolrServerException

getInvariantParams

public ModifiableSolrParams getInvariantParams()
Retrieve the default list of parameters are added to every request regardless.

See Also:
invariantParams

getBaseURL

public String getBaseURL()

setBaseURL

public void setBaseURL(String baseURL)

getParser

public ResponseParser getParser()

setParser

public void setParser(ResponseParser processor)
Note: This setter method is not thread-safe.

Parameters:
processor - Default Response Parser chosen to parse the response if the parser were not specified as part of the request.
See Also:
SolrRequest.getResponseParser()

getHttpClient

public org.apache.http.client.HttpClient getHttpClient()

setConnectionTimeout

public void setConnectionTimeout(int timeout)
HttpConnectionParams.setConnectionTimeout

Parameters:
timeout - Timeout in milliseconds

setSoTimeout

public void setSoTimeout(int timeout)
Sets HttpConnectionParams.setSoTimeout (read timeout). This is desirable for queries, but probably not for indexing.

Parameters:
timeout - Timeout in milliseconds

setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
HttpClientParams.setRedirecting

See Also:
followRedirects

setAllowCompression

public void setAllowCompression(boolean allowCompression)
Allow server->client communication to be compressed. Currently gzip and deflate are supported. If the server supports compression the response will be compressed.


setMaxRetries

public void setMaxRetries(int maxRetries)
Set maximum number of retries to attempt in the event of transient errors.

Parameters:
maxRetries - No more than 1 recommended
See Also:
maxRetries

setRequestWriter

public void setRequestWriter(RequestWriter requestWriter)

add

public UpdateResponse add(Iterator<SolrInputDocument> docIterator)
                   throws SolrServerException,
                          IOException
Adds the documents supplied by the given iterator.

Parameters:
docIterator - the iterator which returns SolrInputDocument instances
Returns:
the response from the SolrServer
Throws:
SolrServerException
IOException

addBeans

public UpdateResponse addBeans(Iterator<?> beanIterator)
                        throws SolrServerException,
                               IOException
Adds the beans supplied by the given iterator.

Parameters:
beanIterator - the iterator which returns Beans
Returns:
the response from the SolrServer
Throws:
SolrServerException
IOException

shutdown

public void shutdown()

setDefaultMaxConnectionsPerHost

public void setDefaultMaxConnectionsPerHost(int max)

setMaxTotalConnections

public void setMaxTotalConnections(int max)
Set the maximum number of connections that can be open at any given time.