/*
*
* Most code from org.apache.solr.util.SimplePostTool
*
*
*/
package org.knoesis.apihut.util;
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.knoesis.apihut.Constants;
public class RemoteCallManager {
private static SolrServer server;
static{
try {
server = new CommonsHttpSolrServer(Constants.Remote.SOLR_URL);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
/*
* Get the server
*/
public static SolrServer getServer(){
return server;
}
public static void setupSchema(){
// no impl
throw new UnsupportedOperationException("Not implemented");
}
/*
* Update
*/
public static void sendUpdate(SolrInputDocument doc) throws IOException{
try {
UpdateResponse resp = server.add(doc);
/* Note that the update response status codes are not well documented. So the
* status check is skipped before commit
*/
// if (resp.getStatus()==200){
/*
Optional attributes for "commit" and "optimize"
waitFlush = "true" | "false" — default is true — block until index changes are flushed to disk
waitSearcher = "true" | "false" — default is true — block until a new searcher is opened and registered as the main query searcher, making the changes visible.
*/
server.commit(true,false);
//}
} catch (SolrServerException e) {
throw new IOException(e);
}
}
/*
* Perform a query
*/
public static QueryResponse sendSearch(SolrQuery query) throws IOException{
try {
return server.query(query);
} catch (SolrServerException e) {
throw new IOException(e);
}
}
}