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?