Skip to content

canimus/acts_as_wild_searchable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ActsAsWildSearchable


This plugin allows you to search in your models on each of its attributes using wild cards. The default behavior is to chain the search parameters using “or” and wild cards in both sides. This behavior can be changed by adding the :clause=>“and” and the :left=>true or :right=>true parameters

GEM Location

gem 'act_as_wild_searchable', :git => 'http://github.com/canimus/acts_as_wild_searchable-0.0.1.gem'

Installation

bundle install

Tested Versions

  • Rails 3.2.3

Usage

Query Basics

  • the _like? method

    Consider that you model has the name attribute

    User.name_like? "John"
    
  • the chain capabilities

    To chain various queries just add another query after the usage of the like? method

    User.name_like?("John").where(:id => 1)
    
  • the multiple_search

    You can add as many clauses and by default will be added using an “or” clause

    User.name_like? "John","David", "Peter" # Produces where (name like ? or name like ? or name like ?, "%John%", "%David%", "%Peter%")
    
  • the left

    You can position the wild card with a hash addition to the call

    User.name_like? "John","David", :left => true # Produces where (name like ? or name like ?,  "%John", "%David")
    
  • the right

    You can position the wild card with a hash addition to the call

    User.name_like? "John","David", :right => true # Produces where (name like ? or name like ?,  "John%", "David%")
    
  • the clause

    You can change the default behavior for the wild card search by addint the clause hash

    User.name_like? "John","David", :clause => "and" # Produces where (name like ? and name like ?,  "%John%", "%David%")
    

General configuration options

You can configure the following attributes that will locate the wild card for your search

left              # false by default
right             # false by default
clause            # "or" by default

About

Rails plugin to search using like and wild cards over your models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published