README.md in ruby_simple_search-0.0.1 vs README.md in ruby_simple_search-0.0.2

- old
+ new

@@ -1,18 +1,47 @@ # RubySimpleSearch -RubySimpleSearch allows to search on the table fields. -e.g. string and text fields. +RubySimpleSearch allows you to search on the table fields (string and text fields) +very easily. -Sometimes we want to do search on the post's title and content -or user's email, username and description or on other models but in same way. -For those searches we use MySql's or Postgresql's LIKE operator to get the -results. While doing same thing on the differet models you actually add lots of -duplications in your code. +Mostly on the admin side, we do have a common text field to search the table +column's data. +Sometimes we want to do a search on the title, content and ratings on the post model or +email, username and description on the user model. For those searches we use MySQL's +or PostgreSQL's LIKE operator to get the results. While doing the same thing again and again +on the different models you actually add lots of duplication in your code. + To avoid duplicating the same code, use RubySimpleSearch :) +#### RubySimpleSearch Features: +- Added like pattern support ('beginning', 'ending', 'containing', 'underscore', 'plain'). + By default pattern is 'containing' + +```Ruby + simple_search_attributes :name, :address, :pattern => :ending + # It will search like '%york' + + simple_search_attributes :name, :address, :pattern => :begining + # It will search like 'york%' + + simple_search_attributes :name, :address, :pattern => :containing + # It will search like '%york%' + + simple_search_attributes :name, :address, :pattern => :underscore + # It will search like '_o_' + + simple_search_attributes :name, :address, :pattern => :plain + # It will search like 'york' +``` +- Added **block** support to simple_search method, so user can extend the query as per + his/her requirements (Now you can operate on the integer/decimal values also) + +- Added specs + +- Added exception handler + ## Installation Add this line to your application's Gemfile: gem 'ruby_simple_search' @@ -31,26 +60,49 @@ ```Ruby class Post < ActiveActiveRecord::Base include RubySimpleSearch - simple_search_attributes :title, :description + simple_search_attributes :title, :description, :pattern => :begining end - -class User < < ActiveActiveRecord::Base +``` +```Ruby +class User < ActiveActiveRecord::Base include RubySimpleSearch simple_search_attributes :email, :username, :address end - -Post.simple_serach('tutorial') -# => posts which have 'tutorial' text in title or in description fields - -User.simple_search('Mechanciles') -# => users which have 'Mechanicles' text in the email, username and in address - +``` +While defining simple_search_attributes, don't add integer/decimal data +attributes to it, instead of this you can do integer/decimal operation +by passing block to simple search method +```Ruby +Post.simple_search('tuto') +# => posts which have 'tuto%' text in the title or in the description fields +``` +```Ruby +User.simple_search('mechanicles') +# => users which have 'mechanicles' text in the email, username and in address +``` +```Ruby +User.simple_search('mechanicles') do |search_term| + ["and address != ?", search_term] +end +# => You can pass block to simple_search method so you can extend it as your +# wish but you need to return an array of valid parameters like you do in #where +# method +``` +```Ruby Model.simple_search('string') -# => will return ActiveRecord::Relation object +# => with and without block will return ActiveRecord::Relation object +``` +```Ruby +Model.simple_search('string').to_sql +#OR +User.simple_search('mechanicles') do |search_term| + ["and address != ?", search_term] +end.to_sql +# => will return sql query in string format ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`)