You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Nigel McNie <ni...@catalyst.net.nz> on 2007/05/15 10:19:45 UTC

Ruby writer - arrays for facet data?

Hi,

I'm using solr to implement a faceted search interface. I found that I
needed the ability to search for *:* so I could get the entire facet
counts, so I upgraded solr from the latest stable to the latest nightly
release.

However, it seems that the ruby writer has changed, or something else
inside solr has changed, because now for the facet data I am getting an
array instead of a hash. Example:

nigel@sounz:~/sounz/solr_server$ curl -s
'http://localhost:8983/solr/select?indent=1&rows=0&q=thea*&facet=true&facet.field=year_group_facet&wt=ruby';
echo
{
 'responseHeader'=>{
  'status'=>0,
  'QTime'=>0,
  'params'=>{
        'wt'=>'ruby',
        'rows'=>'0',
        'facet'=>'true',
        'facet.field'=>'year_group_facet',
        'indent'=>'1',
        'q'=>'thea*'}},
 'response'=>{'numFound'=>5,'start'=>0,'docs'=>[]
 },
 'facet_counts'=>{
  'facet_queries'=>{},
  'facet_fields'=>{
        'year_group_facet'=>[
         '1970-1979',2,
         '1990-1999',2,
         '1980-1989',1,
         '',0,
         '1950-1954',0,
         '1955-1959',0,
         '1960-1964',0,
         '1965-1969',0,
         '2000-2004',0,
         '2005-',0,
         'before-1950',0]}}}

See how the 'year_group_facet' data is in an array instead of a hash, as
it used to be in the stable version.

Is there a reason for this change? From my "hasn't used solr too much
before" perspective, the change does not seem to make much sense.
Perhaps it's a bug?

Thanks in advance anyone who can help :)

-- 
Regards,
Nigel McNie
Catalyst IT Ltd.
DDI: +64 4 803 2203


Re: Ruby writer - arrays for facet data?

Posted by Yonik Seeley <yo...@apache.org>.
On 5/15/07, Nigel McNie <ni...@catalyst.net.nz> wrote:
> Yonik Seeley wrote:
> >
> > '''
> > The JSON response format for facets has changed to make it easier for
> > clients to retain sorted order.  Use json.nl=map explicitly in clients
> > to get the old behavior, or add it as a default to the request handler
> > in solrconfig.xml
> > '''
>
> Thanks for pointing that out, it has fixed my issue. Though I wonder:
> why was it decided to do [key, value, key, value] instead of [{key =>
> value}, {key => value}] when it was found that you needed sorting? IMHO,
> a little easier to work with. (I presume there's a good reason for it
> though...)

Memory is one reason... a map or hash per count isn't ideal.

Another is the API for accessing such a data structure.  While it
looks fine on paper, getting a single key/value easily and efficiently
is not what a map/hash is good for.  What's a map doing in the
equation if there is only ever going to be a single key?

-Yonik

Re: Ruby writer - arrays for facet data?

Posted by Nigel McNie <ni...@catalyst.net.nz>.
Yonik Seeley wrote:
> 
> '''
> The JSON response format for facets has changed to make it easier for
> clients to retain sorted order.  Use json.nl=map explicitly in clients
> to get the old behavior, or add it as a default to the request handler
> in solrconfig.xml
> '''

Thanks for pointing that out, it has fixed my issue. Though I wonder:
why was it decided to do [key, value, key, value] instead of [{key =>
value}, {key => value}] when it was found that you needed sorting? IMHO,
a little easier to work with. (I presume there's a good reason for it
though...)

-- 
Regards,
Nigel McNie
Catalyst IT Ltd.
DDI: +64 4 803 2203


Re: Ruby writer - arrays for facet data?

Posted by Yonik Seeley <yo...@apache.org>.
On 5/15/07, Nigel McNie <ni...@catalyst.net.nz> wrote:
> I'm using solr to implement a faceted search interface. I found that I
> needed the ability to search for *:* so I could get the entire facet
> counts, so I upgraded solr from the latest stable to the latest nightly
> release.
>
> However, it seems that the ruby writer has changed, or something else
> inside solr has changed, because now for the facet data I am getting an
> array instead of a hash.

It's documented for JSON (which Python and Ruby formats inherit from)
in both CHANGES.txt and on the Wiki:

http://wiki.apache.org/solr/SolJSON
http://svn.apache.org/repos/asf/lucene/solr/trunk/CHANGES.txt

'''
The JSON response format for facets has changed to make it easier for
clients to retain sorted order.  Use json.nl=map explicitly in clients
to get the old behavior, or add it as a default to the request handler
in solrconfig.xml
'''

-Yonik