On 1/22/07, Erik Hatcher <[EMAIL PROTECTED]> wrote:
But isn't this considered a bug in the data structure used to write
out the facets?
Not for JSON I think... that's a wire format, and the order is what
you see on the wire.
It can be a problem preserving order, depending on the client.
The problem is, for a large number of cases, the order doesn't matter,
even where we use a named list. If you translate all named lists into
arrays of arrays or arrays of maps, it unnecessarily bloats the XML,
and makes the JSON much harder to read.
For example, the top level NamedList is ordered (responseHeader comes
first), but in Ruby/Python we normally don't care since we can access
by element name.
> Options:
> - Resort yourself (for this specific case), it's probably going to
> be faster than having eval() create a new hash object for each anyway.
For sure it'd be no problem to re-sort on the client. I was more
concerned about the purity of the response and it losing its
semantics as an ordered list.
> - Is there any place to hook into ruby's parser and create a map
> that preserves it's order? I would assume not.
Oh, I'm sure there is a way to accomplish that sort of trickery.
Ruby is hyper dynamic, so I'm quite confident that with a little
voodoo this could be done. But its the wrong way to approach this
> - Does ruby have a JSON parser that preserves the order?
Sure, even in one line of code :)
<http://rubyforge.org/snippet/detail.php?type=snippet&id=29>
But even more robustly this looks like the one to use: http://
json.rubyforge.org/
> - A way to specify a different structure for only certain elements...
Again, shouldn't an array be used in this context anyway, rather than
a hash, regardless of which response writer is being used?
A NamedList is used... that is ordered for XML.
It seems like what would be ideal from a user perspective would be to
have an ordered map so you get random access lookup.
An efficient representation using arrays would be two separate arrays:
one for terms, one for counts.
terms=["foo","bar","baz"]
counts=[30,20,10]
But you loose easy random access lookup, and for a sufficiently large
list, you loose the ability of a human to look at the raw response and
correlate a count with the term.
So what about something that could output something like
omap("term1",100,"term2", 45)
The other alternative (besides changing *every* named list), is to
have a facet.format and override the default structure.
-Yonik
> If that's your *only* sorting problem, find a ruby implementation of a
> hash or a map that preserves order, then re-sort the hash, and replace
> it with the order-preserving map, and then worry about a more general
> solution later?
Maybe what we need is a YAML response writer, and used an ordered
map: http://yaml.org/type/omap.html
Erik