Skip to content

Latest commit

 

History

History
86 lines (56 loc) · 1.67 KB

MIGRATION.md

File metadata and controls

86 lines (56 loc) · 1.67 KB

AttrSearchable to SearchCop

As the set of features of AttrSearchable grew and grew, it has been neccessary to change its DSL and name, as no attr_searchable method is present anymore. The new DSL is cleaner and more concise. Morever, the migration process is simple.

Installation

Change

gem 'attr_searchable'

to

gem 'search_cop'

And then execute:

$ bundle

Or install it yourself as:

$ gem install search_cop

General DSL

AttrSearchable:

class Book < ActiveRecord::Base
  include AttrSearchable

  scope :search_scope, lambda { eager_load :comments, :users, :user }

  attr_searchable :title, :description
  attr_searchable :comment => ["comments.title", "comments.message"]
  attr_searchable :user => ["users.username", "users_books.username"]

  attr_searchable_options :title, :type => :fulltext, :default => true

  attr_searchable_alias :users_books => :user
end

SearchCop:

class Book < ActiveRecord::Base
  include SearchCop

  search_scope :search do
    attributes :title, :description
    attributes :comment => ["comments.title", "comments.message"]
    attributes :user => ["users.username", "users_books.username"]

    options :title, :type => :fulltext, :default => true

    aliases :users_books => :user

    scope { eager_load :comments, :users, :user }
  end
end

Reflection

AttrSearchable:

Book.searchable_attributes
Book.searchable_attribute_options
Book.default_searchable_attributes
Book.searchable_aliases

SearchCop:

Book.search_reflection(:search).attributes
Book.search_reflection(:search).options
Book.search_reflection(:search).default_attributes
Book.search_reflection(:search).aliases