Douglas F Shearer

Acts_as_ferret Returning Only 10 Results?


The acts_as_ferret gem is great! It allows the power of the Ferret (Apache Java Luciene originally) search engine to be leveraged in a Rails application easily.

There is one thing about it that leaves me slightly miffed. Why does any search only return 10 items by default?

The fix is to use your search methods as follows…

If you are wanting model objects returned, then use:

objects = Model.find_by_contents('string search query', :limit=>1000000)

If you just want the IDs returned, use this:

object_ids = Model.find_id_by_contents('string search query', :limit=>1000000)

It would be rather nice if an :all option switch was available, but instead we make do with the :limit=>1000000 ‘hack’, which isn’t a problem unless you end up with more than a million results returned by a search. Unless you’re Google, this isn’t going to be an issue.

Hope this helped some folks out who were puzzled by this as I was.

Update

After looking at my logs, I’ve realised that :num_docs has been deprecated in favour of :limit. I’ve update this post to reflect that.

Did you like my Ruby on Rails related article? Then why not recommend me on Working with Rails?

Tags

, , .

Related Posts

November 7th 2006 18:24 | comments (0)
 

Comments


There are no comments. Be the first.

Add Your Comments


(Required)

Your email address to get your Gravatar. Address itself is not shown.

(Include the http://)

(Required)

 

You Are Here


Douglas F Shearer

This is the homepage of Douglas F Shearer, a software developer and mountainbike racer. Find out more at the About page.

Gallery Latest


Side on Chips on crown Front on chip2 chip1 img67

Stay Informed


What is RSS?

Top Tags