You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ruby-dev@lucene.apache.org by Koji Sekiguchi <ko...@r.email.ne.jp> on 2008/01/12 17:29:28 UTC

solr-ruby - qt parameter with Dismax.rb

Hello solr-ruby & Flare folks!

I have the following request handler defined in solrconfig.xml:

<requestHandler name="demo" class="solr.DisMaxRequestHandler" >
<lst name="defaults">
<str name="echoParams">explicit</str>
<float name="tie">0.01</float>
<str name="qf">
body body_exact^2.0
</str>
<str name="fl">
id,body,score
</str>
<str name="q.alt">*:*</str>
<str name="hl">on</str>
<str name="hl.fl">body</str>
<str name="f.body.hl.fragsize">0</str>
<str name="f.body.hl.alternateField">body</str>
</lst>
</requestHandler>

To use the request handler, I'd like to specify qt=demo for Dismax.rb.
However, I cannot find how to do it.

I've checked Select.rb and it seems to consider qt parameter:

class Solr::Request::Select < Solr::Request::Base
def initialize(qt=nil, params={})
@query_type = qt
@select_params = params
end
end

But Standard.rb specify qt='standard':

class Solr::Request::Standard < Solr::Request::Select
def initialize(params)
super('standard')
end
end

Is there a way to specify qt='demo' with Dismax.rb?


Thanks in advance,

Koji


Re: solr-ruby - qt parameter with Dismax.rb

Posted by Koji Sekiguchi <ko...@r.email.ne.jp>.
Hello Erik,

 > class DemoRequest < Solr::Request::Dismax
 >   def initialize(params)
 >     super
 >     @query_type = "demo"
 >   end
 > end

This is a totally same way what I did to solve my problem.
I wasn't sure that my solution was reasonable in terms of Ruby,
but now I can be confident with this by your reply and your further 
description.

Thank you very much, Erik!

Koji



Re: solr-ruby - qt parameter with Dismax.rb

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Koji,

My apologies for the belated reply.


On Jan 12, 2008, at 11:29 AM, Koji Sekiguchi wrote:
> I have the following request handler defined in solrconfig.xml:
>
> <requestHandler name="demo" class="solr.DisMaxRequestHandler" >
> <lst name="defaults">
> <str name="echoParams">explicit</str>
> <float name="tie">0.01</float>
> <str name="qf">
> body body_exact^2.0
> </str>
> <str name="fl">
> id,body,score
> </str>
> <str name="q.alt">*:*</str>
> <str name="hl">on</str>
> <str name="hl.fl">body</str>
> <str name="f.body.hl.fragsize">0</str>
> <str name="f.body.hl.alternateField">body</str>
> </lst>
> </requestHandler>
>
> To use the request handler, I'd like to specify qt=demo for Dismax.rb.
> However, I cannot find how to do it.

Here's the trick, to benefit from the parameter handling that  
Solr::Request::Dismax offers:

class DemoRequest < Solr::Request::Dismax
   def initialize(params)
     super
     @query_type = "demo"
   end
end

and even a unit test :)

   def test_demo
     f = DemoRequest.new(:query => "whatever")
     assert_equal("demo", f.query_type)
   end


Further, in general you can use solr-ruby's Solr::Connection#post  
method to call into most any Solr request handler, just adhering to  
the duck quacking that given here:

   def post(request)
     response = @connection.post(@url.path + "/" + request.handler,
                                 request.to_s,
                                 { "Content-Type" =>  
request.content_type })

     case response
     when Net::HTTPSuccess then response.body
     else
       response.error!
     end

   end

So as long as the "request" object has #handler, #to_s, and  
#content_type methods.  You can see how these work with the simple  
Solr::Request::Base and Solr::Request::Select classes.

One nagging issue I have with the current solr-ruby design is with  
the Connection#send method, which requires parallel Request and  
Response classes, but if you want to build your own very simple  
request/response classes you could use Connection#send even easier.

Sorry if that last bit of trivia was too much (confusing) information  
- I just wanted to toss that out to show that it's actually not too  
much coding to do these custom requests to Solr.

I definitely can see making solr-ruby more amenable to your "demo"- 
like scenarios, as mapping custom request handlers in Solr is really  
the way to go for many reasons.

	Erik