= SimpleSearch
SimpleSearch privides search methods for your ActiveRecord models, by providing methods that allow you to search, group, and order.
Main goal is to simplify all search related operations from url.
* Searching
* Paging
* Grouping
* Ordering
== Getting Started
In your Gemfile:
gem "simple-search" # Last officially released gem
In your config/environment.rb
require 'simple_search'
In your controller:
def index
@posts = Post.select('posts.*, comments.id as comment_id, comments.body as comment').joins(:comments)
@posts = @posts.simplesearch(params)
render :index
end
In your view:
<%= form_tag('/posts', :method=>:GET) do -%>
ID > <%= text_field_tag 'id_gt', params[:id_gt] %>
Subject contains <%= text_field_tag 'subject_ct', params[:subject_ct] %>
<%= submit_tag "Search" %>
<% end -%>
Pages : <%=raw page_urls(@posts).join(" ") %>
<%=order_link(:id)%> |
<%=order_link(:subject)%> |
<%=order_link(:body)%> |
<%=order_link(:comment_id)%> |
<%=order_link(:comment)%> |
<% @posts.each do |post| %>
<%=h post.id %> |
<%=h post.subject %> |
<%=h post.body %> |
<%=h post.comment_id %> |
<%=h post.comment %> |
<% end %>
=== Search postfixes
* _eq, equal to, =
* _gt, greater than, >
* _lt, less than, <
* _le, less or equal to, <=
* _ge, greater or equal to, <=
* _in, includes, IN
i.e., &id_in=1,2,3
* _bt (alias of _between), between, BETWEEN
i.e., &id_between=1,3
* _sw (alias of _startswith), starts with, LIKE 'key%' (
* _ew (alias of _endsswith), ends with, LIKE '%key'
* _ct (alias of _contains,_like), contains, LIKE '%key%'
* _nc (alias of _notcontains,_notlike), not contains, NOT LIKE '%key%'
* _is, IS
i.e., &id_is=null
* _it (alias of _isnot), IS NOT
=== Sorting your result
* order_by
i.e., &order_by=id+asc
=== Paging
* page , page number
i.e. &page=1
* page_by, number of rows in a page
i.e. &page_by=10
=== Grouping
* group_by, column to group
i.e. &group_by=posts.id
== Contributing to simple-search
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
* Fork the project.
* Start a feature/bugfix branch.
* Commit and push until you are happy with your contribution.
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
== Copyright
Copyright (c) 2012 Allen Kim. See LICENSE.txt for further details.