Hi,
I'm new to Solr and have get the following error when i want to add Data
to the Server instance:
SolrServer server = getSolrServer(); // The method getSolrServer() is
undefined for the type Upload
Here is the complete Code:
import java.io.IOException;
import java.net.MalformedURLException;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.apache.solr.common.SolrInputDocument;
public class Upload
{
public void addData() throws SolrServerException, IOException
{
Upload test = new Upload ();
String url = "http://localhost:8080/solr";
SolrServer server = new CommonsHttpSolrServer( url );
/*
* Setting XMLResponseParser
* SolrJ uses a binary format as the default format now
* For users with Solr 1.2 or older versions of Solr 1.3
* must explicitly ask SolrJ to use XML format
*/
((CommonsHttpSolrServer) server).setParser(new
BinaryResponseParser());
((CommonsHttpSolrServer) server).setParser(new
XMLResponseParser());
((CommonsHttpSolrServer) server).setSoTimeout(1000); // socket
read timeout
((CommonsHttpSolrServer) server).setConnectionTimeout(100);
((CommonsHttpSolrServer) server).setMaxRetries(1);
((CommonsHttpSolrServer) server).setMaxTotalConnections(10);
((CommonsHttpSolrServer) server).setFollowRedirects(false);
server = getSolrServer(); // Here comes the Error :
SolrServer server = getSolrServer();
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField( "id", "id1", 1.0f );
doc1.addField( "name", "doc1", 1.0f );
doc1.addField( "price", 10 );
server.add( doc1 );
server.commit();
System.out.println("Data commited");
}
/**
* @param args
* @throws IOException
* @throws SolrServerException
*/
public static void main(String[] args) throws SolrServerException,
IOException
{
Upload test = new Upload ();
test.addData();
}
}
Can someone help ?
Thanks