You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Artur Zeiler <ar...@gmx.de> on 2008/10/20 13:50:45 UTC

The method getSolrServer() is undefined

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


Re: The method getSolrServer() is undefined

Posted by Chris Hostetter <ho...@fucit.org>.
: 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


Re: The method getSolrServer() is undefined

Posted by Noble Paul നോബിള്‍ नोब्ळ् <no...@gmail.com>.
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




On Mon, Oct 20, 2008 at 5:20 PM, Artur Zeiler <ar...@gmx.de> wrote:

> 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
>
>


-- 
--Noble Paul