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

java.lang.Object
  extended by org.apache.solr.client.solrj.SolrServer
      extended by org.apache.solr.client.solrj.impl.CommonsHttpSolrServer
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
StreamingUpdateSolrServer

public class CommonsHttpSolrServer
extends SolrServer

The CommonsHttpSolrServer uses the Apache Commons HTTP Client to connect to solr.

SolrServer server = new CommonsHttpSolrServer( url );

Since:
solr 1.3
Version:
$Id: CommonsHttpSolrServer.java 1170589 2011-09-14 13:03:51Z janhoy $
See Also:
Serialized Form

Field Summary
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.

static String AGENT
          User-Agent String as identified by the HTTP request by the HttpClient to the Solr server from the client.
protected  RequestWriter requestWriter
          The RequestWriter used to write all requests to Solr
 
Constructor Summary
CommonsHttpSolrServer(String solrServerUrl)
           
CommonsHttpSolrServer(String solrServerUrl, org.apache.commons.httpclient.HttpClient httpClient)
          Talk to the Solr server via the given HttpClient.
CommonsHttpSolrServer(String solrServerUrl, org.apache.commons.httpclient.HttpClient httpClient, boolean useMultiPartPost)
           
CommonsHttpSolrServer(String solrServerUrl, org.apache.commons.httpclient.HttpClient httpClient, ResponseParser parser)
           
CommonsHttpSolrServer(URL baseURL)
           
CommonsHttpSolrServer(URL baseURL, org.apache.commons.httpclient.HttpClient client)
           
CommonsHttpSolrServer(URL baseURL, org.apache.commons.httpclient.HttpClient client, boolean useMultiPartPost)
           
CommonsHttpSolrServer(URL baseURL, org.apache.commons.httpclient.HttpClient client, ResponseParser parser, boolean useMultiPartPost)
           
 
Method Summary
 UpdateResponse add(Iterator<SolrInputDocument> docIterator)
          Adds the documents supplied by the given iterator.
 UpdateResponse add(Iterator<SolrInputDocument> docIterator, int commitWithinMs)
          Adds the documents supplied by the given iterator, specifying max time before they become committed
 UpdateResponse addBeans(Iterator<?> beanIterator)
          Adds the beans supplied by the given iterator
 UpdateResponse addBeans(Iterator<?> beanIterator, int commitWithinMs)
          Adds the beans supplied by the given iterator, specifying max time before they become committed
 String getBaseURL()
           
 org.apache.commons.httpclient.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)
          set allowCompression.
 void setBaseURL(String baseURL)
           
 void setConnectionManagerTimeout(int timeout)
          Deprecated. Use setConnectionManagerTimeout(long)
 void setConnectionManagerTimeout(long timeout)
          Sets soTimeout (read timeout) on the underlying HttpConnectionManager.
 void setConnectionTimeout(int timeout)
          set connectionTimeout on the underlying HttpConnectionManager
 void setDefaultMaxConnectionsPerHost(int connections)
          set maxConnectionsPerHost on the underlying HttpConnectionManager
 void setFollowRedirects(boolean followRedirects)
          set followRedirects.
 void setMaxRetries(int maxRetries)
          set maximum number of retries to attempt in the event of transient errors.
 void setMaxTotalConnections(int connections)
          set maxTotalConnection on the underlying HttpConnectionManager
 void setParser(ResponseParser processor)
          Note: This setter method is not thread-safe.
 void setRequestWriter(RequestWriter requestWriter)
           
 void setSoTimeout(int timeout)
          Sets soTimeout (read timeout) on the underlying HttpConnectionManager.
 
Methods inherited from class org.apache.solr.client.solrj.SolrServer
add, add, add, add, addBean, addBean, addBeans, addBeans, commit, commit, deleteById, deleteById, 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 as identified by the HTTP request by the HttpClient to the Solr server from the client.


_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

CommonsHttpSolrServer

public CommonsHttpSolrServer(String solrServerUrl)
                      throws MalformedURLException
Parameters:
solrServerUrl - 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.
Throws:
MalformedURLException

CommonsHttpSolrServer

public CommonsHttpSolrServer(String solrServerUrl,
                             org.apache.commons.httpclient.HttpClient httpClient)
                      throws MalformedURLException
Talk to the Solr server via the given HttpClient. The connection manager for the client should be a MultiThreadedHttpConnectionManager if this client is being reused across SolrServer instances, or of multiple threads will use this SolrServer.

Throws:
MalformedURLException

CommonsHttpSolrServer

public CommonsHttpSolrServer(String solrServerUrl,
                             org.apache.commons.httpclient.HttpClient httpClient,
                             boolean useMultiPartPost)
                      throws MalformedURLException
Throws:
MalformedURLException

CommonsHttpSolrServer

public CommonsHttpSolrServer(String solrServerUrl,
                             org.apache.commons.httpclient.HttpClient httpClient,
                             ResponseParser parser)
                      throws MalformedURLException
Throws:
MalformedURLException

CommonsHttpSolrServer

public CommonsHttpSolrServer(URL 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.

CommonsHttpSolrServer

public CommonsHttpSolrServer(URL baseURL,
                             org.apache.commons.httpclient.HttpClient client)

CommonsHttpSolrServer

public CommonsHttpSolrServer(URL baseURL,
                             org.apache.commons.httpclient.HttpClient client,
                             boolean useMultiPartPost)
See Also:
useMultiPartPost

CommonsHttpSolrServer

public CommonsHttpSolrServer(URL baseURL,
                             org.apache.commons.httpclient.HttpClient client,
                             ResponseParser parser,
                             boolean useMultiPartPost)
See Also:
useMultiPartPost, _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,
                                 IOException
Throws:
SolrServerException
IOException

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.commons.httpclient.HttpClient getHttpClient()

setConnectionTimeout

public void setConnectionTimeout(int timeout)
set connectionTimeout on the underlying HttpConnectionManager

Parameters:
timeout - Timeout in milliseconds

setConnectionManagerTimeout

@Deprecated
public void setConnectionManagerTimeout(int timeout)
Deprecated. Use setConnectionManagerTimeout(long)

set connectionManagerTimeout on the HttpClient.

Parameters:
timeout - Timeout in milliseconds

setConnectionManagerTimeout

public void setConnectionManagerTimeout(long timeout)
Sets soTimeout (read timeout) on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing.

Parameters:
timeout - Timeout in milliseconds

setSoTimeout

public void setSoTimeout(int timeout)
Sets soTimeout (read timeout) on the underlying HttpConnectionManager. This is desirable for queries, but probably not for indexing.

Parameters:
timeout - Timeout in milliseconds

setDefaultMaxConnectionsPerHost

public void setDefaultMaxConnectionsPerHost(int connections)
set maxConnectionsPerHost on the underlying HttpConnectionManager


setMaxTotalConnections

public void setMaxTotalConnections(int connections)
set maxTotalConnection on the underlying HttpConnectionManager


setFollowRedirects

public void setFollowRedirects(boolean followRedirects)
set followRedirects.

See Also:
_followRedirects

setAllowCompression

public void setAllowCompression(boolean allowCompression)
set allowCompression.

See Also:
_allowCompression

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

add

public UpdateResponse add(Iterator<SolrInputDocument> docIterator,
                          int commitWithinMs)
                   throws SolrServerException,
                          IOException
Adds the documents supplied by the given iterator, specifying max time before they become committed

Parameters:
docIterator - the iterator which returns SolrInputDocument instances
commitWithinMs - the time in milliseconds before a commit automatically is triggered
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

addBeans

public UpdateResponse addBeans(Iterator<?> beanIterator,
                               int commitWithinMs)
                        throws SolrServerException,
                               IOException
Adds the beans supplied by the given iterator, specifying max time before they become committed

Parameters:
commitWithinMs - the time in milliseconds before a commit automatically is triggered
beanIterator - the iterator which returns Beans
Returns:
the response from the SolrServer
Throws:
SolrServerException
IOException


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.