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 ma...@sherpa-consulting.be on 2007/01/16 11:35:56 UTC

Calling Solr requests from java code - examples?

Hi,

Could someone give me some code examples on how Solr requests can be  
called by Java code. I'm new to Java and I'm not very sure on how URLs  
+ params can be called from java code and how the responses can be  
captured. Or what th best practices are?

Grtz






Re: Calling Solr requests from java code - examples?

Posted by Thorsten Scherler <th...@apache.org>.
On Tue, 2007-01-16 at 13:56 +0100, Bertrand Delacretaz wrote:
> On 1/16/07, Thorsten Scherler <th...@juntadeandalucia.es> wrote:
> 
> > ...Have a look at
> > https://issues.apache.org/jira/browse/SOLR-86...
> 
> Right, I should have mentioned this one as well. I have linked SOLR-20
> and SOLR-86 now, so that people can see the various options for Java
> clients.

Cheers, mate. :)

salu2
-- 
thorsten

"Together we stand, divided we fall!" 
Hey you (Pink Floyd)



Re: Calling Solr requests from java code - examples?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 1/16/07, Thorsten Scherler <th...@juntadeandalucia.es> wrote:

> ...Have a look at
> https://issues.apache.org/jira/browse/SOLR-86...

Right, I should have mentioned this one as well. I have linked SOLR-20
and SOLR-86 now, so that people can see the various options for Java
clients.

-Bertrand

Re: Calling Solr requests from java code - examples?

Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
On Tue, 2007-01-16 at 12:52 +0100, maarten@sherpa-consulting.be wrote:
> Thanks!
> 
> and how would you do it calling it from another web application, let's  
> say from a servlet or so? I need to do some stuff in my web java code,  
> then call the Solr service and do some more stuff afterwards
> 

Have a look at 
https://issues.apache.org/jira/browse/SOLR-86

HTH

salu2



Re: Calling Solr requests from java code - examples?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 1/16/07, Pavel Penchev <pa...@tkzs.org> wrote:

> ...What about the case where solr and my application are deployed in the
> same instance of say tomcat. Is there a way to skip the http requests
> and use a direct api?...

The javax.servlet.RequestDispatcher interface allows you to access
other resources (including servlets) running in the same container.
I've never used it but it looks like what you'd need (including a
custom HttpServletResponse class to capture the other servlet's
output).

See http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Servlets9.html#wp64684
which is part of
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html

Depending on how much faster this is than going the http way, it might
be interesting to include it as another protocol in a Java Solr
client.

-Bertrand

Re: Calling Solr requests from java code - examples?

Posted by Pavel Penchev <pa...@tkzs.org>.
A newbie question on the same topic:
What about the case where solr and my application are deployed in the 
same instance of say tomcat. Is there a way to skip the http requests 
and use a direct api?

Regards,
Pavel



Bertrand Delacretaz wrote:
> On 1/16/07, maarten@sherpa-consulting.be 
> <ma...@sherpa-consulting.be> wrote:
>
>> ...and how would you do it calling it from another web application, 
>> let's
>> say from a servlet or so?...
>
> Doesn't make much difference if your client is a standalone or a web
> application: you Solr client class will need to be configured with the
> base URL of the Solr server, it will make HTTP requests to it and
> parse the results as needed.
>
> -Bertrand
>
>


Re: Calling Solr requests from java code - examples?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 1/16/07, maarten@sherpa-consulting.be <ma...@sherpa-consulting.be> wrote:

> ...and how would you do it calling it from another web application, let's
> say from a servlet or so?...

Doesn't make much difference if your client is a standalone or a web
application: you Solr client class will need to be configured with the
base URL of the Solr server, it will make HTTP requests to it and
parse the results as needed.

-Bertrand

Re: Calling Solr requests from java code - examples?

Posted by ma...@sherpa-consulting.be.
Thanks!

and how would you do it calling it from another web application, let's  
say from a servlet or so? I need to do some stuff in my web java code,  
then call the Solr service and do some more stuff afterwards


Quoting Bertrand Delacretaz <bd...@apache.org>:

> On 1/16/07, maarten@sherpa-consulting.be   
> <ma...@sherpa-consulting.be> wrote:
>
>> ...Could someone give me some code examples on how Solr requests can be
>> called by Java code...
>
> Although our Java client landscape is still a bit fuzzy (there are
> several variants floating around), you might want to look at the code
> found in http://issues.apache.org/jira/browse/SOLR-20
>
> If you're new to Java, I'd recommend playing with HttpClient first
> (http://jakarta.apache.org/commons/httpclient/), see the tutorial
> there for the basics.
>
> The standard Java library classes are also usable to write HTTP
> clients, but HttpClient will help a lot in getting the "details"
> right, if you don't mind depending on that library.
>
> -Bertrand




Re: Calling Solr requests from java code - examples?

Posted by Bertrand Delacretaz <bd...@apache.org>.
On 1/16/07, maarten@sherpa-consulting.be <ma...@sherpa-consulting.be> wrote:

> ...Could someone give me some code examples on how Solr requests can be
> called by Java code...

Although our Java client landscape is still a bit fuzzy (there are
several variants floating around), you might want to look at the code
found in http://issues.apache.org/jira/browse/SOLR-20

If you're new to Java, I'd recommend playing with HttpClient first
(http://jakarta.apache.org/commons/httpclient/), see the tutorial
there for the basics.

The standard Java library classes are also usable to write HTTP
clients, but HttpClient will help a lot in getting the "details"
right, if you don't mind depending on that library.

-Bertrand