List Info

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




Re: solr-ruby - qt parameter with Dismax.rb
country flaguser name
United States
2008-01-21 21:36:39
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:ismax
offers:

class DemoRequest < Solr::Request:ismax
   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


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )