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 UpAndGone <up...@web.de> on 2006/06/28 21:39:55 UTC
Java or PHP code to trigger solr?
Hello,
I was just planning to write a web service like front-end to Lucene when I
heard of this project. Are there any examples on integrating Solr yet? I see
the wiki section, but it is empty. How can I trigger solr, say from my Java
app without using curl?
Thanks
Christian
RE: Java or PHP code to trigger solr?
Posted by Brian Lucas <bl...@gmail.com>.
No, curl support is compiled into PHP and is extremely stable so there's no
command shell or POSIX stability issues to deal with -- just direct C
interfacing.
Also, there is a way for PHP to talk to HTTP directly -- while I can post
that method, it's probably not necessary. The curl libraries have been
included in most PHP distros for quite some time and are simply superior to
any other method of sending and receiving data over HTTP sockets.
Without attempting to generalize too much, there aren't too many reasons
that one shouldn't have curl support enabled on their PHP distribution.
Brian
-----Original Message-----
From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
Sent: Wednesday, June 28, 2006 9:35 PM
To: solr-user@lucene.apache.org
Subject: Re: Java or PHP code to trigger solr?
On Jun 28, 2006, at 5:26 PM, Brian Lucas wrote:
> Ok, I uploaded the initial versions: http://wiki.apache.org/solr/
> SolPHP
Wow, so you shell to "curl". Interesting! Surely there is a PHP
way to simply talk HTTP directly? (never having code a line of PHP
ever)
Erik
Re: Java or PHP code to trigger solr?
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 28, 2006, at 5:26 PM, Brian Lucas wrote:
> Ok, I uploaded the initial versions: http://wiki.apache.org/solr/
> SolPHP
Wow, so you shell to "curl". Interesting! Surely there is a PHP
way to simply talk HTTP directly? (never having code a line of PHP
ever)
Erik
AW: Java or PHP code to trigger solr?
Posted by UpAndGone <up...@web.de>.
Wow, that was fast! :-) Thank you very much!
Brian Lucas:
> Ok, I uploaded the initial versions: http://wiki.apache.org/solr/SolPHP
Mike Baranczak
> Here's a Java client for Solr:
>
> http://issues.apache.org/jira/browse/SOLR-20
RE: Java or PHP code to trigger solr?
Posted by Brian Lucas <bl...@gmail.com>.
Ok, I uploaded the initial versions: http://wiki.apache.org/solr/SolPHP
Keep in mind that because of the application-specific nature of these
searches, I have been using a version adapted to my own needs. I attempted
to abstract this version as much as possible but didn't test it after I
stripped away certain things (debugging code, logging code). If there's a
need for that stuff, I'll include it in the next version.
I just wanted to get something out there for you folks initially to start
using.
Let me know how it works. You'll need ADODB to use it properly.
TO-DO:
- clean up some of the XML writing code -- it's a tad "kludgy" right now.
- abstract out more of the logic into configurable variables
- add back in the logging and debugging classes that clean up the "echo"
calls
Now it's on to the rails version.
Brian
-----Original Message-----
From: Michael J. Giarlo [mailto:leftwing@u.washington.edu]
Sent: Wednesday, June 28, 2006 2:52 PM
To: solr-user@lucene.apache.org
Subject: Re: Java or PHP code to trigger solr?
I believe Brian Lucas was writing PHP bindings --
http://wiki.apache.org/solr/SolPHP
How's that going, anyway? I'm pretty eager to get my grubby mitts on it.
-Mike
Mike Baranczak wrote:
> Here's a Java client for Solr:
>
> http://issues.apache.org/jira/browse/SOLR-20
>
> Erik Hatcher was recently talking about a Ruby-on-Rails interface for
> Solr, but I don't know what the status is on that. As far as I know,
> nobody has yet written interfaces for PHP or CF, but it shouldn't be
> that hard; it's just a question of creating an XML document and sending
> it over HTTP.
>
> -MB
>
Re: Java or PHP code to trigger solr?
Posted by "Michael J. Giarlo" <le...@u.washington.edu>.
I believe Brian Lucas was writing PHP bindings --
http://wiki.apache.org/solr/SolPHP
How's that going, anyway? I'm pretty eager to get my grubby mitts on it.
-Mike
Mike Baranczak wrote:
> Here's a Java client for Solr:
>
> http://issues.apache.org/jira/browse/SOLR-20
>
> Erik Hatcher was recently talking about a Ruby-on-Rails interface for
> Solr, but I don't know what the status is on that. As far as I know,
> nobody has yet written interfaces for PHP or CF, but it shouldn't be
> that hard; it's just a question of creating an XML document and sending
> it over HTTP.
>
> -MB
>
Re: Java or PHP code to trigger solr?
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 28, 2006, at 4:22 PM, Mike Baranczak wrote:
> Erik Hatcher was recently talking about a Ruby-on-Rails interface
> for Solr, but I don't know what the status is on that. As far as I
> know, nobody has yet written interfaces for PHP or CF, but it
> shouldn't be that hard; it's just a question of creating an XML
> document and sending it over HTTP.
My current code has not been distilled into a clean API, but it's
usable. It all boils down to this:
def post_to_solr(body, mode = :search)
post = Net::HTTP::Post.new(mode == :search ? "/solr/select" : "/
solr/update")
post.body = body
post.content_type = 'application/x-www-form-urlencoded'
response = Net::HTTP.start(@url.host, @url.port) do |http|
http.request(post)
end
response_dom = Document.new(response.body)
end
though using REXML's Document is likely to be pulled out to something
more optimal for Ruby ingesting, such as YAML.
This sits in a Solr class and has utility methods like this:
def optimize
post_to_solr('<optimize waitFlush="false" waitSearcher="false"/
>', :update)
end
So I can use IRB (via Rails slick script/console) and do this:
solr = Solr.new
results = solr.search([{:field => "year", :value => "1865"}], 0, 20)
I'm tinkering around with various custom request handlers, custom
parameters, and faceted results so nothing has settled down into a
stable way to do things just yet, so I haven't felt the
generalization falling into place yet. I sincerely hope someone Solr/
Lucene/Java and Ruby savvier than I will eventually step up and build
a super slick Solr Ruby DSL :) But it needs to be more flexible than
just the standard request handler to be of use to me, so it's more
complex than meets the eye.
Erik
Re: Java or PHP code to trigger solr?
Posted by Mike Baranczak <MB...@ePublishing.com>.
Here's a Java client for Solr:
http://issues.apache.org/jira/browse/SOLR-20
Erik Hatcher was recently talking about a Ruby-on-Rails interface for
Solr, but I don't know what the status is on that. As far as I know,
nobody has yet written interfaces for PHP or CF, but it shouldn't be
that hard; it's just a question of creating an XML document and
sending it over HTTP.
-MB
On Jun 28, 2006, at 3:54 PM, Tim Archambault wrote:
> I'm curious as well as I am creating a CFMX interface for Solr. If you
> wouldn't mind sharing info, please do.
>
> On 6/28/06, UpAndGone <up...@web.de> wrote:
>>
>> Hello,
>>
>>
>>
>> I was just planning to write a web service like front-end to
>> Lucene when I
>> heard of this project. Are there any examples on integrating Solr
>> yet? I
>> see
>> the wiki section, but it is empty. How can I trigger solr, say
>> from my
>> Java
>> app without using curl?
>>
>>
>>
>> Thanks
>>
>> Christian
>>
>>
>>
>>
>>
>>
>>
>>
>>
Re: Java or PHP code to trigger solr?
Posted by Tim Archambault <ta...@bangordailynews.net>.
I'm curious as well as I am creating a CFMX interface for Solr. If you
wouldn't mind sharing info, please do.
On 6/28/06, UpAndGone <up...@web.de> wrote:
>
> Hello,
>
>
>
> I was just planning to write a web service like front-end to Lucene when I
> heard of this project. Are there any examples on integrating Solr yet? I
> see
> the wiki section, but it is empty. How can I trigger solr, say from my
> Java
> app without using curl?
>
>
>
> Thanks
>
> Christian
>
>
>
>
>
>
>
>
>
Re: Java or PHP code to trigger solr?
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 28, 2006, at 3:39 PM, UpAndGone wrote:
> I was just planning to write a web service like front-end to Lucene
> when I
> heard of this project. Are there any examples on integrating Solr
> yet? I see
> the wiki section, but it is empty. How can I trigger solr, say from
> my Java
> app without using curl?
My indexer currently does this to post to Solr from Java:
private void postToSolr(String xml) throws IOException {
// System.out.println("-------------");
// System.out.println("xml = " + xml);
// System.out.println("-------------");
PostMethod post = new PostMethod("http://localhost:8983/solr/
update");
post.setRequestEntity(new StringRequestEntity(xml));
post.setRequestHeader("Content-type", "text/xml; charset=utf-8");
HttpClient httpclient = new HttpClient();
// Execute request
try {
int result = httpclient.executeMethod(post);
String response = post.getResponseBodyAsString();
// System.out.println(response);
Pattern pattern = Pattern.compile("status=\\\"(\\d*)\\\">(.*)\
\<\\/result\\>", Pattern.DOTALL);
Matcher matcher = pattern.matcher(response);
while (matcher.find()) {
String status = matcher.group(1);
String message = matcher.group(2);
if (!"0".equals(status)) {
throw new IOException(message);
}
}
} finally {
// Release current connection to the connection pool once you
are done
post.releaseConnection();
}
}
postToSolr("<commit/>"); // for example
My error checking is lame though, mainly because Solr doesn't (or
didn't?) send an HTTP error response when bad things happened in a
request handler for instance.
I've been too lazy (well, ok, swamped) to pull out this flakey custom
hacked code with this much more elegant and robust API contributed
here <http://issues.apache.org/jira/browse/SOLR-20>. This will be
incorporated in Solr's codebase in some form when we figure out where
to put it, how to distributed it, and document it. If you use it,
feedback on it would be appreciated.
Erik