# Order by scoring, pagination and AR conditions don't work together

**URL:** <https://www.ruby-forum.com/t/order-by-scoring-pagination-and-ar-conditions-dont-work-together/154846>\
**Category:** Ferret\
**Created:** [December 4, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/order-by-scoring-pagination-and-ar-conditions-dont-work-together/154846 "2008-12-04T13:22:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [December 4, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/order-by-scoring-pagination-and-ar-conditions-dont-work-together/154846/1 "2008-12-04T13:22:16Z")

</div>

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
