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

Mailing List Archive: Lucene: ruby-dev

jruby and solrj

 

 

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


goodieboy at gmail

Oct 5, 2008, 7:54 PM

Post #1 of 6 (5743 views)
Permalink
jruby and solrj

I've been messing around with jRuby and SolrJ with nice results. But can't
seem to get the SolrQuery.addFacetField method to work. I get this error:

"for method addFacetField expected [[Ljava.lang.String;]; got:
[java.lang.String]; error: argument type mismatch (TypeError)"

I'm using it like:

query.add_facet_field 'cat'

and also tried:

query.addFacetField 'cat'

Any ideas as to what I'm doing wrong?

Matt

p.s. The other methods I've tried work great: set_query, set_query_type,
set_facet, set_facet_limit, set_facet_min_count, set_include_score,
add_sort_field.


ryantxu at gmail

Oct 5, 2008, 10:36 PM

Post #2 of 6 (5506 views)
Permalink
Re: jruby and solrj [In reply to]

just guessing, but try passing that as a string[] rather then just a
string

The java function takes ( string ... v ) -- in java that means you can
pass either a string or an array, or a variable length list of
strings. I'm guessing that does something funny with jruby

ryan


On Oct 5, 2008, at 10:54 PM, Matt Mitchell wrote:

> I've been messing around with jRuby and SolrJ with nice results. But
> can't
> seem to get the SolrQuery.addFacetField method to work. I get this
> error:
>
> "for method addFacetField expected [[Ljava.lang.String;]; got:
> [java.lang.String]; error: argument type mismatch (TypeError)"
>
> I'm using it like:
>
> query.add_facet_field 'cat'
>
> and also tried:
>
> query.addFacetField 'cat'
>
> Any ideas as to what I'm doing wrong?
>
> Matt
>
> p.s. The other methods I've tried work great: set_query,
> set_query_type,
> set_facet, set_facet_limit, set_facet_min_count, set_include_score,
> add_sort_field.


erik at ehatchersolutions

Oct 6, 2008, 12:59 PM

Post #3 of 6 (5470 views)
Permalink
Re: jruby and solrj [In reply to]

Unfortunately, to call varargs from JRuby (so I just learned from
irc's #jruby), you have to do this:

query.add_facet_field(['cat'].to_java :string)

anyway, for our solr-jruby purposes, i think we can stick to using the
ModifiableSolrParams API instead of SolrQuery, but we still get
varargs issues.

thankfully Ruby solves this relatively nicely...

solr = EmbeddedSolrServer.new(container, "core1")
query = ModifiableSolrParams.new
def query.abcd(key, values)
add(key,(values.is_a?(Array) ? values : [values]).to_java(:string))
end
query.abcd('q','*:*')
query.abcd('facet.field',['cat'])
response = solr.query(query)

We'll just need to sprinkle a little Ruby fairy dust on some of this
clunky stuff. It's not all that bad. But the varargs one is strange
to me, but I'm sure there is some deep technical reason why that
support isn't intuitive.

Erik


On Oct 6, 2008, at 1:36 AM, Ryan McKinley wrote:

> just guessing, but try passing that as a string[] rather then just a
> string
>
> The java function takes ( string ... v ) -- in java that means you
> can pass either a string or an array, or a variable length list of
> strings. I'm guessing that does something funny with jruby
>
> ryan
>
>
> On Oct 5, 2008, at 10:54 PM, Matt Mitchell wrote:
>
>> I've been messing around with jRuby and SolrJ with nice results.
>> But can't
>> seem to get the SolrQuery.addFacetField method to work. I get this
>> error:
>>
>> "for method addFacetField expected [[Ljava.lang.String;]; got:
>> [java.lang.String]; error: argument type mismatch (TypeError)"
>>
>> I'm using it like:
>>
>> query.add_facet_field 'cat'
>>
>> and also tried:
>>
>> query.addFacetField 'cat'
>>
>> Any ideas as to what I'm doing wrong?
>>
>> Matt
>>
>> p.s. The other methods I've tried work great: set_query,
>> set_query_type,
>> set_facet, set_facet_limit, set_facet_min_count, set_include_score,
>> add_sort_field.


goodieboy at gmail

Oct 6, 2008, 1:19 PM

Post #4 of 6 (5470 views)
Permalink
Re: jruby and solrj [In reply to]

Awesome, thanks Erik! I really like the idea of bypassing SolrQuery, and
just using a straight up Hash. It'll be even easier to keep the API
consistent between jruby and standard ruby now.


On Mon, Oct 6, 2008 at 3:59 PM, Erik Hatcher <erik [at] ehatchersolutions>wrote:

> Unfortunately, to call varargs from JRuby (so I just learned from irc's
> #jruby), you have to do this:
>
> query.add_facet_field(['cat'].to_java :string)
>
> anyway, for our solr-jruby purposes, i think we can stick to using the
> ModifiableSolrParams API instead of SolrQuery, but we still get varargs
> issues.
>
> thankfully Ruby solves this relatively nicely...
>
> solr = EmbeddedSolrServer.new(container, "core1")
> query = ModifiableSolrParams.new
> def query.abcd(key, values)
> add(key,(values.is_a?(Array) ? values : [values]).to_java(:string))
> end
> query.abcd('q','*:*')
> query.abcd('facet.field',['cat'])
> response = solr.query(query)
>
> We'll just need to sprinkle a little Ruby fairy dust on some of this clunky
> stuff. It's not all that bad. But the varargs one is strange to me, but
> I'm sure there is some deep technical reason why that support isn't
> intuitive.
>
> Erik
>
>
>
> On Oct 6, 2008, at 1:36 AM, Ryan McKinley wrote:
>
> just guessing, but try passing that as a string[] rather then just a
>> string
>>
>> The java function takes ( string ... v ) -- in java that means you can
>> pass either a string or an array, or a variable length list of strings. I'm
>> guessing that does something funny with jruby
>>
>> ryan
>>
>>
>> On Oct 5, 2008, at 10:54 PM, Matt Mitchell wrote:
>>
>> I've been messing around with jRuby and SolrJ with nice results. But
>>> can't
>>> seem to get the SolrQuery.addFacetField method to work. I get this error:
>>>
>>> "for method addFacetField expected [[Ljava.lang.String;]; got:
>>> [java.lang.String]; error: argument type mismatch (TypeError)"
>>>
>>> I'm using it like:
>>>
>>> query.add_facet_field 'cat'
>>>
>>> and also tried:
>>>
>>> query.addFacetField 'cat'
>>>
>>> Any ideas as to what I'm doing wrong?
>>>
>>> Matt
>>>
>>> p.s. The other methods I've tried work great: set_query, set_query_type,
>>> set_facet, set_facet_limit, set_facet_min_count, set_include_score,
>>> add_sort_field.
>>>
>>
>


erik at ehatchersolutions

Oct 6, 2008, 1:30 PM

Post #5 of 6 (5458 views)
Permalink
Re: jruby and solrj [In reply to]

On Oct 6, 2008, at 4:19 PM, Matt Mitchell wrote:
> Awesome, thanks Erik! I really like the idea of bypassing SolrQuery,
> and
> just using a straight up Hash. It'll be even easier to keep the API
> consistent between jruby and standard ruby now.

Here's a cute trick:

query = {'qt' => 'standard', 'q'=>'*:*', 'facet.field' => 'cat'}
response = solr.query(MapSolrParams.new(query))

But that doesn't work, as-is, with an array for the facet.field
parameter, nor does it work for symbols, so this doesn't work for two
reasons:

solr.query(MapSolrParams.new(
:qt => 'standard', :q=>'*:*', 'facet.field' => ['cat']
)

Getting warmer! :)

Erik


erik at ehatchersolutions

Oct 6, 2008, 8:40 PM

Post #6 of 6 (5478 views)
Permalink
Re: jruby and solrj [In reply to]

I've created a simple bare minimum server.rb that - similar to SolrJ's
SolrServer abstraction in (currently mostly empty) methods.

And in test/ I've checked in a JRuby example showing the difference
between going through a pure Ruby API and the SolrJ API. You can run
it this way from the root of the solr-ruby-refactoring branch:

jruby -Ilib test/temp.rb

I think the goal is to achieve something like this being equivalent
for both MRI and SolrJ-Ruby, regardless of the solr object type:

response = eval(solr.request(:qt => 'standard', :q => '*:*',
'facet.field' => ['cat'], :wt=>'ruby'))
puts response['response']['numFound']

Not quite sure where the eval belongs, so I left it out of
Solr::Server for now. We want to be able to support raw responses
through solr-ruby also, for use cases like letting Solr's JSON
response pass through a Ruby application server (or perhaps even to
use JSON within solr-ruby, if it parses faster).

Shouldn't be too hard to get there from here, eh Matt?

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.