Discussion:
The method getSolrServer() is undefined
Artur Zeiler
2008-10-20 11:50:45 UTC
Permalink
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
Chris Hostetter
2008-10-26 17:56:51 UTC
Permalink
: 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

"Upload" seems to be a class you have written, and you don't have a method
named getSolrServer() in the code you mailed out ... what are you
expecting that line of code to do?

: String url = "http://localhost:8080/solr";
: SolrServer server = new CommonsHttpSolrServer( url );
...
: server = getSolrServer(); // Here comes the Error :
: SolrServer server = getSolrServer();

...you've already assigned something to the "server" variable, so i'm not
sure what you want your getSolrServer() method to do ... and your code
shouldn't even compile becore you're trying to declare two variables named
"server" i nthe same scope.



-Hoss
Noble Paul നോബിള്‍ नोब्ळ्
2008-10-27 05:30:15 UTC
Permalink
I've updated the documentation at http://wiki.apache.org/solr/Solrj

all these code is not necessary
((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);

--Noble
Post by Chris Hostetter
Hi,
I'm new to Solr and have get the following error when i want to add Data to
SolrServer server = getSolrServer(); // The method getSolrServer() is
undefined for the type Upload
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);
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");
}
/**
*/
public static void main(String[] args) throws SolrServerException,
IOException
{
Upload test = new Upload ();
test.addData();
}
}
Can someone help ?
Thanks
--
--Noble Paul
Loading...