RailsConf Europe 2006: Search with Rails
(slides)
Now at the shopping.nouvelobs.com ecommerce talk which is a large news site in France. Speaker is Gwendal Rou, very French.
ModelSearch is an extension of find that allows something like this:
search = ProductSearch.new() search.buyable = true search.Find(:all)
The idea is that searching with multiple columns is not at the usual high-level in Rails. You have to use SQL.
ModelSearch is capable of; Televisions costing less than 300, sorted by price.
search = ProductSearch.new search.keyword - 'television' search.max_price = 300 search.sort = :price search.find(:all)
That is quite handy. I assume ‘max_’ is dynamically added onto model members. i.e. I assume you could have min_price too. My assumption is nearly correct, you just need to set it up in the model a bit.
A further extension lets you pass the search object into the normal model find e.g. Product.find(:all, search.find_options)
ProductSearch is a class you subclass from ModelSearch and setup with various params. e.g. search_key :keyword, :search => :keyword, in => [:name, :description]
All nicely model based this. Buyable, from the first code, is a custom method in the ProductSearch model. It works well with a form, letting you just pass in properly named input fields.
ModelSearch is planned for release soon.
All in all a nice bit of code for real world problems.
September 16th, 2006 at 1:27 am
[…] nouvelobs.com ecommerce and search with Rails by Gwendal Rou […]
September 18th, 2006 at 4:29 pm
Thanks for your kind article !
We’ve just put online our slides : http://pierlis.com/Pierlis_RailsConf2006.pdf
The plugin will come soon.
May 15th, 2007 at 9:33 am
Hi,
Your plugin looks really good, did you publish it somewhere finally ?
thanks
-sebastien CANTE
May 15th, 2007 at 10:09 am
It isn’t my plugin, sebastien, but rather from the commentor before you.
December 12th, 2007 at 10:01 am
Phew ! We eventually managed to release it : http://www.pierlis.com/blog/2007/12/10/release-of-the-searchapi-plugin