Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Quick and dirty multi column LIKE searches.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 CHANGELOG
Octocat-spinner-32 Manifest
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 init.rb
Octocat-spinner-32 simple_column_search.gemspec
README.rdoc

Simple Column Search

Quick and dirty multi column LIKE searches. Great for prototyping auto-completers as it handles partial matches and adding search terms refines the results.

Running lots of queries or have a large data set? You should probably upgrade to a real search back-end already!

Examples

Add a search method to your model by calling simple_column_search with the fields you want to search.

class User
  simple_column_search :first_name, :last_name
end

Search for a single value across all searched columns.

User.search('eli')             # => anyone with first or last name starting with eli
User.search('miller')          # => anyone with first or last name starting with miller

Refine the search by adding another search term.

User.search('eli miller')
  # => anyone with first or last name starting with eli AND
  #    anyone with first or last name starting with miller

Specify query match mode. Use :exact, :start, :middle, or :end (default is :start).

class User
  simple_column_search :name, :match => :exact
end

Specify query match based on column name.

class User
  simple_column_search :name, :email, :match => lambda { |column| column == :email ? :middle : :start },
end

Escape query string before issuing the search request.

class User
  simple_column_search :name, :escape => lambda { |query| query.gsub(/[^\w\s\-\.']/, '').strip }
end

Install

As a Rails plugin.

./script/plugin install git://github.com/jqr/simple_column_search.git

Prefer gems? Add this to your environment.rb and run the following command.

config.gem 'simple_column_search'

$ rake gems:install

Docs

rdoc.info/projects/jqr/simple_column_search

Homepage

github.com/jqr/simple_column_search

License

Copyright © 2008 Elijah Miller <elijah.miller@gmail.com>, released under the MIT license.

Something went wrong with that request. Please try again.