Hi Jens/all
I've been playing with latest version, and it seems that the combination of
AR conditions, paginating and AR order (eg ":order => "name") seems to be
fine now, even on our server, which was were it was broken before (it always
worked locally, weirdly).
However, i've just tried it with results that are sorted by ferret on the
basis of their boost score, and it seems broken.
I'm sorry i don't have any tests set up but if i walk through an example can
anyone see something that maybe i'm doing wrong? Or shed any light?
I use AR conditions to filter the results through a set of ids that an
individual user is allowed to view. I just have a method User#allowed_ids
for this that returns an array of integers. For the purpose of
illustration, though, let's say that the allowed ids are everything between
1000 & 2000.
allowed_ids = (1000..2000).to_a
=> [1000, 1001, 1002, etc, 2000]
For a particular search (on 'rhythm') i get these results back - the order
is the order calculated by ferret/aaf on the basis of boost values: i've
collected them by id for clarity. In this example i've set a big per_page
to get all the results.
>> ActsAsFerret::find("rhythm", [TeachingObject],{ :page => 1, :per_page =>
1000 }, {} ).collect(&:id)
=> [4038, 698, 4039, 1830, 1831, 1826, 1832, 1825, 1833, 411, 1834, 702,
1827, 1689, 1680, 1688, 1679, 1686, 1684, 1676, 2129, 2130, 2131, 1858,
1859, 1860, 1861, 1865, 2132, 2141, 2345, 2350, 2352, 2353, 2356, 2360,
2362, 2366, 2368, 2371, 2372, 2373, 2376, 2377, 2378, 2384, 2385, 2389,
2407, 2414, 2417, 2419, 2427, 2428, 2438, 2439, 2458, 2459, 2473, 2474,
2475, 2477, 2478, 2133, 2349, 2361, 2363, 2365, 2370, 2375, 2383, 2386,
2392, 2415, 2430, 2431, 2440, 2441, 2442, 2472, 2142, 3751, 2161, 1236]
Now, when i apply the condition of only being in the allowed ids, i'd expect
the remaining ids to be in the same order as above, and that is in fact the
case:
>> ActsAsFerret::find("rhythm", [TeachingObject],{ :page => 1, :per_page =>
1000 }, {:conditions => ["id in (?)", allowed_ids] } ).collect(&:id)
=> [1830, 1831, 1826, 1832, 1825, 1833, 1834, 1827, 1689, 1680, 1688, 1679,
1686, 1684, 1676, 1858, 1859, 1860, 1861, 1865, 1236]
Just to check, let's do the original again (with no AR conditions) and just
do set intersection with the allowed_ids
>> ActsAsFerret::find("rhythm", [TeachingObject],{ :page => 1, :per_page =>
1000 }, {} ).collect(&:id) & allowed_ids
=> [1830, 1831, 1826, 1832, 1825, 1833, 1834, 1827, 1689, 1680, 1688, 1679,
1686, 1684, 1676, 1858, 1859, 1860, 1861, 1865, 1236]
OK - looks good. But, when i try to paginate into some actual pages, the
order breaks: first, without AR conditions:
>> ActsAsFerret::find("rhythm", [TeachingObject],{ :page => 1, :per_page =>
10 }, {} ).collect(&:id)
=> [4038, 698, 4039, 1830, 1831, 1826, 1832, 1825, 1833, 411]
That all seems to be in order - i get the first ten results from the big
list, above.
Now, if we were to apply the allowed_ids condition here, we'd expect the
results to start
[1830, 1831, 1826, 1832, 1825, 1833, ...] - right? Because we should have
the same ordering applied to the remaining resources, and then we get the
first ten for page 1. But, the ordering is different -
>> ActsAsFerret::find("rhythm", [TeachingObject],{ :page => 1, :per_page =>
10 }, {:conditions => ["id in (?)", allowed_ids] } ).collect(&:id)
=> [1826, 1825, 1689, 1680, 1688, 1679, 1686, 1684, 1676, 1236]
So, it seems that pagination + ferret score ordering + AR conditions is a
bad combination
Again, sorry to not supply test cases but we don't use them (i know, i
know!!!). Can anyone shed any light?
thanks - max
2008/7/9 Jens Kraemer <[EMAIL PROTECTED]>:
> Hi folks,
>
> On 09.07.2008, at 06:01, Jeff Webb wrote:
>
>> Sheldon/Jens,
>>
>> Any chance that this has been figured out and patched?
>>
>
> I just committed a fix to this problem to trunk, so pagination with sorting
> and AR conditions should work now.
>
>
> cheers,
> Jens
>
> --
> Jens Krämer
> http://www.jkraemer.net/ - Blog
> http://www.omdb.org/ - The new free film database
>
>
>
>
>
>
>
>
> _______________________________________________
> Ferret-talk mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk