Sorting results by column

I have the acts_as_ferret plugin installed. Everything searches great,
but I would like to limit the results (i.e. by ‘end_date’) and sort them
(by ‘end_date’). ‘end_date’ is a valid column in my “posts” table.
Here’s the code I have already:

@posts = Post.find_by_contents(params[:query])

params[:query] comes from a form. I am replacing less efficent code that
has the restrictions working :

@posts = Post.find(:all,
:conditions => [ ‘(title LIKE :search_query OR body
LIKE :search_query) AND end_date >= :enddate’,
{:search_query => ‘%’ + params[:query] + ‘%’,
:enddate => Time.now}],
:order => ‘end_date’)

I realize i have to pass something similar to :conditions and :order,
but I can’t seem to get ferret to bey the options.

I’ve installed acts_as_ferret just 2 seconds ago and I must say: It
works splendit!!

The following query works (might help you towards a solution):

YourModel.find_by_contents(‘id:“2”’) # Returns entries from yourmodels
table with id=2.

YourModel.find_by_contents(‘name:“somename”’) # Only searches somename
field…

etc…etc…

This does also work:
ModelName.find_by_contents(‘id:( > 2) id:( < 5)’)

Also see the Ferret RDOC:
http://gemjack.com/gems/ferret-0.9.3/index.html

You should be able to sort the ferret results like this:

@posts = Post.find_by_contents(params[:query], :sort => [“end_date”])

This post talked a little bit more about using ferret to sort results:
http://lists.rubyonrails.org/pipermail/rails/2006-June/044513.html

*Note: Whenever I tried to do this ferret would only sort the first page
of results. So if ferret returned 100 results and each page had 10 items
only the first 10 items would be sorted by the desired field. Of course
I was probably doing something wrong. Let me know how this works out for
you.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs