Hi

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.

My search looks like this:

      @results  = TeachingObject.find_with_ferret(search_term,
                        #(ferret) options
                        {:page => options[:page],
                        :per_page => options[:per_page],
                        :sort => Ferret::Search::SortField.new(:asset_count,
:type => :integer, :reverse => true )},
                        #find options
                        { :conditions => ["id in (?)", @ids] } )

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.

Through debugging and experimenting, i've observed the following:

   - The overall results set, without sorting/pagination, is correct
   (therefore :conditions is being taken into account).
   - 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)
   - 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.
   - However, on every individual page, the results are sorted properly for
   that page, ie each page-size subset is internally sorted.
   - If i sort on a different untokenized field,  the problem persists.

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.

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...

thanks
max
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to