lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: Java or PHP code to trigger solr?
Date Thu, 29 Jun 2006 03:32:23 GMT

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 = == :search ? "/solr/select" : "/ 
     post.body = body
     post.content_type = 'application/x-www-form-urlencoded'
     response = Net::HTTP.start(, @url.port) do |http|
     response_dom =

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)

So I can use IRB (via Rails slick script/console) and do this:

	solr =
	results =[{: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.


View raw message