I use this to sort the facet field values against count in
reverse order in Python:

sorted(facet_field_values.items(), lambda x, y: cmp(x[1], y[1]), reverse = True)

Thursday, May 3, 2007, 6:18:05 PM, you wrote:

> We resort it in solr-ruby:

>    def field_facets(field)
>      facets = []
>      values = @data['facet_counts']['facet_fields'][field]
>      Solr::Util.paired_array_each(values) do |key, value|
>        facets << FacetValue.new(key, value)
>      end

>      facets
>    end



> On May 3, 2007, at 8:10 PM, Mike Klaas wrote:

>> On 5/3/07, Jack L <[EMAIL PROTECTED]> wrote:
>>> The Python output uses nested dictionaries for facet counts.
>>> I read it online that Python dictionaries do not preserve order.
>>> So when a string is eval()'d, the sorted order is lost in the
>>> generated Python object. Is it a good idea to use list to wrap
>>> around the dictionary? This is only needed for the fields, sorted
>>> by counts.
>>
>> This might be fixed in the future, but for now, either resort on the
>> client-side (a one- or zero-liner), or specify json.nl=arrarr (which
>> affects the whole python response structure... probably not
>> recommended).
>>
>> There is some past discussion on the list if you search the archives.
>>
>> -Mike

Reply via email to