Plugins - SimplySearchable

StarAdd to favorites

SimplySearchable is a search plugin created by SpinBits - http://spinbits.com.

The main goal of SimplySearchable is to help you create a clean url to search in your controller and model.

This plugin adds a method to the controller named "search" that will find and filter the model data smartly from the search fields defined in its calling line

SimplySearchable recognizes three types of filters:

  1. Exact values: like the title in the example above (acts_as_ferret implementation to come soon)
  2. Belongs to associations: for those fields that ends with _id, like author_id in the example above
  3. Has many association: for those fields that are in plural form, like comments in the example above

Generator:

generators will create a simple search view ‘search.html.erb’ which has a very basic table with your results in the views folder of your simply searchable controller.

Example:

In your controller:

        simply_searchable :fields => ['title', 'author_id', 'comments'], :order  => 'created_at DESC'

This will create a search method that search any text given to be the ‘title’, and search the belongs_to association with ‘authors’ and finally the has_many association with ‘comments’.

i.e. /posts/search?author_id=1&comments[]=1&comments[]=3 This url will search posts from the author with id 1 AND has comments with ids 1 and 3

Quick installation:

Let’s say you have a Post model and PostsController and you want to search by author and comments:

  1. Install the plugin:
                 ./script/plugin install svn://code.spinbits.com/plugins/simply_searchable/trunk
    
  2. In your PostsController add:
                 simply_searchable :fields => ['title', 'author_id', 'comments']
    
  3. In your routes.rb add search method to your desired resource:
                 map.resources :posts, :collection => {:search => :get}
    
  4. Generate the search results page that shows the post’s title and body:
                 ./script/generate simply_searchable Post title body
    
  5. visit /posts/search and start passing your filters:
                 /posts/search?author_id=1                                                                     # View posts from author 1
                 /posts/search?title="test"                                                            # View posts with the title 'test'
                 /posts/search?comments=1&author_id=3                  # View posts that has comment 1 and written by author 3
                 /posts/search?author_id[]=1&author_id[]=2 # View posts from both authors 1 and 2
    

Integrations:

This plugin has integrations with will_paginate:

         ./script/plugin install svn://errtheblog.com/svn/plugins/will_paginate

To integrate will_paginate just pass :with_pagination => {:per_page => X} (X is your preferred number of results per page) to simply_searchable calling line and you’re all set.

Rida Al Barazi

http://code.spinbits.com/simply_searchable.html

svn://code.spinbits.com/plugins/simply_searchable/trunk

Rails' (MIT)

  • Currently 4.7/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Searching and Queries

Tags

Comments

Add a comment
Bryan Larsen 1 May 2008

Great plugin. Note that it supports more options than documented. For example, fields that end in "from" are interpreted as greater-than-or-equals filters. Other special endings are "to" and "_id_tree".

Henrique 19 Nov 2007

Hi, Does this plugin support LIKE conditions?

Rida Al Barazi 31 Jul 2007

Hey Joerg,

Regarding the format.rss it is still not supported in this release, if you need it you will have to do that manually by modifying simply_searchable.rb.

I'm writing a small tutorial on simplysearchable on the new release that will have some new features, including RSS support and actsas_ferret too, so stay tuned :)

Cheers

Joerg Battermann 29 Jul 2007

Hey there :)

Thanks for the plugin. However, does the format.rss part work just like that or do you need that view specified in simply_searchable.rb?

Oh and... how far is acts_as_ferret integration away? ;)

Thanks! -J

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?