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> @results = TeachingObject.find_with_ferret(search_term, <br>
#(ferret) options<br> {:page => options[:page],<br> :per_page => options[:per_page], <br> :sort => Ferret::Search::SortField.new(:asset_count, :type => :integer, :reverse => true )},<br>
#find options<br> { :conditions => ["id in (?)", @ids] } )<br><br>where @ids is an array of ids from which the results must come (ie a collection of 'allowed' results of which @results will be a subset): often the search term is set to * to get all of this collection in @results. ':asset_count' is an untokenized ferret field that stores integers.<br>
<br>Through debugging and experimenting, i'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, the problem persists.<br></li></ul>It seems as if the pagination is happening and THEN the sorting is happening, which obviously doesn't give the expected results. This is just a theory on my part though. <br>
<br>Can anyone tell me how to fix this problem? I've been gnashing my teeth over it for over a day now and can't find any solutions...<br><br>thanks<br>max<br>