0.0
Repository is archived
No release in over 3 years
Low commit activity in last 3 years
Adds a search method which allows you to search for multiple words from multiple columns.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

>= 5.2
 Project Readme

DynamicSearch

DynamicSearch provides support for multi term searches to your rails models. At the moment, I would recommend using at least rails 5.2 or higher for security reasons.

At the moment, the sql only supports PostgreSQL!

Installation

Add this line to your application's Gemfile:

gem 'dynamic_search'

And then execute:

bundle

Or install it yourself as:

gem install dynamic_search

Usage

  1. Include the module to any model you want DynamicSearch functionality.
include DynamicSearch
  1. To use the search you can create a search box form in your view.
<%= form_for :model_name, method: 'get' do |f| %>  
  <%= f.text_field :search, placeholder: "search" %>  
<% end %>  

Then in your controller, you can call the search method on your model. You could also specify the columns you want to search on. If you don't specify columns, DynamicSearch will check against all of the columns on your model except foreign keys, id, and timestamps.

columns_array = ["first_name", "last_name", "username", "email"] 
@results = Model.search(params[:search], columns_array) 

From there I normally would paginate the results with Kaminari or WillPaginate.

Optional Customize the search method in your model to specify how your search should work all the time for that model, instead of just one view like above. In this case, you're telling the search method which columns you want included in your search every time for this model.

def search(search)  
  super(search, ["first_name", "last_name", "username", "email"])  
end  

Contributing

If you find a bug, submit an issue or pull request if you've fixed it. Feel free to reach out on twitter: @jeremydwayne

License

The gem is available as open source under the terms of the MIT License.