On 4/5/07, Ryan K. [email protected] wrote:
On 4/4/07, John B. [email protected] wrote:
(shamelessly bumping this thread up…)
Shame on you.
Bumping this up won’t help anything, because they’re probably only one
person, David, who can answer you question, and he seems to be in and
out, with large periods of time with no net connectivity. It’s not
that people aren’t willing to help, it’s just that most of us can’t.
And I’m back again.
You can actually specify how you want fields to be sorted, ie whether
you want to sort by string, bytes, integer or float;
sort_field = SortField.new(:field_name, {:type => :float, :reverse
=> true})
hits = index.search(query, :sort => Sort.new([sort_field,
SortField::SCORE]))
So, John, in your case you will want to set the type to :string or
even better :byte. Sorting by :byte basically does a strcmp, ignoring
locale and encoding, making it faster than sorting by :string.
Actually, sorting by integer would be even better and can be done if
you store the dates with day precision (eg 19770905). Unfortunately
19991018000000 won’t fit into a single integer so it won’t work for
this precision.
Now, if you don’t specify the sort type, Ferret will try and determine
the sort type for you. It will first try to parse the field as an
integer and then as a float before defaulting the a string type. My
guess is that the reason John’s sort isn’t working is that Ferret is
detecting an integer field so it is trying to sort by integer but the
integers don’t fit in a 4 byte integer, hence the problem.
Hope that explains it. If not, let me know and I’ll try and make it a
little clearer. I’m in a bit of a rush to get through all the emails
on the list to see if there are any issues I need to deal with before
putting out another release.
Cheers,
Dave