Calling Solr requests from java code - examples?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Calling Solr requests from java code - examples?

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





Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Bertrand Delacretaz
On 1/16/07, [hidden email] <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

maarten-14
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 <[hidden email]>:

> On 1/16/07, [hidden email]  
> <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Bertrand Delacretaz
On 1/16/07, [hidden email] <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Pavel Penchev
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, [hidden email]
> <[hidden email]> 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
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Thorsten Scherler-3
In reply to this post by maarten-14
On Tue, 2007-01-16 at 12:52 +0100, [hidden email] 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


Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Bertrand Delacretaz
In reply to this post by Pavel Penchev
On 1/16/07, Pavel Penchev <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

Bertrand Delacretaz
In reply to this post by Thorsten Scherler-3
On 1/16/07, Thorsten Scherler <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Calling Solr requests from java code - examples?

thorsten
On Tue, 2007-01-16 at 13:56 +0100, Bertrand Delacretaz wrote:
> On 1/16/07, Thorsten Scherler <[hidden email]> 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)