On Sat, Sep 10, 2011 at 4:25 AM, Marvin Humphrey <[email protected]> wrote:
> You must stringify during indexing.
>
> Here's example indexing code where both the "date" and "rainfall" fields are
> prepared using sprintf() so that they will sort in the desired order:
>
> my %doc = (
> location => $location,
> date => sprintf("%0.4d-%0.2d-%0.2d", $year, $month, $day),
> rainfall => sprintf("%07.4f", $cm_rainfall), # e.g. 01.1482
> );
> $indexer->add_doc(\%doc);
>
> Of course you have to choose an adequate precision so you don't overflow and
> screw up the sort order. :)
Hmm, my sort floats are typically like this:
min: 0.1254619125
max: 3117.88289166118
typical: 0.231372871201865 (15 dec places max)
sprintf("%0.15f") in Perl produces:
0.125461912500000 ok
3117.882891661180111 screw up (should be 3117.882891661180000)
0.231372871201865 ok
I imagine the large value 3117 with the added "0111" won't present a
problem when sorting -- but I have a feeling I'm wrong, right?