Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: ruby-dev

DirectSolrConnection / JRuby

 

 

Lucene ruby-dev RSS feed   Index | Next | Previous | View Threaded


erik at ehatchersolutions

Oct 8, 2008, 6:08 PM

Post #1 of 1 (3027 views)
Permalink
DirectSolrConnection / JRuby

DirectSolrConnection does work out pretty nicely:


require 'java'
require 'erb'

solr_dist_root = "/Users/erik/apache-solr-1.3.0"
solr_home = "/Users/erik/apache-solr-1.3.0/example/solr"

def require_jars(dir)
jar_pattern = File.join(dir,"**", "*.jar")
jar_files = Dir.glob(jar_pattern)

jar_files.each {|jar_file| require jar_file}
end

require_jars(File.join(solr_dist_root, "lib"))
require_jars(File.join(solr_dist_root, "dist"))

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer
import org.apache.solr.core.CoreContainer
import org.apache.solr.core.CoreDescriptor
import org.apache.solr.common.params.ModifiableSolrParams
import org.apache.solr.common.params.MapSolrParams
import org.apache.solr.servlet.DirectSolrConnection

container = CoreContainer.new
descriptor = CoreDescriptor.new(container, "core1", solr_home)
core = container.create(descriptor)
container.register("core1", core, false)

class Request
def initialize(params)
@params = params
end

def handler
'select'
end

def content_type
'application/x-www-form-urlencoded; charset=utf-8'
end

def to_s
http_params = []
@params.each do |key,value|
if value.respond_to? :each
value.each { |v| http_params <<
"#{key}=#{ERB::Util::url_encode(v)}" unless v.nil?}
else
http_params << "#{key}=#{ERB::Util::url_encode(value)}"
unless value.nil?
end
end

http_params.join("&")
end
end

solr = DirectSolrConnection.new(solr_home,File.join(solr_home,"solr",
"data"),nil)
request = Request.new(:qt => 'standard', :q => '*:*', 'facet.field' =>
['cat'], :wt=>'ruby')
response = solr.request("/#{request.handler}?#{request.to_s}",nil)
puts response
solr.close
core.close

The response is the raw String response, suitable for eval'ing if
wt=ruby.

So, for embedded SolrJRuby work, this will be the most transparent way
to go I think.

The question I have is whether we should concern ourselves with
SolrJ's CommonsHttpSolrServer? I suspect if you're in a JRuby
environment that SolrJ's API will be faster performance-wise than
eval'ing Ruby responses. Testing warranted for sure.

Erik

Lucene ruby-dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.