Max Williams
2008-Dec-04 12:21 UTC
[Ferret-talk] order by scoring, pagination and AR conditions don''t work together
Hi all I''m having a problem with aaf - i want to do a search and order the results by the ferret score. I also want to paginate the results (20 per page), and to complicate matters further i have an array of ''allowed_ids'' - this is effectively the pool of resources which the search results are limited to. So, i want to order by score, pass in some AR conditions, and paginate the results. Currently the pagination seems to be breaking. Here''s an example search, paginated with 1000 per page so it effectively gets all the results (there are only 67 for this particular search). I''ve collected the ids of the results just for illustration purposes: ferret_results = ActsAsFerret::find("viola", [TeachingObject,LearningObject], #(ferret) options { :page => 1, :per_page => 1000 }, #find options - need to specify conditions for each searched class individually {:conditions => { :teaching_object=>["resources.id in (?)",allowed_ids], :learning_object=>["resources.id in (?)",allowed_ids] } } ).collect(&:id) => [5407, 5427, 5416, 5401, 5411, 5415, 5420, 5421, 5426, 5431, 5435, 5436, 5397, 5403, 5412, 5418, 5419, 5423, 5424, 5429, 5437, 5439, 533, 534, 5405, 5425, 5440, 5402, 5413, 5414, 5417, 5432, 5433, 5438, 5410, 5404, 532, 5399, 5409, 531, 5398, 5400, 5408, 5422, 5428, 5430, 5434, 5406, 5441, 518, 524, 535, 529, 525, 526, 536, 537, 538, 530, 528, 527, 4452, 1709, 5790] So - if i was to bring the per_page parameter down to 10 then i''d expect to get the first 10 ids from the list above, right? But, that''s not what happens: ferret_results = ActsAsFerret::find("viola", [TeachingObject,LearningObject], #(ferret) options { :page => 1, :per_page => 10 }, #find options - need to specify conditions for each searched class individually {:conditions => { :teaching_object=>["resources.id in (?)",allowed_ids], :learning_object=>["resources.id in (?)",allowed_ids] } } ).collect(&:id) => [532, 531, 518, 524, 529, 525, 526, 530, 528, 527] Can anyone tell me if i''m doing something wrong, or a way i can work around this? thanks max -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ferret-talk/attachments/20081204/747220b9/attachment-0001.html>