Topic: Search actions and scope bloat

Hi all.

I'm planning the implentation of a search function for my app. I foresee a system in which the user would be able to do a global search across multiple models (much like how Sitepoint.com allows you to search its forums, blogs, books, etc) all in one fell swoop.

This action would definitely cause the controller to handle lots of models at once--not very tidy. Do you think having a controller that juggles multiple models is OK in this case? Or should I try to use, say, a separate search class (ActiveRecord based?) to handle the search actions?

Thanks.

Re: Search actions and scope bloat

It's okay to handle multiple models in something like a SearchController if you're trying to do something like this.  It can become complicated very quickly though.

I'd recommend trying out something like acts_as_ferret or solr.  They are like a search plugin for Rails apps that uses something called Lucene (developed by the Apache group) for helping you to provide search for your site.
http://www.rubyinside.com/acts_as_solr- … s-462.html

There's a great screencast for setting this up:
http://www.rubyinside.com/acts_as_solr- … s-462.html

Re: Search actions and scope bloat

If you do decide to go with just writing the search yourself you should start in the controller and, as things get complicated, start trying to move the code into it's own model.

Get it working first - search can be tricky :-)

Re: Search actions and scope bloat

danger wrote:

If you do decide to go with just writing the search yourself you should start in the controller and, as things get complicated, start trying to move the code into it's own model.

Get it working first - search can be tricky :-)

Will do! ...and thanks!

Re: Search actions and scope bloat

Never used solr but watching that screencast makes it seem more appealing. Might give it a try in the next few days and see what it can (and can't) do.