Hi<br><br>I have a problem with a search where i want to get some results according to some conditions, sort the results, and then paginate over the sorted collection.<br><br>My search looks like this: <br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @results&nbsp; = TeachingObject.find_with_ferret(search_term, <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #(ferret) options<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {:page =&gt; options[:page],<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :per_page =&gt; options[:per_page], <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :sort =&gt; Ferret::Search::SortField.new(:asset_count, :type =&gt; :integer, :reverse =&gt; true )},<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #find options<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { :conditions =&gt; [&quot;id in (?)&quot;, @ids] } )<br><br>where @ids is an array of ids from which the results must come (ie a collection of &#39;allowed&#39; results of which @results will be a subset): often the search term is set to * to get all of this collection in @results.&nbsp; &#39;:asset_count&#39; is an untokenized ferret field that stores integers.<br>
<br>Through debugging and experimenting, i&#39;ve observed the following:<br><ul><li>The overall results set, without sorting/pagination, is correct (therefore :conditions is being taken into account).<br></li><li>If :per_page is set to be so large that no pagination is required, then the sorting occurs properly (therefore sorting is being taken into account)<br>
</li><li>If :per_page is reduced so that pagination is required, then the sorting of the overall set breaks: it seems as if the results are ordered by id, then paginated.<br></li><li>However, on every individual page, the results are sorted properly for that page, ie each page-size subset is internally sorted.</li>
<li>If i sort on a different untokenized field,&nbsp; the problem persists.<br></li></ul>It seems as if the pagination is happening and THEN the sorting is happening, which obviously doesn&#39;t give the expected results.&nbsp; This is just a theory on my part though. <br>
<br>Can anyone tell me how to fix this problem?&nbsp; I&#39;ve been gnashing my teeth over it for over a day now and can&#39;t find any solutions...<br><br>thanks<br>max<br>