On 2/4/2013 3:33 PM, Michael Della Bitta wrote:
Ah, OK, sorry to be terse!
1. Create a class that implements SolrServer from the SolrJ project:
http://lucene.apache.org/solr/4_1_0/solr-solrj/org/apache/solr/client/solrj/SolrServer.html
2. Make the constructor of that class take as arguments the config you
need to make an HttpSolrServer object and store them in member fields.
3. Make a private field for an HttpSolrServer instance but leave it null.
4. Create a private method called getSolrServer() that creates an
HttpSolrServer and assigns it to the private field and returns it if
successful, otherwise it catches and logs the exception that is
thrown.
5. For each of the methods in SolrServer that you need to override,
have it call getSolrServer() and call the same method on the returned
instance if it's not null, e.g.,
public UpdateResponse add(SolrInputDocument doc)
throws SolrServerException,
IOException {
SolrServer solrServer = getSolrServer();
if (solrServer != null) {
return solrServer.add(doc);
}
return new UpdateResponse();
}
You may want to return something other than an empty UpdateResponse
when things fail. That's up to you.
6. Refactor your project to use your SolrServer implementation.
Generally speaking, is it preferred to use a wrapper approach like
you've described or add a method to SolrServer and its implementations?
Whatever I come up with, I'd like to contribute to the project, and if
I'm doing that, I would think it's better to improve what's already
there than add a class.
Thanks,
Shawn